mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
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:
parent
3d8a45a770
commit
742bbb4ccd
@ -206,13 +206,12 @@ float4 FragmentShaderImpl(
|
|||||||
c.rgb /= c.a + (1.0 - sign(c.a));
|
c.rgb /= c.a + (1.0 - sign(c.a));
|
||||||
c = (color_matrix_body * c) + color_matrix_translation;
|
c = (color_matrix_body * c) + color_matrix_translation;
|
||||||
c *= v.color;
|
c *= v.color;
|
||||||
c = clamp(c, 0.0, 1.0);
|
|
||||||
c.rgb *= c.a;
|
c.rgb *= c.a;
|
||||||
} else {
|
} else {
|
||||||
float4 s = v.color;
|
float4 s = v.color;
|
||||||
c *= float4(s.r, s.g, s.b, 1.0) * s.a;
|
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;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,15 +263,15 @@ void main(void) {
|
|||||||
// Apply the color matrix or scale.
|
// Apply the color matrix or scale.
|
||||||
color = (color_matrix_body * color) + color_matrix_translation;
|
color = (color_matrix_body * color) + color_matrix_translation;
|
||||||
color *= varying_color_scale;
|
color *= varying_color_scale;
|
||||||
color = clamp(color, 0.0, 1.0);
|
|
||||||
// Premultiply alpha
|
// Premultiply alpha
|
||||||
color.rgb *= color.a;
|
color.rgb *= color.a;
|
||||||
#else
|
#else
|
||||||
vec4 s = varying_color_scale;
|
vec4 s = varying_color_scale;
|
||||||
color *= vec4(s.r, s.g, s.b, 1.0) * s.a;
|
color *= vec4(s.r, s.g, s.b, 1.0) * s.a;
|
||||||
color = clamp(color, 0.0, color.a);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
color = min(color, color.a);
|
||||||
|
|
||||||
gl_FragColor = color;
|
gl_FragColor = color;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user