graphicsdriver: Simplify clamping color values

For negative values, OpenGL (and Metal) should take care of them
so we don't have to care.
This commit is contained in:
Hajime Hoshi 2019-02-17 15:04:59 +09:00
parent 3d8a45a770
commit 742bbb4ccd
2 changed files with 3 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;
}
`