Jump to content
  • Advertisement
Sign in to follow this  
metalcrusader

OpenGL zFail & infinite view frustum PROBLEM!

This topic is 4442 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I have problems implementing Stencil Shadow Volumes with zFail. To prevent that the volume is clipped by the far plane, I have to use an „infinite view frustum“. But how can I make that in OpenGL ( not the theory and need the OpenGL-Call!). And why do I need that infinite view frustum when I limit the volume to for example 10 and the far clipping plane is at 100000? I ask because in my implementation I get a second „ghost shadow“ and i don´t know how to remove it. I know that the volume must be closed so I use the reversed backfaces as the front cap and the extruded backfaces as back faces but the „ghost shadow“ remains. Please help me!!!

Share this post


Link to post
Share on other sites
Advertisement
Closing the volumes only isn't enough. The farplane should always be removed. This is accomplished by setting it to infinity like this:

gluPerspective(fov, aspect, 1.0f, -1.0f);

As you can see, I've set the farplane to -1.0f. This should solve your problem. Remember, for nvidia cards you can recover the 1% depth-precision loss by using the GL_NV_depth_clamp extension, but you won't notice any significant improvement with a 24-bit zbuffer.

Share this post


Link to post
Share on other sites
Thank you very much for answering! It seems that only a very few people have experiences with zFail!
I tried my program with the infinite far plane, but I still get the same second "ghost shadow". Is there anything else I have to consider for using this infinite far plane?

Another question: I found an extension called "EXT_depth_bounds_test". Can this extension solve by problem and how can I use it?

Share this post


Link to post
Share on other sites
There are a few things you need for zfail to work:

- an infinite farplane
- a nearplane of 1.0f (depth precision)
- be sure to set 8 bits of stencil
- be sure to use glClearStencil(0) at init
- draw front faces with:
glStencilFunc(GL_ALWAYS, 0, ~0);
glStencilOp(GL_KEEP, GL_INCR_WRAP_EXT, GL_KEEP);
- draw back faces with:
glStencilFunc(GL_ALWAYS, 0, ~0);
glStencilOp(GL_KEEP, GL_DECR_WRAP_EXT, GL_KEEP);
- be sure to use the wrapping extension in the above operations!
- your volume geometry must face outwards (with the normals)
- you have to draw front and back caps
- draw your volume geometry (last 2 verts of the quads) AND your backward caps at infinity (use w=0.0f or draw at a VERY LARGE offset (100000 or so))
- be sure to use some polygon offset like: glPolygonOffset(1.0f, 4.0f)

When you get these 11 requirements straight, I think it'll work. It works for me!

Share this post


Link to post
Share on other sites
Thank you again!
I did everything you advised me to do - but the "ghost shadow" didn't want to disapear. Then I compared my code with an old zPass implementation and I noticed that I have set the mask parameter of glStencilFunc to 0 instead of 1. That was all! The ghost shadow disappers and is fine!

Share this post


Link to post
Share on other sites
I should've known! I was doubting to tell you, but I was sure you'd find it sounding dumb.
Well, congrats my friend. I'll look at some optimazations at home for you.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!