Shadow Volume Problems

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).]

Originally posted by Dtag:
[b]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).][/b]

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/ shadowvolume/default.asp

Csiki

Iam drawing them with cappings as you can also see in the pseudo source. Thats why i dont know whats wrong

In addition your geometry (unless you’ve used some tricks) should be 2-manifold/closed.

Y.

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?

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.

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 )

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?

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

Nicolas.

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

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…

Thx all i solved my problem it was mainly a problem with the generation of the shadow volumes.