Vertex winding for Volume Shadows

Started by
0 comments, last by eloso 17 years, 6 months ago
I'm trying to implement volume (or stencil) shadows at the moment and have come to a stand-still. In order to run the algorithm efficiently, you need to have a orientations of all the edges in a mesh consistent. What I need is an algorithm for determining if a triangle is wound correctly and otherwise fixing it. So for example, the following tri would be fine:

   3
  /  /   1-----2
Assuming the face normal points toward you, the vertices are ordered correctly around the normal (anti-clockwise). This is not good however:

   2
  /  /   1-----3
The vertices are number around the wrong way. Is there a way of testing which way around the vertices are given I have the vertex positions and the face normal??? I realise that if I have a test for it then the simple solution is to swap verts 2 and 3, but how do I test that this is the case?
Advertisement
Test the cross product

(v2-v1)x(v3-v1)

if it points to the same direction as your normal your triangle is ok. Otherwise swap v2 and v3.

This topic is closed to new replies.

Advertisement