- Home /
How to set mesh normals per face?
Is there any way of setting the normals for a mesh to be per face? I am using only cubes which need only one normal per face and since I'm having issues with the 65k mesh vertex limit I want to have as few vertices as possible and reuse existing vertices whenever possible.
Note: breaking my mesh down to thousands of individual cube meshes is out of question since that is waay too resource intensive. Also the project this is used for is a minecraft-ish block world.
Answer by Owen-Reynolds · Oct 17, 2015 at 11:37 PM
It seems like you know how to set face normals, and your question is really "Is there a way to set face normals that uses less space than splitting verts."
I think the answer is No. Graphics cards use vertex normals. We wouldn't split vets at edges to get flat faces unless it was the best way.
Now, there was an old setting for "flat faces" that tells the graphics card to use the normal of the first vert (based on the Tri array) for the entire face. It makes every single face in the entire model be flat-shaded, without needing any extra verts. But the model has to have been made with that in mind, and I'm not sure it's even in newer cards, and don't think Unity supports it.
What a shame... The only solution I've found is to break down one single mesh into multiple smaller ones that can handle all the verts needed. I'm not really getting why such a option wouldn't exist anymore since less data for more geometry is a great optimization. I guess the norm of moving towards epic lighting effects and high vert count meshes renders this feature useless in most cases. But thanks anyway :)
You might want to have a look at my answer over here. It's possible to calculate the face normal inside the fragment shader using the partial derivative functions. However read the post carefully ^^. The usual way is to use seperate vertices per quad face (in the case of a cube). So you need 24 vertices ins$$anonymous$$d of 8 which is 3 times as much. However the performance would most likely be better with 3 meshes and vertex normals than 1 mesh with calculated normals.
Yeah, since performance is essential that is probably not the way to go.
Answer by mezzostatic · Jan 30, 2017 at 09:02 PM
you have to duplicate the vertices and give all 3 same normal to have face normals with acute shade change between faces.