shading program the fiddles with Z values

Hi all,
i’m looking for an example of a shader program that changes the depth values, and also would appreciate a short explanation what kind of effects this can produce.

thank you!

void main() { gl_FragColor = vec4(1,1,1,1); gl_FragDepth = 1; }

This function sets the color to white and the depth to 1. Not terribly interesting but I hope you’ll get the idea.

ok 10x but i need i was hoping for something more meaningful -
and also I meant some program the utilizes the incoming fragment’s Z value and not setting the output FragDepth.

gl_FragDepth is read and write variable in fragment shader. How is going to use it is limited by your imagination.

Keep in mind that setting gl_FragDepth may have some performance implications, because early-z and other optimizations can no longer predict the z value (in the same way that happens with alpha-testing).