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

Commit 4d369e3d authored by Michel Comin Escude's avatar Michel Comin Escude
Browse files

Update color grading and image protection

Updates the color grading for each effect. In addition,
add image protection so the effects are always visible
even when the background image is white

Flag: EXEMPT only change in Magic Portrait
Bug: 375632936
Bug: 375632846
Test: visual
Change-Id: I0170556635f3cd031914e50920c7b920ec87530c
parent a15c787b
Loading
Loading
Loading
Loading
+28 −16
Original line number Original line Diff line number Diff line
@@ -33,7 +33,8 @@ uniform mat3 transformMatrixWeather;
#include "shaders/utils.agsl"
#include "shaders/utils.agsl"
#include "shaders/simplex2d.agsl"
#include "shaders/simplex2d.agsl"


const vec3 fogColor = vec3(0.20);
const vec3 fogScrimColor = vec3(0.20);
const vec3 fogColor = vec3(1.0);


vec4 main(float2 fragCoord) {
vec4 main(float2 fragCoord) {
    vec2 timeForeground = vec2(time.x, time.y);
    vec2 timeForeground = vec2(time.x, time.y);
@@ -52,14 +53,19 @@ vec4 main(float2 fragCoord) {
    float2 bgdCoord = transformPoint(transformMatrixBgd, fragCoord);
    float2 bgdCoord = transformPoint(transformMatrixBgd, fragCoord);
    float2 uv = transformPoint(transformMatrixWeather, fragCoord) / screenSize;
    float2 uv = transformPoint(transformMatrixWeather, fragCoord) / screenSize;
    uv.y /= screenAspectRatio;
    uv.y /= screenAspectRatio;
    // Load foreground and blend it with constant solid fog color.
    vec4 fgd = foreground.eval(fgdCoord);
    fgd.rgb = mix(fgd.rgb, fogColor, 0.15 * intensity * fgd.a);


    // Load background and blend it with constant solid fog color.
    // Load background and foreground.
    vec4 fgd = foreground.eval(fgdCoord);
    vec4 bgd = background.eval(bgdCoord);
    vec4 bgd = background.eval(bgdCoord);
    bgd.rgb = mix(bgd.rgb, fogColor, 0.32 * intensity * bgd.a);


    // Adjusts contrast and brightness.
    float noise = 0.025 * triangleNoise(fragCoord.xy + vec2(12.31, 1024.1241));
    bgd.rgb = imageRangeConversion(bgd.rgb, 0.8, 0.02, noise, intensity);
    fgd.rgb = imageRangeConversion(fgd.rgb, 0.8, 0.02, noise, intensity);

    // Blend them with constant solid fog color.
    bgd.rgb = mix(bgd.rgb, fogScrimColor, 0.14 * intensity * bgd.a);
    fgd.rgb = mix(fgd.rgb, fogScrimColor, 0.12 * intensity * fgd.a);
    /* Add first layer: background. */
    /* Add first layer: background. */
    // set background color as the starting layer.
    // set background color as the starting layer.
    vec4 color = bgd;
    vec4 color = bgd;
@@ -115,11 +121,12 @@ vec4 main(float2 fragCoord) {
            bgFogFarCombined *
            bgFogFarCombined *
            smoothstep(-0.1, 0.05, uv.y + fogHeightVariation) *
            smoothstep(-0.1, 0.05, uv.y + fogHeightVariation) *
            (1. - smoothstep(0.15, 0.35, uv.y + fogHeightVariation));
            (1. - smoothstep(0.15, 0.35, uv.y + fogHeightVariation));
        bgdFogLayer1 *= 0.45 * (1. - bgdDither);
        bgdFogLayer1 *= 1.1;
        bgdFogLayer1 += 0.55 * bgdDither;
        bgdFogLayer1 = clamp(bgdFogLayer1, 0., 1.);
        bgdFogLayer1 = clamp(bgdFogLayer1, 0., 1.);
        // Blend with background.
        // Blend with background.
        color.rgb = screenBlend(color.rgb, bgdFogLayer1 * intensity);
        color.rgb =
    //    color.rgb = vec3(bgdFogLayer1 * intensity);
            normalBlendNotPremultiplied(color.rgb, fogColor * 0.8, bgdFogLayer1 * intensity);
    }
    }


    if (uv.y > 0.23 && uv.y < 0.87) {
    if (uv.y > 0.23 && uv.y < 0.87) {
@@ -131,10 +138,12 @@ vec4 main(float2 fragCoord) {
            bgFogloseCombined *
            bgFogloseCombined *
            smoothstep(0.25, 0.55, uv.y + fogHeightVariation) *
            smoothstep(0.25, 0.55, uv.y + fogHeightVariation) *
            (1. - smoothstep(0.7, 0.85, uv.y + fogHeightVariation));
            (1. - smoothstep(0.7, 0.85, uv.y + fogHeightVariation));
        bgdFogLayer2 *= 0.6 * (1.- bgdDither);
        bgdFogLayer2 *= 1.2;
        bgdFogLayer2 += 0.6 * bgdDither;
        bgdFogLayer2 = clamp(bgdFogLayer2, 0., 1.);
        bgdFogLayer2 = clamp(bgdFogLayer2, 0., 1.);
        // Blend with background.
        // Blend with background.
        color.rgb = screenBlend(color.rgb, bgdFogLayer2 * intensity);
        color.rgb =
            normalBlendNotPremultiplied(color.rgb, fogColor * 0.85, bgdFogLayer2 * intensity);
    }
    }


    /* Add third layer: foreground. */
    /* Add third layer: foreground. */
@@ -151,9 +160,11 @@ vec4 main(float2 fragCoord) {
                    1.,
                    1.,
                    0.5 * intensity * smoothstep(0.72, 0.92, uv.y + fogHeightVariation)) *
                    0.5 * intensity * smoothstep(0.72, 0.92, uv.y + fogHeightVariation)) *
                smoothstep(0.42, 0.82, uv.y + fogHeightVariation);
                smoothstep(0.42, 0.82, uv.y + fogHeightVariation);
        fgdFogLayer1 *= 0.65 * (1. - fgdDither);
        fgdFogLayer1 *= 1.3;
        fgdFogLayer1 += 0.6 * fgdDither;
        fgdFogLayer1 = clamp(fgdFogLayer1, 0., 1.);
        fgdFogLayer1 = clamp(fgdFogLayer1, 0., 1.);
        color.rgb = screenBlend(color.rgb, fgdFogLayer1 * intensity);
        color.rgb =
            normalBlendNotPremultiplied(color.rgb, fogColor * 0.9, fgdFogLayer1 * intensity);
    }
    }
    if (uv.y > 0.25) {
    if (uv.y > 0.25) {
        // Foreground fog, layer 2.
        // Foreground fog, layer 2.
@@ -162,11 +173,12 @@ vec4 main(float2 fragCoord) {
                mix(
                mix(
                    fgdFogClose.g,
                    fgdFogClose.g,
                    1.,
                    1.,
                    0.65 * intensity * smoothstep(0.85, 0.98, uv.y + fogHeightVariation)) *
                    0.65 * intensity * smoothstep(0.85, 1.3, uv.y + fogHeightVariation)) *
                smoothstep(0.30, 0.90, uv.y + uv.x * 0.09);
                smoothstep(0.30, 0.90, uv.y + uv.x * 0.09);
        fgdFogLayer2 *= 0.8 * (1. - fgdDither);
        fgdFogLayer2 *= 1.4;
        fgdFogLayer2 += 0.6 * fgdDither;
        fgdFogLayer2 = clamp(fgdFogLayer2, 0., 1.);
        fgdFogLayer2 = clamp(fgdFogLayer2, 0., 1.);
        color.rgb = screenBlend(color.rgb, fgdFogLayer2 * intensity);
        color.rgb = normalBlendNotPremultiplied(color.rgb, fogColor, fgdFogLayer2 * intensity);
    }
    }
    return color;
    return color;
}
}
 No newline at end of file
+2 −2
Original line number Original line Diff line number Diff line
@@ -16,9 +16,9 @@


 /* Color and intensity constants. */
 /* Color and intensity constants. */
 // The color of the highlight of each drop.
 // The color of the highlight of each drop.
 const vec3 highlightColor = vec3(1.); // white
 const vec3 highlightColor = vec3(0.9, 1., 1.); // white
 // The color of the contact ambient occlusion shadow.
 // The color of the contact ambient occlusion shadow.
 const vec3 contactShadowColor = vec3(0.); // black
 const vec3 contactShadowColor = vec3(0.2); // black
 // The tint color of the drop.
 // The tint color of the drop.
 const vec3 dropTint = vec3(1.); // white
 const vec3 dropTint = vec3(1.); // white


+5 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,11 @@ vec4 main(float2 fragCoord) {
    vec4 colorForeground = foreground.eval(uvTextureFgd);
    vec4 colorForeground = foreground.eval(uvTextureFgd);
    vec4 color = background.eval(uvTextureBgd);
    vec4 color = background.eval(uvTextureBgd);


    // Adjusts contrast and brightness.
    float noise = 0.025 * triangleNoise(fragCoord.xy + vec2(12.31, 1024.1241));
    color.rgb = imageRangeConversion(color.rgb, 0.84, 0.02, noise, intensity);
    colorForeground.rgb = imageRangeConversion(colorForeground.rgb, 0.84, 0.02, noise, intensity);

    // Add rotation for the rain (as a default sin(time * 0.05) can be used).
    // 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);
    float variation = wiggle(time - uv.y * 1.1, 0.10);
    vec2 uvRot = rotateAroundPoint(uv, vec2(0.5, -1.42), variation * PI / 9.);
    vec2 uvRot = rotateAroundPoint(uv, vec2(0.5, -1.42), variation * PI / 9.);
+8 −0
Original line number Original line Diff line number Diff line
@@ -61,6 +61,14 @@ vec4 main(float2 fragCoord) {


    vec4 colorForeground = foreground.eval(adjustedUvForeground);
    vec4 colorForeground = foreground.eval(adjustedUvForeground);
    vec4 colorBackground = background.eval(adjustedUvBackground);
    vec4 colorBackground = background.eval(adjustedUvBackground);

     // Adjusts contrast and brightness.
    float noiseT = triangleNoise(fragCoord.xy + vec2(12.31, 1024.1241));
    colorBackground.rgb =
        imageRangeConversion(colorBackground.rgb, 0.88, 0.02, noiseT * 0.025, intensity);
    colorForeground.rgb =
        imageRangeConversion(colorForeground.rgb, 0.88, 0.02, noiseT * 0.025, intensity);

    // 1. Draw background.
    // 1. Draw background.
    vec4 color = colorBackground;
    vec4 color = colorBackground;


+2 −5
Original line number Original line Diff line number Diff line
@@ -117,11 +117,8 @@ vec4 main(float2 fragCoord) {
    brightnessSunray *= brightnessSunray;
    brightnessSunray *= brightnessSunray;


    // Adjusts contrast and brightness.
    // Adjusts contrast and brightness.
    float compression = 0.88;
    float noise = 0.025 * triangleNoise(fragCoord.xy + vec2(12.31, 1024.1241));
    float brightnessIncriease = 0.02;
    color.rgb = imageRangeConversion(color.rgb, 0.88, 0.02, noise, intensity);
    float noise = triangleNoise(fragCoord.xy + vec2(12.31, 1024.1241));
    color.rgb *= mix(1., compression + noise * 0.025, intensity);
    color.rgb += brightnessIncriease * intensity;


    // Adjust color grading for shadows and highlights.
    // Adjust color grading for shadows and highlights.
    float lum = relativeLuminance(color.rgb);
    float lum = relativeLuminance(color.rgb);
Loading