![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | PeteF52 |
I am trying to procedurally generate a terrain mesh so that it is different each time the project is loaded and everything is working as intended except that most meshes get this stringing/shadowing of surfaces along the z-axis.
The problem is more prominent when the amplitude of the terrain is increased.
Can someone please a solution?
Example 1:
Example 2:
Example 3:
This is where I assume the problem is:
public override void _Ready()
{
int vertexIndex = 0;
var vertices = new Vector3[mapWidth*mapHeight];
surfaceTool.Begin(Mesh.PrimitiveType.Triangles);
//surfaceTool.AddSmoothGroup(true);
NoiseTexture noiseTexture = terrainNoise();
for (int z = 0; z < mapHeight; z++)
{
for (int x = 0; x < mapWidth; x++)
{
float vertHeight = noiseTexture.Noise.GetNoise2d(x,z) * 25;
vertices[vertexIndex] = new Vector3(x, vertHeight, z);
vertexIndex++;
}
}
vertexIndex = 0;
for (int z = 0; z < mapHeight; z++)
{
for (int x = 0; x < mapWidth; x++)
{
if (vertexIndex < (mapHeight * mapWidth) - (mapWidth + 1))
{
//First Triangle
surfaceTool.AddVertex(new Vector3(vertices[vertexIndex]));
surfaceTool.AddVertex(new Vector3(vertices[vertexIndex+1]));
surfaceTool.AddVertex(new Vector3(vertices[vertexIndex+mapWidth]));
//Second Triangle
surfaceTool.AddVertex(new Vector3(vertices[vertexIndex+mapWidth]));
surfaceTool.AddVertex(new Vector3(vertices[vertexIndex+1]));
surfaceTool.AddVertex(new Vector3(vertices[vertexIndex+mapWidth+1]));
}
vertexIndex++;
}
}
surfaceTool.Index();
surfaceTool.GenerateNormals();
var meshInstance = new MeshInstance();
meshInstance.Mesh = surfaceTool.Commit();
GetChild<MeshInstance>(0).AddChild(meshInstance);
}
There is also a noise generator before this block of coding.
I am still very new to both Godot and C# and have had to mix several tutorials to get to this point so I’m sorry if the code is messy.