问题
I'm saving the depth value via fragmend shader in the color buffer of the main framebuffer (in 'opengl es' there is no way to read the depth buffer via glReadPixels()). Additionally I need the maximum precision of 32-bit, that's why I use the rgba of the colorbuffer. But I realized that using also the alpha channel the results are not always correct, maybe because of some post fragmend operations. The following works:
- set fragColor.a = 1 (but then I'm loosing one channel) or
- set gl_FragDepth = 0.0 (works fine also with alpha != 1)
fragShader
void main(void) {
gl_FragDepth = 0.0;//gl_FragCoord.z;
}
But why does this work if the depth value in depth buffer is always 0.0?
来源:https://stackoverflow.com/questions/50288912/what-does-in-opengl-exactly-means-gl-fragdepth-0-0