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

Commit 2e3b238e authored by Yein Jo's avatar Yein Jo
Browse files

[Sync snow effect] update snow accumulation

Bug: 325090421
Test: Manual
Flag: NA
Change-Id: I1bd6554f2b58182d29d2d0a16898767e9cfd62a4
parent b2a3bb87
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -15,8 +15,8 @@
 */

uniform shader foreground;
uniform float2 imageSize;
uniform half intensity;
uniform half imageWidth;
uniform half snowThickness;

#include "shaders/simplex2d.agsl"
#include "shaders/utils.agsl"
@@ -27,17 +27,19 @@ float random(vec2 uv) {

vec4 main(float2 fragCoord) {
    // fragCoord should be already the adjusted UVs to have the expected rect of the image.
    float variation = 0.5 + 0.5 * simplex2d(25. * fragCoord / imageSize.xx);
    float distance = 8. * variation * intensity;
    vec2 uv = fragCoord / imageWidth;
    float variation = 0.3 + simplex2d(11. * uv);
    float distance = 20. * variation * snowThickness;

    float aN = foreground.eval(fragCoord + vec2(0., distance)).a;
    float aS = foreground.eval(fragCoord + vec2(0., -distance)).a;
    float dY = (aN - aS) * 0.5;
    dY = max(dY, 0.0);

    float accumulatedSnow = smoothstep(0.1, 1.8, sqrt(dY * dY) * 5.0);
    float accumulatedSnow = smoothstep(0.1, 1.8, dY * 5.0);
    vec4 color = vec4(0., 0., 0., 1.);
    color.r = accumulatedSnow;
    color.g = random(fragCoord / imageSize.xx);
    color.g = random(uv);
    color.b = variation;
    return color;
}
+5 −5
Original line number Diff line number Diff line
@@ -32,9 +32,9 @@ uniform float2 screenSize;

/* Constants that can be modified. */
// Snow tint.
const vec4 snowColor = vec4(vec3(0.9), 1.);
const vec3 snowColor = vec3(0.9);
// Glass tint.
const vec4 glassTint = vec4(vec3(0.8), 1.); // gray
const vec3 glassTint = vec3(0.8); // gray

// snow opacity (how visible it is).
const float snowOpacity = 1.4;
@@ -54,7 +54,7 @@ vec4 main(float2 fragCoord) {
    // Add some slight tint to the frosted glass.

    // Get color of the background texture.
    color.rgb = mix(colorBackground.rgb, glassTint.rgb, frostedGlassIntensity);
    color.rgb = mix(colorBackground.rgb, glassTint, frostedGlassIntensity);
    for (half i = 9.; i > 2.; i--) {
        // Generate snow behind the subject.
        // Normalized layer index.
@@ -66,7 +66,7 @@ vec4 main(float2 fragCoord) {
              /* Grid size = */ vec2(mix(3.0, 6.0, idx), mix(1.0, 3.0, idx)),
              /* layer number = */ i);

        color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask);
        color.rgb = mix(color.rgb, snowColor, snowOpacity * snow.flakeMask);
    }

    // Add the foreground. Any effect from here will be in front of the subject.
@@ -87,7 +87,7 @@ vec4 main(float2 fragCoord) {
              /* Grid size = */ vec2(i + 1., 1.4),
              /* layer number = */ i);

        color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask);
        color.rgb = mix(color.rgb, snowColor, snowOpacity * snow.flakeMask);
    }

    /* Debug snow */
+3 −4
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ class SnowEffect(
            "intensity",
            snowConfig.colorGradingIntensity * intensity
        )
        snowConfig.accumulatedSnowShader.setFloatUniform("intensity", intensity)
        snowConfig.accumulatedSnowShader.setFloatUniform("snowThickness", intensity)

        // Regenerate accumulated snow since the uniform changed.
        generateAccumulatedSnow()
@@ -166,9 +166,8 @@ class SnowEffect(
    private fun generateAccumulatedSnow() {
        val renderingCanvas = frameBuffer.beginDrawing()
        snowConfig.accumulatedSnowShader.setFloatUniform(
            "imageSize",
            renderingCanvas.width.toFloat(),
            renderingCanvas.height.toFloat()
            "imageWidth",
            renderingCanvas.width.toFloat()
        )
        snowConfig.accumulatedSnowShader.setInputBuffer(
            "foreground",