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

Commit 4803d31a authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Fix weather effects being scaled differently in different images, and add parallax to sun effects

The reason is that the scale to fit image into screen size has been
wrongly applied to weather layers. And to fix it, we extract only the
translate part from parallax matrix to apply to weather layers. And for
foreground and background, we still use the parallax matrix.

Bug: 375272898
Bug: 375214506
Test: manually test density and thickness of raindrop across diferent
test images, and test the parallax of sun effects by swiping left and
right in homescreen while sun effects is playing
Flag: EXEMPT only change in Magic Portrait

Change-Id: I2e697dee70529291f949517172e764bb3ee090a4
parent 0f1a3800
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ uniform half pixelDensity;
uniform half intensity;
uniform mat3 transformMatrixFgd;
uniform mat3 transformMatrixBgd;
uniform mat3 transformMatrixWeather;

#include "shaders/constants.agsl"
#include "shaders/utils.agsl"
@@ -49,7 +50,7 @@ vec4 main(float2 fragCoord) {

    float2 fgdCoord = transformPoint(transformMatrixFgd, fragCoord);
    float2 bgdCoord = transformPoint(transformMatrixBgd, fragCoord);
    float2 uv = bgdCoord / screenSize;
    float2 uv = transformPoint(transformMatrixWeather, fragCoord) / screenSize;
    uv.y /= screenAspectRatio;
    // Load foreground and blend it with constant solid fog color.
    vec4 fgd = foreground.eval(fgdCoord);
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ uniform float2 screenSize;
uniform half intensity;
uniform mat3 transformMatrixFgd;
uniform mat3 transformMatrixBgd;
uniform mat3 transformMatrixWeather;

#include "shaders/constants.agsl"
#include "shaders/utils.agsl"
@@ -83,7 +84,7 @@ vec4 main(float2 fragCoord) {
    float2 uvTextureFgd = transformPoint(transformMatrixFgd, fragCoord);
    float2 uvTextureBgd = transformPoint(transformMatrixBgd, fragCoord);
    // Calculate uv for snow based on transformed coordinates
    float2 uv = uvTextureFgd / screenSize;
    float2 uv = transformPoint(transformMatrixWeather, fragCoord) / screenSize;

    vec4 colorForeground = foreground.eval(uvTextureFgd);
    vec4 color = background.eval(uvTextureBgd);
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ uniform float screenAspectRatio;
uniform float2 screenSize;
uniform mat3 transformMatrixFgd;
uniform mat3 transformMatrixBgd;
uniform mat3 transformMatrixWeather;

#include "shaders/constants.agsl"
#include "shaders/utils.agsl"
@@ -55,7 +56,7 @@ vec4 main(float2 fragCoord) {
    float2 adjustedUvBackground = transformPoint(transformMatrixBgd, fragCoord);

    // Calculate uv for snow based on transformed coordinates
    float2 uv = adjustedUvBackground / screenSize;
    float2 uv = transformPoint(transformMatrixWeather, fragCoord) / screenSize;
    float2 uvAdjusted = vec2(uv.x, uv.y / screenAspectRatio);

    vec4 colorForeground = foreground.eval(adjustedUvForeground);
+2 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ uniform float time;
uniform float intensity;
uniform mat3 transformMatrixFgd;
uniform mat3 transformMatrixBgd;
uniform mat3 transformMatrixWeather;


#include "shaders/constants.agsl"
@@ -98,8 +99,7 @@ vec4 main(float2 fragCoord) {
    float2 adjustedUvForeground = transformPoint(transformMatrixFgd, fragCoord);
    float2 adjustedUvBackground = transformPoint(transformMatrixBgd, fragCoord);


    float2 uv = fragCoord / screenSize;
    float2 uv = transformPoint(transformMatrixWeather, fragCoord) / screenSize;
    uv -= vec2(0.5, 0.5);
    uv.y /= screenAspectRatio;
    vec2 sunVariation = vec2(0.1 * sin(time * 0.3), 0.14 * cos(time * 0.5));
+3 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.google.android.wallpaper.weathereffects.graphics.WeatherEffect
import com.google.android.wallpaper.weathereffects.graphics.WeatherEffect.Companion.DEFAULT_INTENSITY
import com.google.android.wallpaper.weathereffects.graphics.utils.GraphicsUtils
import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.centerCropMatrix
import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.extractTranslationMatrix
import com.google.android.wallpaper.weathereffects.graphics.utils.MatrixUtils.postprocessParallaxMatrix
import com.google.android.wallpaper.weathereffects.graphics.utils.TimeUtils
import kotlin.math.sin
@@ -143,8 +144,10 @@ class FogEffect(
                )
        }
        val postprocessedMatrix = postprocessParallaxMatrix(matrix!!)
        val weatherMatrix = extractTranslationMatrix(postprocessedMatrix)
        fogConfig.shader.setFloatUniform("transformMatrixFgd", postprocessedMatrix)
        fogConfig.shader.setFloatUniform("transformMatrixBgd", postprocessedMatrix)
        fogConfig.shader.setFloatUniform("transformMatrixWeather", weatherMatrix)

        fogConfig.shader.setFloatUniform("screenSize", surfaceSize.width, surfaceSize.height)
        fogConfig.shader.setFloatUniform(
Loading