mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphicsdriver: Optimize shaders
Simplified the case when a color matrix is not used.
This commit is contained in:
parent
1c3113e763
commit
3ecb00f717
@ -121,7 +121,6 @@ template<uint8_t address>
|
||||
struct GetColorFromTexel<FILTER_NEAREST, address> {
|
||||
inline float4 Do(VertexOut v, texture2d<float> texture, constant float2& source_size, float scale) {
|
||||
constexpr sampler texture_sampler(filter::nearest);
|
||||
const float2 texel_size = 1 / source_size;
|
||||
|
||||
float2 p = AdjustTexelByAddress<address>(v.tex, v.tex_region);
|
||||
if (p.x < v.tex_region[0] ||
|
||||
@ -203,13 +202,17 @@ float4 FragmentShaderImpl(
|
||||
constant float4& color_matrix_translation,
|
||||
constant float& scale) {
|
||||
float4 c = GetColorFromTexel<filter, address>().Do(v, texture, source_size, scale);
|
||||
c.rgb /= c.a + (1.0 - sign(c.a));
|
||||
if (useColorM) {
|
||||
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 *= v.color;
|
||||
c = clamp(c, 0.0, 1.0);
|
||||
c.rgb *= c.a;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -256,19 +256,21 @@ void main(void) {
|
||||
color = mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y);
|
||||
#endif
|
||||
|
||||
#if defined(USE_COLOR_MATRIX)
|
||||
// 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));
|
||||
|
||||
#if defined(USE_COLOR_MATRIX)
|
||||
// Apply the color matrix or scale.
|
||||
color = (color_matrix_body * color) + color_matrix_translation;
|
||||
#endif
|
||||
|
||||
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
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user