- Home /
 
My procedural mesh leaves traces on rendering
Hello,
I am working with the 2020.3.17f1. A procedural terrain generation script (Zenva's tutorial: the complete procedural terrain generation in Unity course) works correctly, but leaves traces (from the mesh grid I think) in the scene and in the game view, see the 2 screenshots.
It seems to be related to the light, when I rotate my directional light, the tracks move. I have tried everything I know about shadows, but the concern persists.
When I change the terrain material shader from standard to Mobile / Unlit ( Supports Ligthmap), Unlit / Texture (no texture) or Unlit / Transparent cutout, the traces disappear.
I also have the problem with the 2019.4.30.f1.
There are 6 scripts: TileGenerator (generates the terrain), NoiseGenerator (generates the noise with a PerlinNoise and waves), MeshGenerator, TextureBuilder (detailed below), TerrainType and Wave define data types.
Thank you for giving me some avenues to explore.
 using UnityEngine;
 
 public class TextureBuilder
 {
     public static Texture2D BuildTexture (float[,] noiseMap, TerrainType[] terrains)
     {
         Color[] pixels = new Color[noiseMap.Length];
 
         int size = noiseMap.GetLength (0);
 
         for (int x = 0; x < size; x++)
         {
             for (int z = 0; z < size; z++)
             {
                 int index = (x * size) + z;
                 
                 for (int t = 0; t < terrains.Length; t++)
                 {
                     if (noiseMap[x, z] < terrains[t].threshold)
                     {
                         float minVal = (t == 0 ? 0f : terrains[t - 1].threshold);
                         float maxVal = terrains[t].threshold;
 
                         pixels[index] = terrains[t].colorGradient.Evaluate (1f - (maxVal - noiseMap[x, z]) / (maxVal - minVal));
                         break;
                     }
                 }
             }
         }
 
         Texture2D texture = new Texture2D (size, size)
         {
             wrapMode = TextureWrapMode.Clamp,
             filterMode = FilterMode.Bilinear
         };
         texture.SetPixels (pixels);
         texture.Apply ();
 
         return texture;
     }
 }
 
               
 
For an unlit shader this looks like a some kind of vertex color interpolation or colormap sampling issue. But if this is a lit shader then my bet is on mesh normals not following surface curvature very well.
Your answer