PDA

View Full Version : skybox depth test

remdul
09-24-2007, 06:29 AM
I draw skybox geometry after baking the scenery Z-buffer to take advantage of early-z and the z-buffer test itself.

I push the skybox near the farplane with glDepthRange, e.g.:

glDepthRange(0.9999,1);
// draw skybox
glDepthRange(0,1);

But this still results in clipping near the far plane (fog color does not match skybox smoothly).

How do I set the depth test to pass fragments if z==1.0, fail otherwise?

Or how do I make sure the skybox z fragment will always be 1.0? I'm thinking, if set the fragment depth to 1.0 in a shader I lose the early-z test.

Flavious
09-24-2007, 06:36 AM
Try setting z = w in your vertex program instead. That way z / w = 1.

remdul
09-24-2007, 06:40 AM
Ah, that makes perfect sense, why didn't I think of that? :)

*Edit: I still have some clipping issues, but I suspect this is due floating point inaccuracies as I move the skybox in the world to the eye position, instead of moving the eye position to the origin.

Are there alternatives that guarantee the fragment will pass when z==1.0 (per fragment rather than vertex level)?

Flavious
09-24-2007, 07:29 AM
You could try multiplying w by a number slightly less than 1, or you could use NV_depth_clamp, if available.

remdul
09-24-2007, 07:48 AM
You could try multiplying w by a number slightly less than 1That is essentially the same as the glDepthRange trick.

Not sure I want to use NV_depth_clamp as it is NV only.

Trenki
09-24-2007, 09:04 AM
I think it would even be possible to set glDepthRange(1, 1), so the resulting fragment depth will always be 1 but you propably still would get the problems due to clipping as clipping is applied before the depth range. So depth range is practically useless.

If you set z = w you basically put the point directly on the far clipping plane. Theroretically this should be ok but as you say you still get errors. You could make z a tiny bit smaller though.

An alternative would be to use a perspective transform which sets the far clipping plane to infinity and this would avoid the whole problem altogether.

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

remdul
09-24-2007, 10:04 AM
Yes, glDepthRange(1,1) doesn't work for me, the entire skybox is clipped. According to an old ATI paper this *should* work, but I heard it no longer behaves reliably on the latest drivers.

An alternative would be to use a perspective transform which sets the far clipping plane to infinity and this would avoid the whole problem altogether.Does that work? Don't things get clamped or clipped one way or another?

Trenki
09-24-2007, 12:25 PM
Originally posted by remdul:

An alternative would be to use a perspective transform which sets the far clipping plane to infinity and this would avoid the whole problem altogether.Does that work? Don't things get clamped or clipped one way or another?Yes, this should work as it is also needed for correct stencil shadows. Take a look at The Mechanics of Robust Stencil Shadows (http://www.gamasutra.com/features/20021011/lengyel_pfv.htm) or Projection Matrix Tricks (http://www.terathon.com/gdc07_lengyel.ppt) .

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

remdul
09-24-2007, 03:54 PM
I will give it a look. The slides in particular look very interesting.

Thanks!