mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
graphicsdriver: Optimize shader by removing 'if'
This commit is contained in:
parent
1f46299870
commit
815ed8cda2
@ -203,9 +203,7 @@ float4 FragmentShaderImpl(
|
|||||||
constant float4& color_matrix_translation,
|
constant float4& color_matrix_translation,
|
||||||
constant float& scale) {
|
constant float& scale) {
|
||||||
float4 c = GetColorFromTexel<filter, address>().Do(v, texture, source_size, scale);
|
float4 c = GetColorFromTexel<filter, address>().Do(v, texture, source_size, scale);
|
||||||
if (0 < c.a) {
|
c.rgb /= c.a + (1.0 - sign(c.a));
|
||||||
c.rgb /= 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 = clamp(c, 0.0, 1.0);
|
||||||
|
@ -247,10 +247,9 @@ void main(void) {
|
|||||||
color = mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y);
|
color = mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Un-premultiply alpha
|
// Un-premultiply alpha.
|
||||||
if (0.0 < color.a) {
|
// When the alpha is 0, 1.0 - sign(alpha) is 1.0, which means division does nothing.
|
||||||
color.rgb /= color.a;
|
color.rgb /= color.a + (1.0 - sign(color.a));
|
||||||
}
|
|
||||||
// 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user