The use case is essentially the same as Alpha Blending with Integer Texture for Object Picking
One of the answers is to discard fragments that fail the alpha test.
So I'm wondering if it's possible to discard
for one render target in a framebuffer, while still writing to the others. In my initial attempt of simply not writing the out
value for that target, it seems to still write the default value (0
, uvec4(0)
, etc.)
No, if you discard
then no buffers will be updated, regardless of whether you assigned to the output variable beforehand or not.
The
discard
keyword is only allowed within fragment shaders. It can be used within a fragment shader to abandon the operation on the current fragment. This keyword causes the fragment to be discarded and no updates to any buffers will occur.– The OpenGL ES Shading Language Specification, Page 58 (Page 64 in the PDF)
(emphasis mine)
If blending is enabled, then you could write a transparent color to the output that you want to "discard".
// discard;
out = vec4(0.0, 0.0, 0.0, 0.0);