开发者

How to write/prevent writing to OpenGL depth buffer in GLSL

开发者 https://www.devze.com 2023-03-01 00:46 出处:网络
I want to write to the OpenGL depth buffer only if the current pixel has an alpha > 0.5 how to do that?

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消