• ### What is your GameDev Story?

This topic is 4902 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone. I was wondering if anyone could help me with my silhouette algorithm. I'm able to retrieve all of the edges needed from the shadow casting object, which is a simple box using triangles, but once the edges are created and I am trying to extrude a shadow volume using quads no shadows appear. I adjust my edges manually and shows a shadow when the light is directly above the box, but when the light is moved to one side or the other I get expected errors. I was just wondering if anyone knew how to sort my edges so that they could render shadow volume correctly. Thank you ahead of time for your help

##### Share on other sites
I don't understand your problem. Your edge silhouette are the edges with one face front-facing the source, and the other face back facing the source. As for the ordering, it should not matter, as long as the anti-clockwise ordering of vertices is always respected.

If you have the edges, it's a simple matter of extrusion.

##### Share on other sites
OK how do you sort the vertices so that they are counter-clockwise?

##### Share on other sites
Quote:
 Original post by darrenc182OK how do you sort the vertices so that they are counter-clockwise?

Well, it's tricky. There isn't a sure-fire way to detect if the ordering of an arbitrary mesh is CCW (counter-clockwise) or CW (clockwise), It's all a matter of relativity, unless the mesh is convex, ... It's a conceptual problem, like deciding what is 'solid' and what isn't in your geometry.

For a box (or any convex shape), it's straight forward. All face normals should point to the outside of the box (obviously), and the face normal of a triangle A(V0, V1, V2), will have that normal in the same direction to the vector N = ((V1 - V0) x (V2 - V1)). That's for a right handed system (the system used in every sane geometry application and API, like OpenGL and DirectX), and that defines anti-clockwise vertices.

If you define normals of triangles like that for each triangle of the box, and while rendering, set Front Face to CCW (glFrontFace(GL_CCW)) and enable back-face culling (glEnable(GL_CULL_FACE)), there will be no holes in the box mesh. If there are holes, it means that the triangles forming the hole are listed in the wrong order. That will definitely screw up your shadow.

So all it boils down to is a careful ordering of vertices for your box, and edge connectivity. Then after that, there is not much to worry about.

In general, if you want to do stencil shadows, especially the DOOM3 kind, you have to make sure that your meshes are 2-manifold. In escence, they have no leak in the geometry (no holes), no flipped triangles (facing the wrong way), and no T-junction (every triangles connected to only one other triangle for each of the edge.

So, lots of constraints, but it is necessary. Else, you'll see artifacts, like big grey quads appearing.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 31
• 16
• 11
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015592
×