简体   繁体   English

glsl es 2.0丢弃和深度缓冲区

[英]glsl es 2.0 discard and depth buffer

OpenGL ES 2.0 can't write to Depth Buffer, since it doesn't have gl_FragDepth , but if I do discard - will it affect Depth Buffer (I mean, not overwrite it with CURRENT gl_FragCoord.z , but leave as is)? OpenGL ES 2.0无法写入深度缓冲区,因为它没有gl_FragDepth ,但是如果我discard ,它将影响深度缓冲区(我的意思是,不要用CURRENT gl_FragCoord.z覆盖它,而是保持原样)?

Something like this: 像这样:

void main() {
   if (sin(x) > 0.5 ){
      discard;
   } else {
      gl_FragColor = (1.0, 1.0, 1.0, 1.0);
   }
}

I expect to get holes in Depth Buffer, in discard cases. discard情况下,我希望在深度缓冲区中出现漏洞。

Your statement saying "OpenGL ES 2.0 can't write to Depth Buffer" is somewhat misleading. 您所说的“ OpenGL ES 2.0无法写入深度缓冲区”的说法有些误导。 It will write to the depth buffer, as long as there is a depth buffer in the current framebuffer, and depth buffer writes are enabled. 只要当前帧缓冲区中有深度缓冲区,并且将启用深度缓冲区写入,它将写入深度缓冲区。

Not having a writable gl_FragDepth variable in the fragment shader means that you can't modify the depth value in the fragment shader. 在片段着色器中没有可写的gl_FragDepth变量意味着您无法在片段着色器中修改深度值。 It's alway the incoming depth value that is written to the depth buffer. 始终将传入的深度值写入深度缓冲区。

If you discard a fragment, neither the color nor the depth value is written. 如果discard片段,则不会写入颜色或深度值。 So yes, if you discard a fragment, the depth buffer will not be modified for that fragment. 因此,是的,如果您丢弃一个片段,则不会为该片段修改深度缓冲区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM