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:
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?
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?
Is there any recommanded scenerio that I should use dual-source 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.