From 742bbb4ccd07420063253df8998e4eaf74b1608a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 17 Feb 2019 15:04:59 +0900 Subject: [PATCH] graphicsdriver: Simplify clamping color values For negative values, OpenGL (and Metal) should take care of them so we don't have to care. --- internal/graphicsdriver/metal/driver.go | 3 +-- internal/graphicsdriver/opengl/shader.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/graphicsdriver/metal/driver.go b/internal/graphicsdriver/metal/driver.go index e111e2a66..e9116216c 100644 --- a/internal/graphicsdriver/metal/driver.go +++ b/internal/graphicsdriver/metal/driver.go @@ -206,13 +206,12 @@ float4 FragmentShaderImpl( c.rgb /= c.a + (1.0 - sign(c.a)); c = (color_matrix_body * c) + color_matrix_translation; c *= v.color; - c = clamp(c, 0.0, 1.0); c.rgb *= c.a; } else { float4 s = v.color; c *= float4(s.r, s.g, s.b, 1.0) * s.a; - c = clamp(c, 0.0, c.a); } + c = min(c, c.a); return c; } diff --git a/internal/graphicsdriver/opengl/shader.go b/internal/graphicsdriver/opengl/shader.go index 8941ad33f..f31eb4e6e 100644 --- a/internal/graphicsdriver/opengl/shader.go +++ b/internal/graphicsdriver/opengl/shader.go @@ -263,15 +263,15 @@ void main(void) { // Apply the color matrix or scale. color = (color_matrix_body * color) + color_matrix_translation; color *= varying_color_scale; - color = clamp(color, 0.0, 1.0); // Premultiply alpha color.rgb *= color.a; #else vec4 s = varying_color_scale; color *= vec4(s.r, s.g, s.b, 1.0) * s.a; - color = clamp(color, 0.0, color.a); #endif + color = min(color, color.a); + gl_FragColor = color; } `