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

Commit da207e22 authored by Yein Jo's avatar Yein Jo
Browse files

Update recent changes in aux

- update snow effect
- update normal blend
- update SnowEffect to use ImageCrop

Bug: 300991599
Test: Verify the effects don't break
Change-Id: Id4331d7389a586b651aaa66b588c34aac7ff4d5d
parent 7b1c0ff1
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -46,14 +46,6 @@ float fbm (vec3 st, vec2 time) {
    return result;
}

vec3 normalBlendWithWhiteSrc(vec3 b, float o) {
    return b * (1. - o) + o;
}

vec3 normalBlend(vec3 b, vec3 f, float o) {
    return b * (1. - o) + f * o;
}

vec4 main(float2 fragCoord) {
    float2 uv = fragCoord / screenSize;
    uv.y /= screenAspectRatio;
+1 −1
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ vec4 main(float2 fragCoord) {
    color.rgb = mix(color.rgb, highlightColor.rgb, rainVisibility * rain.dropMask);

    // Add the foreground. Any effect from here will be in front of the subject.
    color.rgb = mix(color.rgb, colorForeground.rgb, colorForeground.a);
    color.rgb = normalBlend(color.rgb, colorForeground.rgb, colorForeground.a);

    // Generate rain in front of the subject (bigger and faster).
    rain = generateRain(
+4 −2
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ Snow generateSnow(
    in float layerNumber
) {
    /* Grid. */
    float depth = 1. + layerNumber * 0.3;
    // Increase the last number to make each layer more separate from the previous one.
    float depth = 1. + layerNumber * 0.35;
    float speedAdj = 1. + layerNumber * 0.15;
    float layerR = idGenerator(layerNumber);
    snowGridSize *= depth;
@@ -83,7 +84,8 @@ Snow generateSnow(

    // Horizontal movement: Wiggle.
    float wiggleSpeed = 3.0;
    float wiggleAmp = 0.8;
    // Adjust wiggle based on layer number (0 = closer to screen => we want less movement).
    float wiggleAmp = 0.4 + 0.4 * smoothstep(0.5, 2.5, layerNumber);
    // Define the start based on the cell id.
    float horizontalStartAmp = 0.5;
    // Add the wiggle (equation decided by testing in Grapher).
+16 −15
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
uniform shader foreground;
uniform shader background;
uniform shader blurredBackground;
uniform float2 uvOffsets;
uniform float uvScale;
uniform float2 uvOffsetFgd;
uniform float2 uvScaleFgd;
uniform float2 uvOffsetBgd;
uniform float2 uvScaleBgd;
uniform float time;
uniform float screenAspectRatio;
uniform float2 screenSize;
@@ -34,7 +36,7 @@ const vec4 snowColor = vec4(vec3(0.9), 1.);
const vec4 glassTint = vec4(vec3(0.8), 1.); // gray

// snow opacity (how visible it is).
const float snowOpacity = 0.8;
const float snowOpacity = 1.4;

// how frosted the glass is.
const float frostedGlassIntensity = 0.07;
@@ -42,22 +44,21 @@ const float frostedGlassIntensity = 0.07;
vec4 main(float2 fragCoord) {
    float2 uv = fragCoord / screenSize;
    // Adjusts the UVs to have the expected rect of the image.
    float2 uvTexture = fragCoord * uvScale + uvOffsets;

    vec4 colorForeground = foreground.eval(uvTexture);
    vec4 colorForeground = foreground.eval(fragCoord * uvScaleFgd + uvOffsetFgd);
    vec4 colorBackground = background.eval(fragCoord * uvScaleBgd + uvOffsetBgd);
    vec4 color = vec4(0., 0., 0., 1.);

    // Add some slight tint to the frosted glass.

    // Get color of the background texture.
    color.rgb = mix(background.eval(uvTexture).rgb, glassTint.rgb, frostedGlassIntensity);
    color.rgb = mix(colorBackground.rgb, glassTint.rgb, frostedGlassIntensity);
    for (float i = 9.; i > 2.; i--) {
        // Generate snow behind the subject.
        Snow snow = generateSnow(
              /* uvNorm = */ uv,
              /* fragment aspect ratio = */ screenAspectRatio,
              /* time = */ time * 1.25,
              /* Grid size = */ vec2(3.0, 2.0),
              uv,
              screenAspectRatio,
              time * 1.25,
              /* Grid size = */ vec2(2.1, 1.4),
              /* layer number = */ i);

        color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask);
@@ -69,10 +70,10 @@ vec4 main(float2 fragCoord) {
    for (float i = 2.; i >= 0.; i--) {
        // Generate snow behind the subject.
        Snow snow = generateSnow(
              /* uvNorm = */ uv,
              /* fragment aspect ratio = */ screenAspectRatio,
              /* time = */ time * 1.25,
              /* Grid size = */ vec2(3.0, 2.0),
              uv,
              screenAspectRatio,
              time * 1.25,
              /* Grid size = */ vec2(2.1, 1.4),
              /* layer number = */ i);

        color.rgb = mix(color.rgb, snowColor.rgb, snowOpacity * snow.flakeMask);
+18 −0
Original line number Diff line number Diff line
@@ -44,3 +44,21 @@ float wiggle(float time, float wiggleSpeed) {
    return sin(wiggleSpeed * time + 0.5 * sin(wiggleSpeed * 5. * time))
        * sin(wiggleSpeed * time) - 0.5;
}

/*
 * This is the normal blend mode in which the foreground is painted on top of the background based
 * on the foreground opacity.
 *
 * @param b the background color.
 * @param f the foreground color.
 * @param o the mask or the foreground alpha.
 *
 * Note: this blending function expects the foreground to have premultiplied alpha.
 */
vec3 normalBlend(vec3 b, vec3 f, float o) {
    return b * (1. - o) + f;
}

vec3 normalBlendWithWhiteSrc(vec3 b, float o) {
    return b * (1. - o) + o;
}
Loading