From a79111e05c0b28a48da88b0c30806ba0e84fa679 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Thu, 6 May 2021 17:45:59 -0700 Subject: [PATCH] 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 --- graphics/java/android/graphics/drawable/RippleShader.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/graphics/java/android/graphics/drawable/RippleShader.java b/graphics/java/android/graphics/drawable/RippleShader.java index 2b4d5b45a0099..d00492cedb38d 100644 --- a/graphics/java/android/graphics/drawable/RippleShader.java +++ b/graphics/java/android/graphics/drawable/RippleShader.java @@ -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;