more z-Buffer control

something like writing a specified value to z-buffer if test passes, instead of depthvalue …

Can’t this be done with the help of the stencil buffer?

The short answer: No.

I wanted this feature for doing a trick for shadowing actually.

V-man

Actually it can be done with the help of a stencil buffer in two passes, as long as the depthvalue is a constant.

First pass:
Clear stencil buffer
Depth testing enabled
Set stencil to write 1 for all pixels that pass depth testing
Draw object

Second pass:
Mask color buffer
Set depth range (near and far) to value to write
Set depth function to GL_ALWAYS
Enable stencil testing, set test to pass on stencil values of 1, otherwise fail
Draw object

The result is that for pixels that have a stencil value of 1 from the first pass, in the second pass will be assigned the desired zdepth.

The problem is the object to render. It must be billboarded and be at the proper depth. Maybe a few other things like depth range need to be changed too but that’s not an issue.

Just a small problem…

V-man