Jump to content


ZPass shadow volumes -> ZFail


9 replies to this topic

#1 draculr

    New Member

  • Members
  • Pip
  • 7 posts

Posted 12 July 2005 - 05:32 AM

So I have my ZPass algorithm working, however now I want to switch over to ZFail so that the shadows do not screw up when you walk behind a shadow caster.

So there are 2 things I need to change that I know of :

(1)
Change:
glCullFace(GL_BACK);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
glCullFace(GL_FRONT);
glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);

to:

glCullFace(GL_FRONT);
glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);
glCullFace(GL_BACK);
glStencilOp(GL_KEEP,GL_DECR,GL_KEEP);

(2)
Render the shadow volume caps (at both ends)

Ok so I have the back faces of my polygon stored in an array, then I want to extend them to infinity and cap it there...

So for each triangle, I take each vertex and do the following:

vertex1_ext = vertex1 + 10000 * (vertex1 - lightPosition);
vertex2_ext = vertex2 + 10000 * (vertex2 - lightPosition);
vertex3_ext = vertex3 + 10000 * (vertex3 - lightPosition);

Then I render the original vertices normally and the ext vertices backwards to reverse the normal.


Is that correct? Is that all I need to do? Sicne this doesnt seem to give me correct shadows :|


Do I need to render the entire mesh as the shadow cap instead of just the faces facing away from the light?

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 12 July 2005 - 06:36 AM

First, be sure that your z-buffer far plane is at least 10,000 units away. Or else use an actual projection to homogenous infinity, and a corresponding infinite projection matrix. Remember the far cap must be inside the range of the depth buffer.

Second, ensure that you're rendering all INCR faces first, and then all DECR faces (this includes the caps), or else use INCR_WRAP and DECR_WRAP. The back cap should be the projected vertices that are back-facing w.r.t. the light, and the front cap should be those same vertices, unprojected and with their orientation reversed (the unprojected back-faces are used as the front cap, to prevent z-fighting on the lit faces).

Other than that your setup looks good.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 draculr

    New Member

  • Members
  • Pip
  • 7 posts

Posted 14 July 2005 - 12:32 AM

Reedbeta said:

First, be sure that your z-buffer far plane is at least 10,000 units away. Or else use an actual projection to homogenous infinity, and a corresponding infinite projection matrix. Remember the far cap must be inside the range of the depth buffer.

Second, ensure that you're rendering all INCR faces first, and then all DECR faces (this includes the caps), or else use INCR_WRAP and DECR_WRAP. The back cap should be the projected vertices that are back-facing w.r.t. the light, and the front cap should be those same vertices, unprojected and with their orientation reversed (the unprojected back-faces are used as the front cap, to prevent z-fighting on the lit faces).

Other than that your setup looks good.

View Post



Still doesnt seem to work for me, how do you modify the z-buffer far plane?

#4 Ed Mack

    Senior Member

  • Members
  • PipPipPipPip
  • 1239 posts

Posted 14 July 2005 - 01:01 AM

The far plane is set when you setup the projection matrix (probably during a call to glPerspective).

#5 elengyel

    Member

  • Members
  • PipPip
  • 50 posts

Posted 16 July 2005 - 05:03 AM

If you haven't already read the following, I high recommend it -- I guarantee you'll find it helpful.

http://www.gamasutra.../lengyel_01.htm

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 16 July 2005 - 06:48 AM

If you're interested in shadow techniques, also check this out:

http://artis.inrialpes.fr/Publications/200...hlh-zp-plus.pdf

Significantly faster than Z-fail, and gives (almost) correct shadows unlike Z-pass. I haven't tried it myself though, the implementation needs some kinda messy special cases.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 krausest

    New Member

  • Members
  • Pip
  • 1 posts

Posted 18 July 2005 - 07:26 PM

Reedbeta said:

If you're interested in shadow techniques, also check this out:

http://artis.inrialpes.fr/Publications/200...hlh-zp-plus.pdf

Significantly faster than Z-fail, and gives (almost) correct shadows unlike Z-pass. I haven't tried it myself though, the implementation needs some kinda messy special cases.

View Post


Would you really recommend it? I've read the paper and don't believe you can make it work without artefacts.
If you just check for each object if z-fail is necessary and render the other objects using z-pass the performance drop shouldn't be too bad.

#8 elengyel

    Member

  • Members
  • PipPip
  • 50 posts

Posted 22 July 2005 - 04:02 AM

I don't think that ZP-plus idea is very good. I've posted some detailed comments about it here:

http://www.terathon.com/eric/blog.html

#9 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 22 July 2005 - 06:49 AM

Well, you've convinced me. I didn't like ZP+ that much from the start either. Doing standard Z-pass except where Z-fail is required seems like a much nicer solution. And anyway, doesn't Doom 3 use complete Z-fail (or a mixture of Z-pass and Z-fail)? And it runs just fine even with dozens of shadow casters, hundreds of shadow polygons.
reedbeta.com - developer blog, OpenGL demos, and other projects

#10 elengyel

    Member

  • Members
  • PipPip
  • 50 posts

Posted 22 July 2005 - 07:17 PM

Yes, Doom3 uses a combination of z-pass and z-fail. So does this:

http://www.terathon....e/download.html





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users