- Home /
weird shadows in the procedurally created mesh
after I procedurally generate mesh it gets weird shadows on edges in the middle of a face, or in some other seemingly random places. I assume I'm missing something - how to make the "shadows" regulary distributed on faces like on primitives available in unity - in this example: on a cube. or on any imported meshes?
code
function creatingMesh(newVertices, newTriangles){ var newGameObject:GameObject = new GameObject("newCut"); var newMesh:Mesh = new Mesh(); newGameObject.AddComponent(MeshFilter); newGameObject.AddComponent(MeshRenderer);
newMesh.vertices = newVertices.ToArray();
var uvs = new Vector2[newMesh.vertices.length];
for (i= 0; i<uvs.length; i++){
uvs[i] = Vector2(newMesh.vertices[i].x, newMesh.vertices[i].z);
}
newMesh.uv = uvs;
newMesh.triangles = newTriangles.ToArray();
newGameObject.GetComponent(MeshFilter).mesh = newMesh;
newMesh.RecalculateNormals();
if(newObjectMaterial) newGameObject.renderer.material = newObjectMaterial;
newGameObject.AddComponent(Rigidbody);
newGameObject.AddComponent(MeshCollider);
newGameObject.collider.convex = true;
}
Answer by Eric5h5 · Nov 17, 2010 at 04:37 AM
You need to split vertices so that hard edges have more than one vertex, since normals are per-vertex. You're getting the same result that you would if you imported something like a cube, and turned on Generate Normals and gave it a smoothing angle of 180. If you made a cube from 8 vertices, then you can only have smooth lighting since all vertices share the same normals. But that naturally looks totally wrong for a cube, so you'd need to make it from 24 vertices (4 per side). This way each vertex can have proper normals.
Your answer
Follow this Question
Related Questions
Mathf.PerlinNoise is always returning "0.4652731" regardless of the input 1 Answer
LocomotionSystem not working in Unity 5 2 Answers
Generate mesh from raycast positions, independent of rotations 0 Answers
SpeedTree shaders are not working with Projectors 0 Answers
How do I procedurally place light probes 0 Answers