I have an issue with back face culling in my engine on the monkey model from Blender exported as .obj format. However, with the box model from Blender exported the same way all is good.
My first assumption is that something's wrong with the winding order of certain faces in the monkey model. So I've tried to check order by calculating normals on each face by myself using the cross product cross(v2-v1,v3-v1).
I expected that all normals would have Z-coordinate with the same sign, but got different results on different faces.
But why is the box, which I exported the same way, rendered correctly? So, I tried to calculate normals the same way on the box model–and wow!–I still get different Z signs on two faces out of twelve...
But I see that the box is rendered correctly, then I checked my method to calculate the faces' normals. And they calculated correctly–you can see them in the box GIF.
So the question is: did I correctly understood winding order? A I use the correct way to check the winding? Should all faces in the model have the same sign of Z for normals? Should I do additional geometry preparation for object models to render them all correctly?
- The engine follows the left-handed rule.
- Render API: Metal.
- All draws happen with backface culling and in clockwise order.
P.S.: online renderers of .obj models renders my monkey model correctly. I don't understand what to fix in my engine, cause my assumptions that normals should all have the same Z sign seems to be wrong.
Box:
<iframe src="https://giphy.com/embed/8Rtq2jXCowwkCIkFoK" width="480" height="400" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/8Rtq2jXCowwkCIkFoK">via GIPHY</a></p> Monkey:
<iframe src="https://giphy.com/embed/Hvbi2wmktmfziLavii" width="480" height="400" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/Hvbi2wmktmfziLavii">via GIPHY</a></p>