From 368dda80d20618ccd2f05eac48543f3c11ecb902 Mon Sep 17 00:00:00 2001 From: Nahuel Rocchetti Date: Wed, 2 Aug 2023 03:54:12 -0300 Subject: [PATCH] start prep terrain for new shaders --- Assets/Materials/Terrain.mat | 41 ++++++++++++++++++- Assets/Scripts/OpenTS2/Content/TerrainType.cs | 4 ++ .../OpenTS2/Scenes/NeighborhoodTerrain.cs | 15 ++++--- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/Assets/Materials/Terrain.mat b/Assets/Materials/Terrain.mat index 3485c43..7178211 100644 --- a/Assets/Materials/Terrain.mat +++ b/Assets/Materials/Terrain.mat @@ -23,6 +23,10 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _CliffTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - _DetailAlbedoMap: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -45,7 +49,7 @@ Material: m_Offset: {x: 0, y: 0} - _MainTex: m_Texture: {fileID: 0} - m_Scale: {x: 0.01, y: 0.01} + m_Scale: {x: 0.0075, y: 0.0075} m_Offset: {x: 0, y: 0} - _MatCap: m_Texture: {fileID: 2800000, guid: 174675c9d2f4de84ba7e6face5995a2e, type: 3} @@ -63,6 +67,38 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + - _Roughness: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Roughness1: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Roughness2: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ShadowMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Shore: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ShoreMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Variation1: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _Variation2: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} m_Floats: - _Ambient: 0.2 - _BumpScale: 1 @@ -77,6 +113,7 @@ Material: - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 + - _SeaLevel: 0 - _Shininess: 0.7 - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 @@ -87,6 +124,8 @@ Material: - _StencilReadMask: 255 - _StencilWriteMask: 255 - _Subtract: 0.2 + - _TerrainHeight: 128 + - _TerrainWidth: 128 - _UVSec: 0 - _UseUIAlphaClip: 0 - _ZWrite: 1 diff --git a/Assets/Scripts/OpenTS2/Content/TerrainType.cs b/Assets/Scripts/OpenTS2/Content/TerrainType.cs index bfe64a3..c4518da 100644 --- a/Assets/Scripts/OpenTS2/Content/TerrainType.cs +++ b/Assets/Scripts/OpenTS2/Content/TerrainType.cs @@ -4,12 +4,16 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using OpenTS2.Common; +using UnityEngine; namespace OpenTS2.Content { public abstract class TerrainType { public abstract string Name { get; } + public virtual float RoadDistanceForRoughness => 40f; + public virtual float RoughnessFalloff => 40f; + public virtual Shader TerrainShader => Shader.Find("OpenTS2/ClassicTerrain"); public abstract ResourceKey Texture { get; } public virtual ResourceKey Texture1 => Texture; public virtual ResourceKey Texture2 => Texture1; diff --git a/Assets/Scripts/OpenTS2/Scenes/NeighborhoodTerrain.cs b/Assets/Scripts/OpenTS2/Scenes/NeighborhoodTerrain.cs index c2af1cd..f9c3c6f 100644 --- a/Assets/Scripts/OpenTS2/Scenes/NeighborhoodTerrain.cs +++ b/Assets/Scripts/OpenTS2/Scenes/NeighborhoodTerrain.cs @@ -29,15 +29,17 @@ namespace OpenTS2.Scenes void Awake() { Instance = this; + + var terrain = NeighborhoodManager.CurrentNeighborhood.Terrain; + var terrainType = terrain.TerrainType; + _meshFilter = GetComponent(); var contentProvider = ContentProvider.Get(); var meshRenderer = GetComponent(); _terrainMaterial = meshRenderer.material; + _terrainMaterial.shader = terrainType.TerrainShader; _terrainMaterial.SetVector("_LightVector", Sun.forward); - var terrain = NeighborhoodManager.CurrentNeighborhood.Terrain; - var terrainType = terrain.TerrainType; - var matCap = contentProvider.GetAsset(s_matCapKey); var smooth = contentProvider.GetAsset(terrainType.Texture); var variation1 = contentProvider.GetAsset(terrainType.Texture1); @@ -139,8 +141,9 @@ namespace OpenTS2.Scenes // TODO: Optimize, maybe multithread. void MakeRoughness(Mesh terrainMesh) { - var maxRoadDistance = 80f; - var minRoadDistance = 40f; + var terrainType = NeighborhoodManager.CurrentNeighborhood.Terrain.TerrainType; + var roadDistanceForRoughness = terrainType.RoadDistanceForRoughness; + var roughnessFalloff = terrainType.RoughnessFalloff; var vertices = terrainMesh.vertices; var colors = terrainMesh.colors; var roads = NeighborhoodManager.CurrentNeighborhood.Decorations.RoadDecorations; @@ -172,7 +175,7 @@ namespace OpenTS2.Scenes color.b = 1f; else { - var amount = Mathf.Clamp((closestRoadDistance - minRoadDistance) / maxRoadDistance, 0f, 1f); + var amount = Mathf.Clamp((closestRoadDistance - roughnessFalloff) / (roadDistanceForRoughness + roughnessFalloff), 0f, 1f); color.b = amount; } colors[i] = color;