1

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.)

vallentin
  • 23,478
  • 6
  • 59
  • 81
davidkomer
  • 3,020
  • 2
  • 23
  • 58

1 Answers1

2

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);
vallentin
  • 23,478
  • 6
  • 59
  • 81
  • On mobile devices, another option is to fetch the colour of the previous fragment (gl_LastFragData/gl_LastFragColorARM). But not all OpenGL ES implementations support this, and in particular I don't think WebGL supports this. – Andrea Jan 06 '21 at 10:53