是否可以在写入另一个绘图缓冲区的同时丢弃一个绘图缓冲区?

Is it possible to discard for one draw buffer while still writing to another?

用例与Alpha Blending with Integer Texture for Object Picking

基本相同

其中一个 的答案是丢弃未通过 alpha 测试的片段。

所以我想知道是否有可能 discard 用于帧缓冲区中的一个渲染目标,同时仍然写入其他渲染目标。在我最初尝试简单地不为该目标写入 out 值时,它似乎仍然写入默认值(0uvec4(0) 等)

不,如果您 discard 那么无论您是否事先分配给输出变量,都不会更新缓冲区。

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)

(强调我的)

如果启用了混合,那么您可以将透明颜色写入要“丢弃”的输出。

// discard;
out = vec4(0.0, 0.0, 0.0, 0.0);