Fix keying matte operation in GPU compositor

The calculation of the matte could lead to a division-by-zero
leading to completely different results on different graphics
backends.

Perform the same checks of the input and key saturation before
performing division as it is done in the CPU compositors.

The `node keying matte` test is still failing on Metal, but the
look of the result is much closer to what it would be.
This commit is contained in:
Sergey Sharybin
2024-01-23 14:01:08 +01:00
committed by Sergey Sharybin
parent aecf1fba84
commit dd1374fb7b

View File

@@ -39,7 +39,19 @@ void main()
float input_saturation = compute_saturation(input_color, key_saturation_indices);
float key_saturation = compute_saturation(key_color, key_saturation_indices);
float matte = 1.0f - clamp(input_saturation / key_saturation, 0.0, 1.0);
float matte;
if (input_saturation < 0) {
/* Means main channel of pixel is different from screen, assume this is completely a
* foreground. */
matte = 1.0f;
}
else if (input_saturation >= key_saturation) {
/* Matched main channels and higher saturation on pixel is treated as completely background. */
matte = 0.0f;
}
else {
matte = 1.0f - clamp(input_saturation / key_saturation, 0.0, 1.0);
}
imageStore(output_img, texel, vec4(matte));
}