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

Commit ec06925d authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 13010426 from e4b9eea5 to 25Q2-release

Change-Id: I91988007235bce299f0f4fc7b5181b97cad63b47
parents 08d207c3 e4b9eea5
Loading
Loading
Loading
Loading
+0 −105
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

uniform shader texture;
uniform float time;
uniform float screenAspectRatio;
uniform float gridScale;
uniform float2 screenSize;
uniform half intensity;

#include "shaders/constants.agsl"
#include "shaders/utils.agsl"
#include "shaders/glass_rain.agsl"
#include "shaders/rain_constants.agsl"

vec4 main(float2 fragCoord) {
    // 0. Calculate UV and add a bit of noise so that the droplets are not perfect circles.
    float2 uv = vec2(valueNoise(fragCoord) * 0.015 - 0.0025) + fragCoord / screenSize;

    // 1. Generate small glass rain.
    GlassRain smallDrippingRain = generateGlassRain(
         uv,
         screenAspectRatio,
         time * 0.7,
         /* Grid size = */ vec2(5.0, 1.6) * gridScale,
         intensity * 0.6);
    float dropMask = smallDrippingRain.dropMask;
    float droppletsMask = smallDrippingRain.droppletsMask;
    float trailMask = smallDrippingRain.trailMask;
    vec2 dropUvMasked = smallDrippingRain.drop * dropMask;
    vec2 droppletsUvMasked = smallDrippingRain.dropplets * droppletsMask;

    // 2. Generate medium size glass rain.
    GlassRain medDrippingRain = generateGlassRain(
          uv,
          screenAspectRatio,
          time * 0.80,
          /* Grid size = */ vec2(6., 0.945) * gridScale,
          intensity * 0.6);

    // 3. Combine those two glass rains.
    dropMask = max(medDrippingRain.dropMask, dropMask);
    droppletsMask = max(medDrippingRain.droppletsMask, droppletsMask);
    trailMask = max(medDrippingRain.trailMask, trailMask);
    dropUvMasked = mix(dropUvMasked,
        medDrippingRain.drop * medDrippingRain.dropMask, medDrippingRain.dropMask);
    droppletsUvMasked = mix(droppletsUvMasked,
        medDrippingRain.dropplets * medDrippingRain.droppletsMask, medDrippingRain.droppletsMask);

    // 4. Add static rain droplets on the glass surface. (They stay in place and dissapate.)
    vec2 gridSize = vec2(12., 12.) * gridScale;
    // Aspect ratio impacts visible cells.
    gridSize.y /= screenAspectRatio;
    vec3 staticRain = generateStaticGlassRain(uv, time, intensity, gridSize);
    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;
    vec2 s = screenSize;
    // Ensure the diffracted image in drops is not inverted.
    s.y *= -1;

    vec4 color = texture.eval(fragCoord);
    vec3 sampledColor = texture.eval(fragCoord + uvDiffractionOffsets * s).rgb;
    color.rgb = mix(color.rgb, sampledColor, max(dropMask, droppletsMask));

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

    // 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);

    // 8. Add shadows to the drops.
    color.rgb = mix(
        color.rgb,
        contactShadowColor,
        dropShadowIntensity *
            smoothstep(0.055, 0.1, max(length(dropUvMasked * 1.7),
                length(droppletsUvMasked * 1.9))));

    return color;
}
 No newline at end of file
+0 −2
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ Rain generateRain(
    in float rainIntensity
) {
    /* Grid. */
    // Number of rows and columns (each one is a cell, a drop).
    float cellAspectRatio = rainGridSize.x / rainGridSize.y;
    // Aspect ratio impacts visible cells.
    uv.y /= screenAspectRatio;
    // scale the UV to allocate number of rows and columns.
+83 −6
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ uniform mat3 transformMatrixWeather;
#include "shaders/rain_shower.agsl"
#include "shaders/rain_constants.agsl"
#include "shaders/rain_splash.agsl"
#include "shaders/glass_rain.agsl"

// Controls how visible the rain drops are.
const float rainVisibility = 0.4;
@@ -79,6 +80,7 @@ vec3 drawSplashes(vec2 uv, vec2 fragCoord, vec3 color) {
}

vec4 main(float2 fragCoord) {
    // 1. Generate rain shower.
    // Apply transform matrix to fragCoord
    float2 uvTexture = transformPoint(transformMatrixBitmap, fragCoord);
    // Calculate uv for snow based on transformed coordinates
@@ -96,7 +98,7 @@ vec4 main(float2 fragCoord) {
    float variation = wiggle(time - uv.y * 1.1, 0.10);
    vec2 uvRot = rotateAroundPoint(uv, vec2(0.5, -1.42), variation * PI / 9.);

    // 1. Generate a layer of rain behind the subject.
    // 1.1. Generate a layer of rain behind the subject.
    Rain rain = generateRain(
          uvRot,
          screenAspectRatio,
@@ -106,7 +108,7 @@ vec4 main(float2 fragCoord) {

    color.rgb = mix(color.rgb, highlightColor, rainVisibility * rain.dropMask);

    // 2. Generate mid layer of rain behind the subject.
    // 1.2. Generate mid layer of rain behind the subject.
    rain = generateRain(
          uvRot,
          screenAspectRatio,
@@ -114,16 +116,16 @@ vec4 main(float2 fragCoord) {
          /* Grid size = */ vec2(30.0, 4.0) * gridScale,
          intensity);

    // 3. Blend those layers.
    // 1.3. Blend those layers.
    color.rgb = mix(color.rgb, highlightColor, rainVisibility * rain.dropMask);

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

    // 5. Draw splashes
    // (1.5. Draw splashes)
    color.rgb = drawSplashes(uv, fragCoord, color.rgb);

    // 6. Generate a layer of rain in front of the subject (bigger and faster).
    // 1.6. Generate a layer of rain in front of the subject (bigger and faster).
    rain = generateRain(
          uvRot,
          screenAspectRatio,
@@ -134,5 +136,80 @@ vec4 main(float2 fragCoord) {
    // Closer rain drops are less visible.
    color.rgb = mix(color.rgb, highlightColor, 0.7 * rainVisibility * rain.dropMask);

    // 2. Generate glass rain layer.
    // 2.0. Calculate UV and add a bit of noise so that the droplets are not perfect circles.
    float2 glassUv = vec2(valueNoise(fragCoord) * 0.015 - 0.0025) + fragCoord / screenSize;

    // 2.1. Generate small glass rain.
    GlassRain smallDrippingRain = generateGlassRain(
         glassUv,
         screenAspectRatio,
         time * 0.7,
         /* Grid size = */ vec2(5.0, 1.6) * gridScale,
         intensity * 0.6);
    float dropMask = smallDrippingRain.dropMask;
    float droppletsMask = smallDrippingRain.droppletsMask;
    float trailMask = smallDrippingRain.trailMask;
    vec2 dropUvMasked = smallDrippingRain.drop * dropMask;
    vec2 droppletsUvMasked = smallDrippingRain.dropplets * droppletsMask;

    // 2.2. Generate medium size glass rain.
    GlassRain medDrippingRain = generateGlassRain(
          glassUv,
          screenAspectRatio,
          time * 0.80,
          /* Grid size = */ vec2(6., 0.945) * gridScale,
          intensity * 0.6);

    // 2.3. Combine those two glass rains.
    dropMask = max(medDrippingRain.dropMask, dropMask);
    droppletsMask = max(medDrippingRain.droppletsMask, droppletsMask);
    trailMask = max(medDrippingRain.trailMask, trailMask);
    dropUvMasked = mix(dropUvMasked,
        medDrippingRain.drop * medDrippingRain.dropMask, medDrippingRain.dropMask);
    droppletsUvMasked = mix(droppletsUvMasked,
        medDrippingRain.dropplets * medDrippingRain.droppletsMask, medDrippingRain.droppletsMask);

    // 2.4. Add static rain droplets on the glass surface. (They stay in place and dissapate.)
    vec2 gridSize = vec2(12., 12.) * gridScale;
    // Aspect ratio impacts visible cells.
    gridSize.y /= screenAspectRatio;
    vec3 staticRain = generateStaticGlassRain(glassUv, time, intensity, gridSize);
    dropMask = max(dropMask, staticRain.z);
    dropUvMasked = mix(dropUvMasked, staticRain.xy * staticRain.z, staticRain.z);

    // 2.5. Distort uv for the rain drops and dropplets.
    float distortionDrop = -0.1;
    vec2 uvDiffractionOffsets =
        distortionDrop * dropUvMasked;
     vec2  s = screenSize;
    // Ensure the diffracted image in drops is not inverted.
    s.y *= -1;

     vec3 sampledColor = background.eval(uvTexture + uvDiffractionOffsets * s).rgb;
    sampledColor = imageRangeConversion(sampledColor, 0.84, 0.02, noise, intensity);
    color.rgb = mix(color.rgb, sampledColor, max(dropMask, droppletsMask));

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

    // 2.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);

    // 2.8. Add shadows to the drops.
    color.rgb = mix(
        color.rgb,
        contactShadowColor,
        dropShadowIntensity *
            smoothstep(0.055, 0.1, max(length(dropUvMasked * 1.7),
                length(droppletsUvMasked * 1.9))));

    return color;
}
+3 −31
Original line number Diff line number Diff line
@@ -58,8 +58,8 @@ Snow generateSnow(

    /* Grid. */
    // Increase the last number to make each layer more separate from the previous one.
    float depth = 0.65 + layerIndex * 0.37;
    float speedAdj = 1. + layerIndex * 0.15;
    float depth = 0.65 + layerIndex * 0.555;
    float speedAdj = 1. + layerIndex * 0.225;
    float layerR = idGenerator(layerIndex);
    snowGridSize *= depth;
    time += layerR * 58.3;
@@ -116,37 +116,9 @@ Snow generateSnow(
        farLayerFadeOut;

    /* Cell snow flake. */
    // Horizontal movement: Wiggle (Adjust the wiggle speed based on the distance).
    float wiggleSpeed = map(
        normalizedLayerIndex,
        0.2,
        0.7,
        closestSnowLayerWiggleSpeed,
        farthestSnowLayerWiggleSpeed);
    // Adjust wiggle based on layer number (0 = closer to screen => we want less movement).
    float wiggleAmp = 0.6 + 0.4 * smoothstep(0.5, 2.5, layerIndex);
    // Define the start based on the cell id.
    float horizontalStartAmp = 0.5;
    // Add the wiggle (equation decided by testing in Grapher).
    float horizontalWiggle = wiggle(
        // Current uv position.
        uv.y
        // Adjustment so the shape is not skewed.
        - cellUv.y / snowGridSize.y
        // variation based on cell ID.
        + cellId * 2.1,
        wiggleSpeed * speedAdj);

    // Add the start and wiggle and make that when we are closer to the edge, we don't wiggle much
    // (so the drop doesn't go outside it's cell).
    horizontalWiggle = horizontalStartAmp * wiggleAmp * horizontalWiggle;

    // Calculate main cell drop.
    float snowFlakePosUncorrected = (cellUv.x - horizontalWiggle);

    // Calculate snow flake.
    vec2 snowFlakeShape = vec2(0.28, 0.26);
    vec2 snowFlakePos = vec2(snowFlakePosUncorrected, cellUv.y * cellAspectRatio);
    vec2 snowFlakePos = vec2(cellUv.x, cellUv.y * cellAspectRatio);
    snowFlakePos -= vec2(
            0.,
            (uv.y - 0.5 / screenAspectRatio)  - cellUv.y / snowGridSize.y
+1 −3
Original line number Diff line number Diff line
@@ -37,10 +37,8 @@ vec4 main(float2 fragCoord) {
    float dY = (aN - aS) * 0.5;
    dY = max(dY, 0.0);

    float accumulatedSnow = smoothstep(0.1, 1.8, dY * 5.0);
    vec4 color = vec4(0., 0., 0., 1.);
    color.r = accumulatedSnow;
    color.r = dY * 10.0;
    color.g = random(uv);
    color.b = variation;
    return color;
}
Loading