Jump to content
  • Advertisement
Sign in to follow this  
darrenc182

Shadow Volume Silhouette Algorithm

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by darrenc182
OK 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!