Confusion about dual-source blending

I recently know dual-soruce blending technique from some computer graphics materials. It is fresh to me although it is not a new technique. And after some researching, I got that, to use this, besides setting proper blend state parameters, I need to write multiple outputs for one attachment/buffer in a fragment shader. For example in GLSL, I need to speicify an additional parameter called index in fragment shader’s output layout qualifier, like:

layout (location = 0, index = 0) out vec4 outputColor0;
layout (location = 0, index = 1) out vec4 outputColor1;

Then, I write value to them respectively.

But I am still confused about this technique. My questions are:

  1. Does this index parameter in layout qualifier only exists for dual-source blending? Or, is there any other scenerios in whch I can use index parameter?
  2. If I use multiple outputs for one attachment/buffer in a fragment shader, but I do not enable duel-source blending when setting blend state, or even disable blending at all. Do additional outpus (I mean ouputs specified with index which is greater than 0) contribute to final value in a attachment/buffer?
  3. Is there any recommanded scenerio that I should use dual-source blending?

Thanks a lot!

1 Like

It’s only used for blending.

No. If blending is disabled or the blending function is one which doesn’t use the second source colour, then it has no effect. The “source colour” used for blending is always the first source colour (index 0). The second source colour (index 1) is only used as a (source or destination) blending factor.

The extension which introduced it (ARB_blend_func_extended) gives the following examples:

Logically, there doesn’t seem to be much use for it unless you are using the second source colour as a destination factor. As a source factor, you could just perform the multiplication in the shader.

It’s nice. Thanks for your answers!