Sorry in advance for any grammatical or lexical mistakes. English is not my first language.
I have a problem and the title describes it fairly good. Looking at the screenshot, those two objects have the same material on them. The key difference is, one on the right is a cube primitive, and the other is procedurally generated. As we can see, there is very ugly shading on my generated mesh. It seems like when looked from a close distance, some sort of static shows itself. It looks grainy and offputting.
There isn’t really much to the code i think.
{ // Creates an n-sided table for n >= 3 and a square table otherwise
MeshFilter filter = TableManager.inst.GetComponent<MeshFilter>();
Mesh mesh = new Mesh();
filter.mesh = mesh;
List<Vector3> vertices = new List<Vector3>();
for (int i = 0; i < 2 * n; i++)
{
vertices.Add(new Vector3(Mathf.Cos(2 * Mathf.PI / n * (i + 0.5f)) * radius,
i >= n ? -0.5f : 0f,
Mathf.Sin(2 * Mathf.PI / n * (i + 0.5f)) * radius));
}
List<int> indices = new List<int>();
for (int i = 0; i < n - 2; i++)
{
indices.Add(0);
indices.Add(i + 2);
indices.Add(i + 1);
}
for (int i = n; i < 2 * n - 2; i++)
{
indices.Add(n);
indices.Add(i + 1);
indices.Add(i + 2);
}
for (int i = 0; i < n - 1; i++)
{
indices.Add(i);
indices.Add(i + 1);
indices.Add(i + n + 1);
indices.Add(i);
indices.Add(i + 1 + n);
indices.Add(i + n);
}
indices.Add(n - 1);
indices.Add(0);
indices.Add(n);
indices.Add(n - 1);
indices.Add(n);
indices.Add(2 * n - 1);
mesh.Clear();
mesh.vertices = vertices.ToArray();
mesh.triangles = indices.ToArray();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
I have really no idea what causes this. Could anyone please help?

