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

Commit 9ba974d8 authored by Michel Comin Escude's avatar Michel Comin Escude
Browse files

Adjust rain to work on tablet and foldable

Bug: 332775703
Test: visual
Flag: EXEMPT MP apk not in build yet
Change-Id: I896e8754f8691246fd6b2056f211082454860307
parent 856bfb2d
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ GlassRain generateGlassRain(
    // Number of rows and columns (each one is a cell, a drop).
    float cellAspectRatio = rainGridSize.x / rainGridSize.y;
    // Aspect ratio impacts visible cells.
    rainGridSize.y /= screenAspectRatio;
    uv.y /= screenAspectRatio;
    // scale the UV to allocate number of rows and columns.
    vec2 gridUv = uv * rainGridSize;
    // Invert y (otherwise it goes from 0=top to 1=bottom).
@@ -149,10 +149,7 @@ GlassRain generateGlassRain(
/**
 * Generate rain drops that stay in place on the glass surface.
 */
vec3 generateStaticGlassRain(vec2 uv, half screenAspectRatio, half time, half intensity) {
    vec2 gridSize = vec2(15., 15.);
    // Aspect ratio impacts visible cells.
    gridSize.y /= screenAspectRatio;
vec3 generateStaticGlassRain(vec2 uv, half time, half intensity, vec2 gridSize) {
    // 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).
+7 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
uniform shader texture;
uniform float time;
uniform float screenAspectRatio;
uniform float gridScale;
uniform float2 screenSize;
uniform half intensity;

@@ -34,7 +35,7 @@ vec4 main(float2 fragCoord) {
         uv,
         screenAspectRatio,
         time * 0.7,
         /* Grid size = */ vec2(4.0, 2.0),
         /* Grid size = */ vec2(4.0, 2.0) * gridScale,
         intensity * 0.6);
    float dropMask = smallDrippingRain.dropMask;
    float droppletsMask = smallDrippingRain.droppletsMask;
@@ -47,7 +48,7 @@ vec4 main(float2 fragCoord) {
          uv,
          screenAspectRatio,
          time * 0.8869,
          /* Grid size = */ vec2(3.5, 1.5),
          /* Grid size = */ vec2(3.5, 1.5) * gridScale,
          intensity * 0.6);

    // 3. Combine those two glass rains.
@@ -60,7 +61,10 @@ vec4 main(float2 fragCoord) {
        medDrippingRain.dropplets * medDrippingRain.droppletsMask, medDrippingRain.droppletsMask);

    // 4. Add static rain droplets on the glass surface. (They stay in place and dissapate.)
    vec3 staticRain = generateStaticGlassRain(uv, screenAspectRatio, time, intensity);
    vec2 gridSize = vec2(15., 15.) * 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);

+12 −5
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ Rain generateRain(
    // Number of rows and columns (each one is a cell, a drop).
    float cellAspectRatio = rainGridSize.x / rainGridSize.y;
    // Aspect ratio impacts visible cells.
    rainGridSize.y /= screenAspectRatio;
    uv.y /= screenAspectRatio;
    // scale the UV to allocate number of rows and columns.
    vec2 gridUv = uv * rainGridSize;
    // Invert y (otherwise it goes from 0=top to 1=bottom).
@@ -63,20 +63,27 @@ Rain generateRain(
    vec2 cellUv = fract(gridUv) - 0.5;

    float intensity = idGenerator(floor(vec2(cellId * 8.16, 27.2)));
    if (intensity < 1. - rainIntensity) {
    if (rainIntensity < intensity) {
        return Rain(0.0, cellUv);
    }

    /* Cell-id-based variations. */
    // This factor is used to make the particle visibile right after it is visible
    // (based on cellIntensity). 0 = snow flake invisible, 1 = snow flake visible.
    float visivilityFactor = smoothstep(
        intensity,
        min(intensity + 0.18, 1.0),
        rainIntensity);

    /* Cell-id-based variations. */
    // Adjust time based on columnId.
    time += columnId * 7.1203;
    // Adjusts scale of each drop (higher is smaller).
    float scaleVariation = 1.0 - 0.3 * cellId;
    float opacityVariation = (1. - 0.9 * cellId);

    /* Cell drop. */
    // Define the start based on the cell id.
    float horizontalStart = 0.8 * (cellId - 0.5);
    float horizontalStart = 0.8 * (intensity - 0.5);

    // Calculate drop.
    vec2 dropPos = cellUv;
@@ -90,7 +97,7 @@ Rain generateRain(
        .80 + 3. * cellId,
        // Adjust the shape.
        1. - length(vec2(dropPos.x, (dropPos.y - dropPos.x * dropPos.x)))
    );
    ) * visivilityFactor;

    return Rain(dropMask, cellUv);
}
+5 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ uniform float2 uvOffsetBgd;
uniform float2 uvScaleBgd;
uniform float time;
uniform float screenAspectRatio;
uniform float gridScale;
uniform float2 screenSize;
uniform half intensity;

@@ -40,7 +41,7 @@ const float rainVisibility = 0.4;
 */
vec3 drawSplashes(vec2 uv, vec2 fragCoord, vec3 color) {
    /** 1. Make a grid */
    vec2 gridSize = vec2(15., 15.);
    vec2 gridSize = vec2(15., 15.) * gridScale;
    // Aspect ratio impacts visible cells.
    gridSize.y /= screenAspectRatio;
    // Scale the UV to allocate number of rows and columns.
@@ -98,7 +99,7 @@ vec4 main(float2 fragCoord) {
          uvRot,
          screenAspectRatio,
          time * 18.,
          /* Grid size = */ vec2(20.0, 2.0),
          /* Grid size = */ vec2(20.0, 2.0) * gridScale,
          intensity);

    color.rgb = mix(color.rgb, highlightColor, rainVisibility * rain.dropMask);
@@ -108,7 +109,7 @@ vec4 main(float2 fragCoord) {
          uvRot,
          screenAspectRatio,
          time * 21.4,
          /* Grid size = */ vec2(30.0, 4.0),
          /* Grid size = */ vec2(30.0, 4.0) * gridScale,
          intensity);

    // 3. Blend those layers.
@@ -125,7 +126,7 @@ vec4 main(float2 fragCoord) {
          uvRot,
          screenAspectRatio,
          time * 27.,
          /* Grid size = */ vec2(8.0, 3.0),
          /* Grid size = */ vec2(8.0, 3.0) * gridScale,
          intensity);

    // Closer rain drops are less visible.
+12 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ class RainEffect(
) : WeatherEffect {

    private val rainPaint = Paint().also { it.shader = rainConfig.colorGradingShader }

    // Set blur effect to reduce the outline noise. No need to set blur effect every time we
    // re-generate the outline buffer.
    private val outlineBuffer =
@@ -57,10 +58,14 @@ class RainEffect(
        updateTextureUniforms()
        adjustCropping(surfaceSize)
        prepareColorGrading()
        updateRainGridSize(surfaceSize)
        setIntensity(rainConfig.intensity)
    }

    override fun resize(newSurfaceSize: SizeF) = adjustCropping(newSurfaceSize)
    override fun resize(newSurfaceSize: SizeF) {
        adjustCropping(newSurfaceSize)
        updateRainGridSize(newSurfaceSize)
    }

    override fun update(deltaMillis: Long, frameTimeNanos: Long) {
        elapsedTime += TimeUtils.millisToSeconds(deltaMillis)
@@ -191,4 +196,10 @@ class RainEffect(
            )
        }
    }

    private fun updateRainGridSize(surfaceSize: SizeF) {
        val widthScreenScale = GraphicsUtils.computeDefaultGridSize(surfaceSize, rainConfig.pixelDensity)
        rainConfig.rainShowerShader.setFloatUniform("gridScale", widthScreenScale)
        rainConfig.glassRainShader.setFloatUniform("gridScale", widthScreenScale)
    }
}
Loading