From eb3c45c8affca655a16b3f0804f7af54652576bd Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 2 Oct 2022 00:18:47 +0900 Subject: [PATCH] Revert "internal/graphicsdriver/opengl, metal, directx: skip multiplying a scale when a color matrix is used" This reverts commit b457dc330742b3e6421aa2d1dcd098296f4c1aa1. Reason: a color scale might be used with ColorM (DrawTriangles) --- internal/graphicsdriver/directx/pipeline_windows.go | 3 ++- internal/graphicsdriver/metal/graphics_darwin.go | 1 + internal/graphicsdriver/opengl/defaultshader.go | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/graphicsdriver/directx/pipeline_windows.go b/internal/graphicsdriver/directx/pipeline_windows.go index 8ce84a356..1f5e7df8f 100644 --- a/internal/graphicsdriver/directx/pipeline_windows.go +++ b/internal/graphicsdriver/directx/pipeline_windows.go @@ -221,7 +221,8 @@ float4 PSMain(PSInput input) : SV_TARGET { color = mul(color_matrix_body, color) + color_matrix_translation; // Premultiply alpha color.rgb *= color.a; - // Do not apply the color scale as the scale should always be (1, 1, 1, 1) when a color matrix is used. + // Apply color scale. + color *= input.color; // Clamp the output. color.rgb = min(color.rgb, color.a); return color; diff --git a/internal/graphicsdriver/metal/graphics_darwin.go b/internal/graphicsdriver/metal/graphics_darwin.go index f128a4529..351b638d1 100644 --- a/internal/graphicsdriver/metal/graphics_darwin.go +++ b/internal/graphicsdriver/metal/graphics_darwin.go @@ -197,6 +197,7 @@ struct FragmentShaderImpl { c.rgb /= c.a + (1.0 - sign(c.a)); c = (color_matrix_body * c) + color_matrix_translation; c.rgb *= c.a; + c *= v.color; c.rgb = min(c.rgb, c.a); } else { c *= v.color; diff --git a/internal/graphicsdriver/opengl/defaultshader.go b/internal/graphicsdriver/opengl/defaultshader.go index 60bce1935..148f9b1e0 100644 --- a/internal/graphicsdriver/opengl/defaultshader.go +++ b/internal/graphicsdriver/opengl/defaultshader.go @@ -237,12 +237,14 @@ void main(void) { color = (color_matrix_body * color) + color_matrix_translation; // Premultiply alpha color.rgb *= color.a; - // Do not apply the color scale as the scale should always be (1, 1, 1, 1) when a color matrix is used. + // Apply color scale. + color *= varying_color_scale; // Clamp the output. color.rgb = min(color.rgb, color.a); # else - // Apply the color scale. + // Apply color scale. color *= varying_color_scale; + // No clamping needed as the color matrix shader is used then. # endif // defined(USE_COLOR_MATRIX) gl_FragColor = color;