Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 916a9c6c authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Further shader optimizations

- Removed unused variable and function
- Made output colors premultiplied

Test: visual
Fixes: 182417605
Change-Id: Ie8caecd08a3cd1a784203ad2e5010fc741ff7f86
parent 10f93838
Loading
Loading
Loading
Loading
+3 −54
Original line number Diff line number Diff line
@@ -61,53 +61,6 @@ final class RippleShader extends RuntimeShader {
            + "  return 1. - smoothstep(1. - blurHalf, 1. + blurHalf, d / radius);\n"
            + "}\n"
            + "\n"
            + "float softRing(vec2 uv, vec2 xy, float radius, float blur) {\n"
            + "  float thickness = 0.4;\n"
            + "  float circle_outer = softCircle(uv, xy, radius + thickness * 0.5, blur);\n"
            + "  float circle_inner = softCircle(uv, xy, radius - thickness * 0.5, blur);\n"
            + "  return circle_outer - circle_inner;\n"
            + "}\n"
            + "\n"
            + "struct Viewport {\n"
            + "  float aspect;\n"
            + "  vec2 uv;\n"
            + "  vec2 resolution_pixels;\n"
            + "};\n"
            + "\n"
            + "Viewport getViewport(vec2 frag_coord, vec2 resolution_pixels) {\n"
            + "  Viewport v;\n"
            + "  v.aspect = resolution_pixels.y / resolution_pixels.x;\n"
            + "  v.uv = frag_coord / resolution_pixels;\n"
            + "  v.uv.y = (1.0 - v.uv.y) * v.aspect;\n"
            + "  v.resolution_pixels = resolution_pixels;\n"
            + "  return v;\n"
            + "}\n"
            + "\n"
            + "vec2 getTouch(vec2 touch_position_pixels, Viewport viewport) {\n"
            + "  vec2 touch = touch_position_pixels / viewport.resolution_pixels;\n"
            + "  touch.y *= viewport.aspect;\n"
            + "  return touch;\n"
            + "}\n"
            + "\n"
            + "struct Wave {\n"
            + "  float ring;\n"
            + "  float circle;\n"
            + "};\n"
            + "\n"
            + "Wave getWave(Viewport viewport, vec2 touch, float progress) {\n"
            + "  float fade = pow((clamp(progress, 0.8, 1.0)), 8.);\n"
            + "  Wave w;\n"
            + "  w.ring = max(softRing(viewport.uv, touch, progress, 0.45) - fade, 0.);\n"
            + "  w.circle = softCircle(viewport.uv, touch, 2.0 * progress, 0.2) - progress;\n"
            + "  return w;\n"
            + "}\n"
            + "\n"
            + "vec4 getRipple(vec4 color, float loudness, float sparkle, Wave wave) {\n"
            + "  float alpha = wave.ring * sparkle * loudness\n"
            + "        + wave.circle * color.a;\n"
            + "  return vec4(color.rgb, saturate(alpha));\n"
            + "}\n"
            + "\n"
            + "float getRingMask(vec2 frag, vec2 center, float r, float progress) {\n"
            + "      float dist = distance(frag, center);\n"
            + "      float expansion = r * .6;\n"
@@ -126,19 +79,15 @@ final class RippleShader extends RuntimeShader {
            + "    float fadeIn = subProgress(0., 0.175, in_progress);\n"
            + "    float fadeOutNoise = subProgress(0.375, 1., in_progress);\n"
            + "    float fadeOutRipple = subProgress(0.375, 0.75, in_progress);\n"
            + "    Viewport vp = getViewport(p, in_resolution);\n"
            + "    vec2 touch = getTouch(in_origin, vp);\n"
            + "    Wave w = getWave(vp, touch, in_progress * 0.25);\n"
            + "    float ring = getRingMask(p, in_origin, in_maxRadius, fadeIn);\n"
            + "    float alpha = min(fadeIn, 1. - fadeOutNoise);\n"
            + "    float sparkle = sparkles(p, in_progress * 0.25 + in_secondsOffset)\n"
            + "        * ring * alpha;\n"
            + "    vec4 r = getRipple(in_color, 1., sparkle, w);\n"
            + "    float fade = min(fadeIn, 1.-fadeOutRipple);\n"
            + "    vec4 circle = vec4(in_color.rgb, softCircle(p, in_origin, in_maxRadius "
            + "      * fadeIn, 0.2) * fade * in_color.a);\n"
            + "    vec4 circle = in_color * (softCircle(p, in_origin, in_maxRadius "
            + "      * fadeIn, 0.2) * fade);\n"
            + "    float mask = in_hasMask == 1. ? sample(in_shader).a > 0. ? 1. : 0. : 1.;\n"
            + "    return mix(circle, vec4(1.), sparkle * mask);\n"
            + "    return mix(circle, vec4(sparkle), sparkle) * mask;\n"
            + "}";
    private static final String SHADER = SHADER_UNIFORMS + SHADER_LIB + SHADER_MAIN;