Archived

This topic is now archived and is closed to further replies.

nitzan

shadows and carmack's reverse

Recommended Posts

I implemented the shadow volumes from the Lesson 27 tutorial into my game engine. Everything worked and looked great until I entered one of the shadows. Since the front facing tetrahedron no longer existed, the shadow stopped being drawn. Now I implemented Carmack's reverse. But I seem to have some problems with artifacts. My far clip plane is set at 1000 and my shadows only extend 100 units. I tried setting the clip plane to 5000 and 50,000 just in case, but the artifacts persist. My question is ... Do I have to enable anything else special to use carmack's reverse ? Pretty much all I did was set the stencil updates to fail instead of pass: increment stencil when depthtest FAILS for BACK facing shadows then decrement stencil when depthtest FAILS for FRONT facing shadows added screenshots. normal looks correct, reverse has artifacts as can be seen in the table leg: normal render normal stencil reverse render reveser stencil Nitzan

Share this post


Link to post
Share on other sites
yes you are making a small mistake, one difference with using depth fail is that your shadow volumes must be ''air tight''...

that is,

when you render the volume, for both inc and dec of the stencil buffer, you must also render the faces that are in the light (the front cap of the shadow volume) and also project these out as far as the shadow is being cast (to make a rear cap to the volume). This makes the volume ''air tight''.. if you get what I mean.
There are ways to optimize out geometry, and some other things, but generally you pretty much must do this.

| - Project-X - my mega project.. getting there... - | - adDeath - | - email me - |

Share this post


Link to post
Share on other sites
Ok, I now have a new problem...

If I render the lit faces with depth testing enabled, they z buffer screws up since the "shadow" face is "colliding" with the model''s face.

If I disable depth testing, the face might show up through an object thats infront of it.

How do I render the front (lit) faces ?

Nitzan

Share this post


Link to post
Share on other sites
depth test function should be GL_LEQUAL. this should have no problems if your geometry is the same, but I've seen some weird things happen on ati cards with slightly different depth values when texturing is or isn't used and the same with nvidia but I forget what caused it.

What you can do is use either polygon offset or fudge the projection matrix to shift the depth values back very slightly... This will put the volume slightly behind the lit surface (which you want). To fudge the projection matrix simply regenerate it with the near and far clip planes slightly forward (ever so slightly)... say +0.005... You also might want to look into infinite far clip plane (very useful) and using the w coord as 0 to project the shadow to infinity.

| - Project-X - my mega project.. getting there... - | - adDeath - | - email me - |

[edited by - RipTorn on July 6, 2003 3:33:42 AM]

Share this post


Link to post
Share on other sites
Ok, I found a quick solution is to scale down the shadow model by 0.99.

Unfortunately some models seem to cast shadows incorrectly. It seems parts of the shadow that sould be cancelled out are not. The anomalies in the shadow also follow the camera. Any ideas what this is and how it could be solved ?

At first I though it was my far clip plane, but increasing that by alot and reducing the distance the shadow gets projected didnt seem to solve it.

Thanks,

Nitzan

[edited by - nitzan on July 7, 2003 12:07:56 PM]

Share this post


Link to post
Share on other sites