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

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

Add static rain droplets on the glass surface.

Bug: 325090421
Test: Manual
Flag: NA
Change-Id: I0194d91ec739f966c28a5cb9134589fe9ba27c98
parent 7bf01595
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -145,3 +145,49 @@ GlassRain generateGlassRain(
    return GlassRain(
        dropPos, cellMainDropMask, trailDropsPos, cellDroppletsMask, cellTrailMask, cellUv);
}

/**
 * Generate rain drops that stay in place on the glass surface.
 */
vec3 generateStaticGlassRain(vec2 uv, half screenAspectRatio, half time) {
    vec2 gridSize = vec2(15., 15.);
    // Aspect ratio impacts visible cells.
    gridSize.y /= screenAspectRatio;
    // scale the UV to allocate number of rows and columns.
    vec2 gridUv = uv * gridSize;
    // Invert y (otherwise it goes from 0=top to 1=bottom).
    gridUv.y = 1. - gridUv.y;
    // Generate column id, to offset columns vertically (so rain is not aligned).
    float columnId = idGenerator(floor(gridUv.x));
    gridUv.y += columnId * 5.6;

    // Get the cell ID based on the grid position. Value from 0 to 1.
    float cellId = idGenerator(floor(gridUv));

    // Draw rain drops with a probability based on the cell id.
    if (cellId < 0.8) {
        return vec3(0.);
    }

    // For each cell, we set the internal UV from -0.5 (left, bottom) to 0.5 (right, top).
    vec2 cellUv = fract(gridUv) - 0.5;
    vec2 pixUv = cellUv;
    pixUv.x *= -1;
    vec2 pixDistance = screenSize * pixUv / gridSize;

    float delay = 3.5173;
    float duration = 8.2;
    float t = time + 100. * cellId;
    float circletime = floor(t / (duration + delay));
    float delayOffset = idGenerator(floor(gridUv) + vec2(circletime, 43.14 * cellId));
    float normalizedTime = map(/* value */     mod(t, duration + delay) - delay * delayOffset,
                               /* in range */  0, duration,
                               /* out range */ 0, 1);
    // Apply a curve to the time.
    normalizedTime *= normalizedTime;

    vec2 pos = cellUv * (1.5 - 0.5 * cellId + normalizedTime * 50.);
    float mask = smoothstep(0.3, 0.2, length(pos)) * smoothstep(0.2, 0.06, normalizedTime);

    return vec3(pos * 0.19, mask);
}
+9 −4
Original line number Diff line number Diff line
@@ -58,7 +58,12 @@ vec4 main(float2 fragCoord) {
    droppletsUvMasked = mix(droppletsUvMasked,
        medDrippingRain.dropplets * medDrippingRain.droppletsMask, medDrippingRain.droppletsMask);

    // 4. Distort uv for the rain drops and dropplets.
    // 4. Add static rain droplets on the glass surface. (They stay in place and dissapate.)
    vec3 staticRain = generateStaticGlassRain(uv, screenAspectRatio, time);
    dropMask = max(dropMask, staticRain.z);
    dropUvMasked = mix(dropUvMasked, staticRain.xy * staticRain.z, staticRain.z);

    // 5. Distort uv for the rain drops and dropplets.
    float distortionDrop = -0.1;
    vec2 uvDiffractionOffsets =
        distortionDrop * dropUvMasked;
@@ -70,20 +75,20 @@ vec4 main(float2 fragCoord) {
    vec3 sampledColor = texture.eval(fragCoord + uvDiffractionOffsets * s).rgb;
    color.rgb = mix(color.rgb, sampledColor, max(dropMask, droppletsMask));

    // 5. Add color tint to the rain drops.
    // 6. Add color tint to the rain drops.
    color.rgb = mix(
        color.rgb,
        dropTint,
        dropTintIntensity * smoothstep(0.7, 1., max(dropMask, droppletsMask)));

    // 6. Add highlight to the drops.
    // 7. Add highlight to the drops.
    color.rgb = mix(
        color.rgb,
        highlightColor,
        highlightIntensity
            * smoothstep(0.05, 0.08, max(dropUvMasked * 1.7, droppletsUvMasked * 2.6)).x);

    // 7. Add shadows to the drops.
    // 8. Add shadows to the drops.
    color.rgb = mix(
        color.rgb,
        contactShadowColor,
+6 −0
Original line number Diff line number Diff line
@@ -75,3 +75,9 @@ vec3 normalBlend(vec3 b, vec3 f, float o) {
vec3 normalBlendWithWhiteSrc(vec3 b, float o) {
    return b * (1. - o) + o;
}

float map(float value, float inMin, float inMax, float outMin, float outMax) {
    float v = clamp(value, inMin, inMax);
    float p = (v - inMin) / (inMax - inMin);
    return p * (outMax - outMin) + outMin;
}