Advertisement

Using "Carmack's Reverse" in Lesson28

Started by March 23, 2002 12:36 PM
3 comments, last by Arsenal 22 years, 11 months ago
Lesson28 provided a great tutorial into implementing stencil buffer shadows. A flaw in the stencil technique is that the shadow can get screwed up if the shadow volume intersects the near plane. I decided to try the "Carmack''s Reverse" technique which would only cause artifacts at the FAR clipping plane...unfortunately, having changed the Lesson28 code for Carmack''s version, I''m not getting the results I want. Am I missing something? Here''s what I changed in the CastShadow function (for the Win32 version) THIS: glFrontFace(GL_CCW); glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); TO THIS: glFrontFace(GL_CW); glStencilOp(GL_KEEP, GL_INCR, GL_KEEP); AND THIS: glFrontFace(GL_CW); glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); TO THIS: glFrontFace(GL_CCW); glStencilOp(GL_KEEP, GL_DECR, GL_KEEP); Has anybody else tried to implement it in the lesson, or anywhere else? Could it be something on how the model is defined? Thanks Mark Grocki Lead Developer 2Real Entertainment http://www.2realentertainment.com
Mark Grocki
as far as i know he only draws the open shadow volumes, means the expansions at the edges, thats all..
for cr, you always need closed shadow-volumes, means always the complete shadow-volume. soon there will be a working demo on the nvidia page out, they''re coding on it. a perfect shadow-volume demo, running in all circumstances on all hardware with stencils..

you could take a look at this then..
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Advertisement
Arsenal:
The algorithm is right, but:
1- you have to extend the far plane,
2- you have to project shadow volumes, not just the silhouettes.

Carmack''s reverse works fine, but:
1- extending the far plane makes you lose a bit of depth precision,
2- projecting a shadow volume costs more fillrate than projecting silhouettes only,
3- if the light is very close to an object, the shadow of this object is not projected far enough.


quote:

soon there will be a working demo on the nvidia page out, they''re coding on it. a perfect shadow-volume demo, running in all circumstances on all hardware with stencils..

You must be talking about Kilgard''s advanced stencil shadows
Okay, I''m a little confused now. I''m not quite sure of the difference between the "shadow volume" and the "silhouette".

In Lesson28, the shadow is created by casting an "infinite" quad from a silhouette edge away from the light. Now, doesn''t that define a volume if a silhouette edge is all around an object? But I know that will also draw the interior silhouette edges if the object casting the shadow is not convex. Does the "shadow volume" only include the other silhouette? Are they any resources on computing the volume?

Now, Carmack''s technique works for him because he doesn''t have to extend the far plane really far because of claustrophobic interior areas and his lights are attenuated anyway.

I understand the #3 disadvantage quite well.

Thanks for the help

Mark Grocki
Lead Developer
2Real Entertainment
http://www.2realentertainment.com
Mark Grocki
The silhouettes are the "extended edges" which are neighbour to triangles facing light and triangle facing dark.
That''s what is used in Lesson28.

The shadow volumes need to cap the beginning and the end.

Let''s get a little scheme in 2D to understand a bit better. (I''m sorry if I sound too childish but at least everyone on the board will be able to understand more easily).

The star is the light source and the quad is the object which project a shadow.
The scene is :

          .-----.        |     |  *     |     |        |     |        .-----.  


To project the silhouette, you have to draw the following polygons (which are lines in 2D) :

               _/           _/         _/        /          *                     \_          \_            \_              \  

Note that I removed the quad to better view what is the shadow.

To project the shadow volume, you have to cap the beginning and the end :

                 ___________             _/           |           _/             |         _/               |        /                 |        |                 |  *     |                 |        |                 |        \_                |          \_              |            \_            |              \___________|  




To display the silhouette , the algorithm is :

for each edge
if the first neighbour triangle is facing light and the other neighbour triangle is not facing light
"extend" the edge and draw a quad between the "normal" edge and the "extended" edge


To display the volume , the algorithm becomes :

for each edge
if the first neighbour triangle is facing light and the other neighbour triangle is not facing light
"extend" the edge and draw a quad between the "normal" edge and the "extended" edge

for each triangle
if the triangle is facing light
draw the "normal" triangle
else // the triangle is not facing light
draw the ''extended" triangle


I hope it''s a bit more clear now.

Please note that the "volume" algorithm does work only for closed objects, whereas the "silhouette" algorithm works with opened objects too.


quote:
Now, Carmack''s technique works for him because he doesn''t have to extend the far plane really far because of claustrophobic interior areas and his lights are attenuated anyway.



Yes that''s his explanation.
Although he''s right for his particular case of Doom III, it''s wrong to believe that it can be applied to all sceneries.
That''s why MJK discussed about it.

This topic is closed to new replies.

Advertisement