- Home /
How to disable smooth lighting on procedural mesh
Hello, I made a terrain generator script which generate a grid and (temporarily) set random height to the vertices.
The problem is that it looks very smooth : http://i.imgur.com/36HVwqH.png But i'd like to make it looks "flat" and show the edges.
It actually like the "Smooth" shading of Blender : http://i.imgur.com/A0P09Mr.png
But i want it to look like the "Flat" shading : http://i.imgur.com/oCJd9Ib.png
So I needto set this appearance only with code. Thanks !
Answer by maxizrin · Mar 16, 2017 at 10:39 AM
You will have to duplicate the vertices of the edges.
When you call mesh.RecalculateNormals() it calculates an average normal of adjacent faces. The normals are used to calculate the amount of light a face gets, averaging the normal makes that smooth lighting effect.
I've looked into this for a while, there is an option to do this on an imported mesh, but nothing for a runtime generated mesh. This is because imported meshes actually have the triangles separate under the hood. You just have to duplicate the vertices of every edge, and that should work.