graphicsdriver: Optimize shader by removing 'if'

This commit is contained in:
Hajime Hoshi 2019-02-16 16:22:51 +09:00
parent 1f46299870
commit 815ed8cda2
2 changed files with 4 additions and 7 deletions

View File

@ -203,9 +203,7 @@ float4 FragmentShaderImpl(
constant float4& color_matrix_translation,
constant float& scale) {
float4 c = GetColorFromTexel<filter, address>().Do(v, texture, source_size, scale);
if (0 < c.a) {
c.rgb /= c.a;
}
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);

View File

@ -247,10 +247,9 @@ void main(void) {
color = mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y);
#endif
// Un-premultiply alpha
if (0.0 < color.a) {
color.rgb /= color.a;
}
// Un-premultiply alpha.
// When the alpha is 0, 1.0 - sign(alpha) is 1.0, which means division does nothing.
color.rgb /= color.a + (1.0 - sign(color.a));
// Apply the color matrix or scale.
color = (color_matrix_body * color) + color_matrix_translation;
color *= varying_color_scale;