I want to write to the OpenGL depth buffer only if the current pixel has an alpha > 0.5 how to do that?
If the pixel has alpha < 0.5, i want to render the color but not write it's depth to the depth buffer. The command discard
isn't what I'm looking for, since it discards both, color and depth information; I only want to discard depth information.
There is the gl_FragDepth
variable that can be set, but to which value?
And for the case alpha < 0.5, how to leave gl_FragDepth
unchanged?
Do I have to use FBOs for this, or should it also work without? The project I'm working on, is a GLES 2.0 Android project
The values in the depth buffer can be a point's z-coordinate or its homogeneous w-coordinate - from the point's (x,y,z,w) location in projection space. A depth buffer that uses z values is often called a z-buffer, and one that uses w values is called a w-buffer.
A depth buffer, also known as a z-buffer, is a type of data buffer used in computer graphics to represent depth information of objects in 3D space from a particular perspective. Depth buffers are an aid to rendering a scene to ensure that the correct polygons properly occlude other polygons.
To enable depth testing, call glEnable with GL_DEPTH_TEST. When rendering to a framebuffer that has no depth buffer, depth testing always behaves as though the test is disabled. When depth testing is disabled, writes to the depth buffer are also disabled.
z' = (2^d -1 ) * ((far + near)/(2 * (far - near) + (1 / z) * (-far * near) / (far - near) + 1/2) when d is the depth of the z-buffer (24 bits at my case) and z is the z value of the vertex.
I've solved the problem for me by using
glDepthMask(false)
This command disables writing to to the depth buffer but still performs depth-testing. I've simply rendered my transparent objects after all other objects and got exactly the result I was looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With