0
\$\begingroup\$

I'm creating this mesh during runtime in Unity3D.

enter image description here

The mesh shape is ok, but as you can see on this screenshot, the mesh is not correctly rendered: it's only rendered when the camera is looking back at the mesh, but I don't want to rotate the mesh or modify the camera position.

I know I can create a simple shader to activate backface culling... But I don't need a custom shader. I want to understand what I do wrong.

All my normals are set to -Vector3.forward:

        normals[vert_idx] = -Vector3.forward;
        normals[vert_idx + 1] = -Vector3.forward;
        normals[vert_idx + 2] = -Vector3.forward;
        normals[vert_idx + 3] = -Vector3.forward;

Are normals the only things involved in this problem? Or should I look to triangles order, vertices order or something?

Thanks.

\$\endgroup\$
1
\$\begingroup\$

Triangles have a direction in which they face. They are transparent from the other direction.

Which direction each triangle faces is determined by the order in which you state the three vertices it consists of. When you would like the triangle to be visible from the other side, pass the vertices in reversed order. If you would like them to be visible from both sides, you need to create two triangles.

Normals are a different topic. They determine how the object is shaded. But calculating them yourself is optional. You can leave that to Unity by calling mesh.RecalculateNormals() after setting up all triangles.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your answer. I have learnt new things thanks to your answer. \$\endgroup\$ – lvictorino Apr 20 '16 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.