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

Commit c8f425e1 authored by Michel Comin Escude's avatar Michel Comin Escude
Browse files

Fix several issues in rain effect

Some refactors introduced errors in the rendering of the rain.
Some of the issues are:
- Weather intensity was scaled globally by 0.6 for glass rain shader,
  but it had to only be scaled in selected places
- Time was scaled globally by 0.7 for glass rain shader,
  but it had to only be scaled in selected places
- UVs were rotated for both falling rain and rain splashes, which caused
  the rain splashes to not be displayed properly.
- Legacy error: splashes where displaced by `cellUv += 0.1;` but instead,
  only y component had to be affected (adjusted it to 0.15 as well)
The original CLs that introduced the errors are in ag/26275152,
ag/26387876 and ag/26399159

Bug: 352822756
Test: visual
Flag: EXEMPT MP apk not in build yet
Change-Id: Ieb578d112003373e29e2415aaf6a34a4be9743eb
parent acfcd1d7
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -26,18 +26,16 @@ uniform half intensity;
#include "shaders/rain_constants.agsl"

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

    float2 uv = fragCoord / screenSize;
    // 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,
         time * 0.7,
         /* Grid size = */ vec2(4.0, 2.0),
         intensity);
         intensity * 0.6);
    float dropMask = smallDrippingRain.dropMask;
    float droppletsMask = smallDrippingRain.droppletsMask;
    float trailMask = smallDrippingRain.trailMask;
@@ -48,9 +46,9 @@ vec4 main(float2 fragCoord) {
    GlassRain medDrippingRain = generateGlassRain(
          uv,
          screenAspectRatio,
          time * 1.267,
          time * 0.8869,
          /* Grid size = */ vec2(3.5, 1.5),
          intensity);
          intensity * 0.6);

    // 3. Combine those two glass rains.
    dropMask = max(medDrippingRain.dropMask, dropMask);
+4 −4
Original line number Diff line number Diff line
@@ -91,11 +91,11 @@ vec4 main(float2 fragCoord) {

    // Add rotation for the rain (as a default sin(time * 0.05) can be used).
    float variation = wiggle(time - uv.y * 1.1, 0.10);
    uv = rotateAroundPoint(uv, vec2(0.5, -1.42), variation * PI / 9.);
    vec2 uvRot = rotateAroundPoint(uv, vec2(0.5, -1.42), variation * PI / 9.);

    // 1. Generate a layer of rain behind the subject.
    Rain rain = generateRain(
          uv,
          uvRot,
          screenAspectRatio,
          time * 18.,
          /* Grid size = */ vec2(20.0, 2.0),
@@ -105,7 +105,7 @@ vec4 main(float2 fragCoord) {

    // 2. Generate mid layer of rain behind the subject.
    rain = generateRain(
          uv,
          uvRot,
          screenAspectRatio,
          time * 21.4,
          /* Grid size = */ vec2(30.0, 4.0),
@@ -122,7 +122,7 @@ vec4 main(float2 fragCoord) {

    // 6. Generate a layer of rain in front of the subject (bigger and faster).
    rain = generateRain(
          uv,
          uvRot,
          screenAspectRatio,
          time * 27.,
          /* Grid size = */ vec2(8.0, 3.0),
+3 −2
Original line number Diff line number Diff line
@@ -21,8 +21,9 @@
 */
float drawSplash(vec2 cellUv, float cellTime) {
    /** 0. Adjust UV and time. */
    cellUv = cellUv * 0.5;
    cellUv += 0.1;
    cellUv *= 0.5;
    // Moves drop a little bit down on the its grid cell.
    cellUv.y += 0.15;
    float t = 0.408 + cellTime * 4.;

    /** 1. Start of drawing a splash */
+2 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ class RainEffect(
        elapsedTime += deltaMillis * MILLIS_TO_SECONDS

        rainConfig.rainShowerShader.setFloatUniform("time", elapsedTime)
        rainConfig.glassRainShader.setFloatUniform("time", elapsedTime * 0.7f)
        rainConfig.glassRainShader.setFloatUniform("time", elapsedTime)

        rainConfig.glassRainShader.setInputShader("texture", rainConfig.rainShowerShader)
        rainConfig.colorGradingShader.setInputShader("texture", rainConfig.glassRainShader)
@@ -85,7 +85,7 @@ class RainEffect(

    override fun setIntensity(intensity: Float) {
        rainConfig.rainShowerShader.setFloatUniform("intensity", intensity)
        rainConfig.glassRainShader.setFloatUniform("intensity", intensity * 0.6f)
        rainConfig.glassRainShader.setFloatUniform("intensity", intensity)
        rainConfig.colorGradingShader.setFloatUniform(
            "intensity",
            rainConfig.colorGradingIntensity * intensity