Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...