PDA

View Full Version : Shadow Volume Problems



Dtag
07-30-2003, 12:09 AM
Hi
Iam currently working on shadow volumes. My technique is for now strongly based on this ( http://users.ox.ac.uk/~univ1234/opengl/shadvol/shadvol.htm ) sample. My problem is that ZPass works fine for me, and ZFail has completely weird results.
Here are 2 Screenshots of the 2 methods: http://www.pay4hits.de/shadowok.jpg http://www.pay4hits.de/shadowerr.jpg
The first one obviously shows ZPass as its working there.
Iam using the following (pseudo)code to render:
AMBIENTPASS();
(I have just one Light right now)
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glEnable(GL_DEPTH_TEST);
glDepthMask(0);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glEnable(GL_STENCIL_TEST);

glStencilFunc(GL_ALWAYS, 0, ~0);
// For ZFail
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
glCullFace(GL_BACK);
DRAWSHADOWVOLUMEWITHCAPS();
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
glCullFace(GL_FRONT);
DRAWSHADOWVOLUMEWITHCAPS();
// For ZPass
glCullFace(GL_BACK);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
DRAWSHADOWVOLUMEWITHOUTCAPS();
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glCullFace(GL_FRONT);
DRAWSHADOWVOLUMEWITHOUTCAPS();
//
RENDERLIGHTPASS();

As one can see both techniques dont differ too much which is why Iam wondering how its possible that zpass works flawlessly and zfail returns so strange results. Does anyone have an idea what might be wrong?

[This message has been edited by Dtag (edited 07-30-2003).]

[This message has been edited by Dtag (edited 07-30-2003).]

Csiki
07-30-2003, 12:28 AM
Originally posted by Dtag:
Hi
Iam currently working on shadow volumes. My technique is for now strongly based on this ( http://users.ox.ac.uk/~univ1234/opengl/shadvol/shadvol.htm ) sample. My problem is that ZPass works fine for me, and ZFail has completely weird results.
Here are 2 Screenshots of the 2 methods: http://www.pay4hits.de/shadowok.jpg http://www.pay4hits.de/shadowerr.jpg
The first one obviously shows ZPass as its working there.
Iam using the following (pseudo)code to render:
AMBIENTPASS();
(I have just one Light right now)
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glEnable(GL_DEPTH_TEST);
glDepthMask(0);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glEnable(GL_STENCIL_TEST);

glStencilFunc(GL_ALWAYS, 0, ~0);
// For ZFail
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
glCullFace(GL_BACK);
DRAWSHADOWVOLUMEWITHCAPS();
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
glCullFace(GL_FRONT);
DRAWSHADOWVOLUMEWITHCAPS();
// For ZPass
glCullFace(GL_BACK);
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
DRAWSHADOWVOLUMEWITHOUTCAPS();
glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
glCullFace(GL_FRONT);
DRAWSHADOWVOLUMEWITHOUTCAPS();
//
RENDERLIGHTPASS();

As one can see both techniques dont differ too much which is why Iam wondering how its possible that zpass works flawlessly and zfail returns so strange results. Does anyone have an idea what might be wrong?

[This message has been edited by Dtag (edited 07-30-2003).]

[This message has been edited by Dtag (edited 07-30-2003).]

At zpass you have to make the capping for your shadow volume or you will get nearly always wrong results.
See: www.gamedev.net/columns/hardcore/ (http://www.gamedev.net/columns/hardcore/) shadowvolume/default.asp


Csiki

Dtag
07-30-2003, 12:32 AM
Iam drawing them with cappings as you can also see in the pseudo source. Thats why i dont know whats wrong http://www.opengl.org/discussion_boards/ubb/frown.gif

Ysaneya
07-30-2003, 12:34 AM
In addition your geometry (unless you've used some tricks) should be 2-manifold/closed.

Y.

Dtag
07-30-2003, 12:57 AM
Hmm so you all think it must be the shadow volume that is wrong in this case? Is there a possibility that anything else is wrong?

Nicolas Lelong
07-30-2003, 02:01 AM
Hi,

just my two cents, but it seems to me that your zFail code should draw _back_ facing polygons first, then _front_ facing ones.

Quite the opposite of the zPass approach.

So I think your zFail code should be :

// For ZFail
glStencilOp(GL_KEEP, GL_INCR, GL_KEEP);
glCullFace(GL_FRONT); //< changed
DRAWSHADOWVOLUMEWITHCAPS();
glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
glCullFace(GL_BACK); //< changed
DRAWSHADOWVOLUMEWITHCAPS();

I may be wrong though...
Hope this helps,

Nicolas.

Dtag
07-30-2003, 02:11 AM
Hm sorry forgot to say this. The geometry is q3 geometry where the polygons are supposed to use frontface culling, so everything is the other way round ( including the shadow volume )

Csiki
07-30-2003, 03:10 AM
Originally posted by Dtag:
Hm sorry forgot to say this. The geometry is q3 geometry where the polygons are supposed to use frontface culling, so everything is the other way round ( including the shadow volume )

What picture you get when you render the zfail shadow without caps also?

Nicolas Lelong
07-30-2003, 03:40 AM
The geometry is q3 geometry where the polygons are supposed to use frontface culling, so everything is the other way round

So I would suggest you to change front face definition (using glFrontFace) instead of using glCullFace(GL_FRONT) all the time. I don't think it has performance impact, but it is much 'clean' this way.


( including the shadow volume )

I don't think this impacts my previous post. What I meant is that zFail & zPass methods do not draw the polygons in the same order :

* zPass draws front facing (visible if you prefer) polygons first, then back facing ones (not visible)
* zFail draw back facing first then front facing.

If your code snippet is effectively waht you use, I think both your zFail & zPass methods draw the polygons in the same order, And I think that could be your problem.

Once more, I may be wrong http://www.opengl.org/discussion_boards/ubb/smile.gif

Nicolas.

AdrianD
07-31-2003, 03:31 AM
when you use 128 as the stencil ref-value, or use the stencil_wrap extension you don't need to care about the rendering order.Take a look at this, ti a very good paper about this topic: (besides the inf-projection-method described in this paper, this is also an excelent paper about stencil shadow rendering)
http://developer.nvidia.com/object/robust_shadow_volumes.html

here is the soucecode/demo: http://developer.nvidia.com/object/inf_shadow_volumes.html

NordFenris
07-31-2003, 09:08 AM
Now, I'm just a newbie on this, but I just wanted to make sure that you noticed that the left flaming skull is behind the shadow. I don't know if it's significant in any way, it just surprised me a little...

Dtag
08-01-2003, 07:51 AM
Thx all i solved my problem it was mainly a problem with the generation of the shadow volumes.