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

Commit 24514da1 authored by Yein Jo's avatar Yein Jo
Browse files

Add noise to the rain droplets on the glass surface.

The reference CL has the noisesf which has a value range of [0,3], made
it [0,1] for reusability. Then modified the multiplier to match the
result.
Also shuffled the util functions to group them based on their
functionality.

Bug: 325090421
Test: Manual
Flag: NA
Change-Id: Id7ebe43052106e65bb95600600a6545fee89d144
parent abda8a8c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ 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;

    // 1. Generate small glass rain.
+45 −19
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 */

/** Noise */
highp float idGenerator(vec2 point) {
    vec2 p = fract(point * vec2(723.123, 236.209));
    p += dot(p, p + 17.1512);
@@ -24,6 +25,36 @@ highp float idGenerator(float value) {
    return idGenerator(vec2(value, 1.412));
}

// Noise range of [-1.0, 1.0[ with triangle distribution.
float triangleNoise(vec2 n) {
    n  = fract(n * vec2(5.3987, 5.4421));
    n += dot(n.yx, n.xy + vec2(21.5351, 14.3137));
    float xy = n.x * n.y;
    // compute in [0..2[ and remap to [-1.0..1.0[
    return fract(xy * 95.4307) + fract(xy * 75.04961) - 1.0;
}

// Noise range of [0, 1].
float valueNoise(vec2 fragCoord) {
    float scale = 0.021;
    float2 i = floor(fragCoord * scale);
    vec2 f = fract(fragCoord * scale);

    float a = idGenerator(i);
    float b = idGenerator(i + vec2(1.0, 0.0));
    float c = idGenerator(i + vec2(0.0, 1.0));
    float d = idGenerator(i + vec2(1.0, 1.0));

    vec2 u = smoothstep(0. ,1. , f);

    float noise = mix(a, b, u.x) +
                  (c - a) * u.y * (1.0 - u.x) +
                  (d - b) * u.x * u.y;
    // Remap the range back to [0,3].
    return noise / 3.;
}

/** Transfrom */
mat2 rotationMat(float angleRad) {
  float c = cos(angleRad);
  float s = sin(angleRad);
@@ -35,29 +66,16 @@ mat2 rotationMat(float angleRad) {
  );
}

float sdfCircle(vec2 p, float r) {
    return length(p) - r;
}

vec2 rotateAroundPoint(vec2 point, vec2 centerPoint, float angleRad) {
    return (point - centerPoint) * rotationMat(angleRad) + centerPoint;
}

// function created on Grapher (equation decided by testing in Grapher).
float wiggle(float time, float wiggleSpeed) {
    return sin(wiggleSpeed * time + 0.5 * sin(wiggleSpeed * 5. * time))
        * sin(wiggleSpeed * time) - 0.5;
}

// Noise range of [-1.0, 1.0[ with triangle distribution.
float triangleNoise(vec2 n) {
    n  = fract(n * vec2(5.3987, 5.4421));
    n += dot(n.yx, n.xy + vec2(21.5351, 14.3137));
    float xy = n.x * n.y;
    // compute in [0..2[ and remap to [-1.0..1.0[
    return fract(xy * 95.4307) + fract(xy * 75.04961) - 1.0;
/** SDF */
float sdfCircle(vec2 p, float r) {
    return length(p) - r;
}

/** Blend */
/*
 * This is the normal blend mode in which the foreground is painted on top of the background based
 * on the foreground opacity.
@@ -76,8 +94,16 @@ vec3 normalBlendWithWhiteSrc(vec3 b, float o) {
    return b * (1. - o) + o;
}

/** Math Utils */
// function created on Grapher (equation decided by testing in Grapher).
float wiggle(float time, float wiggleSpeed) {
    return sin(wiggleSpeed * time + 0.5 * sin(wiggleSpeed * 5. * time))
           * sin(wiggleSpeed * time) - 0.5;
}

float map(float value, float inMin, float inMax, float outMin, float outMax) {
    float v = clamp(value, inMin, inMax);
    float p = (v - inMin) / (inMax - inMin);
    return p * (outMax - outMin) + outMin;
}