PDA

View Full Version : Clip planes affect depth function?



halo
03-06-2006, 02:59 PM
I am drawing a projected shadow onto a floor, by drawing the floor in a second pass, with a shadow texture, and a darken blend mode. I am clipping away the unneeded parts of the floor with glClipPlane(), so that I don't have to blend a lot of pixels that would be invisible anyways. On this card, the max clip planes if 6.

If I use 0 to 2 clipping planes, everything appears fine. If I use more than two clipping planes, the shadow z-fights with the floor. I am using a depth function of GL_LEQUAL, and the shadow looks fine if no clipping planes are used. I am sure the plane equations are correct, and there is not a clipping plane lying along the floor. It does not matter which clipping planes I use, it always z-fights if 3 or more clipping planes are enabled.

The card is a GE Force 440 MX, which is probably the problem, but I still need to try to solve this.

Komat
03-06-2006, 04:14 PM
If cliping planes are implemented using real geometricaly clipping and not per pixel trick with special texture, the resulting geometry and vertex positions is likely to be slightly different than if clipping planes are not used and z-fighting will result.
The GF4MX supports 2 texture units so if you use only one texture, driver may be able to emulate up to 2 clipping planes with the unused texture unit and alpha test. If then number of clip planes increases beyond that, driver can not use that trick anymore (GF4MX does not support 3d textures if I remember correctly) and has to do geometric clipping. Other hw or driver may (and will) behave differently so you can not relly on this behaviour.
To fight the z-fighting you can use the glPolygonOffset functionality to move depth values in such way that shadow pass geometry is considered before the first pass geometry.