Fix sparkle alpha blending

We should not blend between the fill alpha and the sparkle alpha.
This would cause the sparkle pixel to have lower opacity than the fill,
when the fillAlpha > sparkleAlpha.

We do need to blend the fill and sparkle colors, but their alphas need
to be combined separately.

In the end we then premultiply the alpha into the color.

Test: manual
Bug: 186130682
Change-Id: I519f6c797839feda14e714c7375ee727aba2cf8b
This commit is contained in:
Lucas Dupin
2021-05-06 17:45:59 -07:00
parent 7b0989f35d
commit a79111e05c

View File

@@ -113,10 +113,11 @@ final class RippleShader extends RuntimeShader {
+ " float sparkle = sparkles(densityUv, in_noisePhase) * ring * alpha "
+ "* turbulence;\n"
+ " float fade = min(fadeIn, 1. - fadeOutRipple);\n"
+ " vec4 circle = in_color * (softCircle(p, center, in_maxRadius "
+ " * scaleIn, 0.2) * fade);\n"
+ " float circleAlpha = softCircle(p, center, in_maxRadius * scaleIn, 0.2) * fade;\n"
+ " vec3 color = mix(in_color.rgb, in_sparkleColor.rgb, sparkle);\n"
+ " float mask = in_hasMask == 1. ? sample(in_shader, p).a > 0. ? 1. : 0. : 1.;\n"
+ " return mix(circle, in_sparkleColor, sparkle) * mask;\n"
+ " float a = (in_color.a * circleAlpha + in_sparkleColor.a * sparkle) * mask;\n"
+ " return vec4(color * a, a);\n"
+ "}";
private static final String SHADER = SHADER_UNIFORMS + SHADER_LIB + SHADER_MAIN;
private static final double PI_ROTATE_RIGHT = Math.PI * 0.0078125;