Reputation: 5641
I did a lot of researches on how filling the depth buffer manually without success. Until here, all I know is a depth texture (GL_DEPTH_COMPONENT) attached to a FBO is filled automatically by OpenGL during the render pass.
For exemple, the following fragment shader code works:
/*
** Output pixel color value.
*/
layout (location = 0) out float FragmentDepth;
/*
** Fragment shader entry point.
*/
void main(void)
{
//Depth filled automatically
}
So if I write the following line of code into the main:
FragmentDepth = 0.0f; //the texture should be black
the result is the same!
So I wonder how it's possible to "tell" to OpenGL do not write automatically in the depth buffer and takes into account my depth equation?
I tried glDepthMask(false) function but of course this solution not work!
Actually, I'd like to customize my depth buffer filling and do not depend on the action of OpenGL in background.
How can I do this?
Is the only way is to use a color buffer (like GL_RGB texture format) to store depth values manually ?
Thanks a lot in advance for your help!
Upvotes: 3
Views: 8020
Reputation: 2455
Custom depth values can be written in fragment shader with gl_FragDepth
. See here: https://www.opengl.org/sdk/docs/man/html/gl_FragDepth.xhtml
A few additional notes:
gl_FragDepth
else you'll get undefined behaviorgl_FragDepth
disables a possible early Z-test and so will typically decrease the performance. So only use it if it's really necessaryUpvotes: 4