What I'm want to do in OpenGL using C++ and GLSL: When texture has alpha (texture.a! = 1.0;) then this pixel is not written to the depth buffer. (for color buffer it is written) Write depth occurs only when a pixel texture.a == 1.0;
Discarding in shader is not a solution - then this pixel is not written to color buffer.
Any ideas?
@UPDATE: Example: I've got some UI images rendered by OpenGL. Some of them have alpha in corners. In scene rendering I have "depth prepass" to save some pixels by not calculating light on them. I want to also get UI images to that prepass - but only completely opaque pixels (alpha = 1.0).
gl_FragDepth = 0.0
for opaque fragments,gl_FragDepth = 1.0
for anything with an alpha value != 1.0. Either approach works, but you have to re-draw the GUI every frame if you do it this way. – Andon M. Coleman