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

Commit 3d84fbc5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add accumulated snow." into main

parents f6b03684 63d62f29
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ android_library {
    manifest: "AndroidManifest.xml",
    sdk_version: "system_current",
    // min_sdk version must be specified to not compile against platform apis.
    // Using RuntimeShader requires minimum of 33.
    min_sdk_version: "33",
    // Using HardwareBufferRenderer requires minimum of 34.
    min_sdk_version: "34",
    static_libs: [
        "androidx.slice_slice-core",
        "androidx.slice_slice-builders",
@@ -60,7 +60,7 @@ android_app {
    owner: "google",
    privileged: false,
    sdk_version: "system_current",
    min_sdk_version: "33",
    min_sdk_version: "34",
    static_libs: [
        "WeatherEffectsLib"
    ],
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ uniform half pixelDensity;

#include "shaders/constants.agsl"
#include "shaders/utils.agsl"
#include "shaders/simplex_flow_noise.agsl"
#include "shaders/simplex2d.agsl"

const int numOctaves = 2;

+34 −5
Original line number Diff line number Diff line
@@ -30,6 +30,17 @@ vec2 getVectorFromAngle(float theta) {
    return vec2(cos(theta), sin(theta));
}

// Returns kernel summation from the given simplex vertices (v0, v1, v2), and their corresponding
// gradients (g0, g1, g2).
float kernel_summation(vec2 v0, vec2 v1, vec2 v2, vec2 g0, vec2 g1, vec2 g2) {
   vec3 w = max(0.5 - vec3(dot(v0, v0), dot(v1, v1), dot(v2, v2)), 0.0);

    w = w*w*w*w;
    vec3 n = w * vec3(dot(v0, g0), dot(v1, g1), dot(v2, g2));

    return dot(n, vec3(32.0));
}

// 2D Simplex noise with dynamic gradient vectors. Return value [-1, 1].
//
// This method produces similar visuals to Simplex noise 3D, but at a lower computational cost.
@@ -70,11 +81,29 @@ float simplex2d_flow(vec2 p, float rot, float time) {
    g1 += getVectorFromAngle(rot * time * hash1d(i+walk));
    g2 += getVectorFromAngle(rot * time * hash1d(i+1.));

    // Kernel summation
    vec3 w = max(0.5 - vec3(dot(v0, v0), dot(v1, v1), dot(v2, v2)), 0.0);
    return kernel_summation(v0, v1, v2, g0, g1, g2);
}

    w = w*w*w*w;
    vec3 n = w * vec3(dot(v0, g0), dot(v1, g1), dot(v2, g2));
// 2D Simplex noise
float simplex2d(vec2 p) {
    // Skew the input coordinate and find the simplex index.
    vec2 i = floor(p + (p.x + p.y) * SKEW);
    // First vertex of the triangle.
    vec2 v0 = p - i + (i.x + i.y) * UNSKEW;

    return dot(n, vec3(32.0));
    // Find two other vertices.
    // Determines which triangle we should walk.
    // If y>x, m=0 upper triangle, x>y, m=1 lower triangle.
    float side = step(v0.y, v0.x);
    vec2 walk = vec2(side, 1.0 - side);

    vec2 v1 = v0 - walk + UNSKEW;
    vec2 v2 = v0 - 1.0 + 2.*UNSKEW;

    // Get random gradient vector.
    vec2 g0 = hash2d(i);
    vec2 g1 = hash2d(i+walk);
    vec2 g2 = hash2d(i+1.0);

    return kernel_summation(v0, v1, v2, g0, g1, g2);
}
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

uniform shader foreground;
uniform float2 imageSize;

#include "shaders/simplex2d.agsl"
#include "shaders/utils.agsl"

float random(vec2 uv) {
    return fract(sin(dot(uv.xy, vec2(14.53898, 56.233))) * 45312.644263742);
}

vec4 main(float2 fragCoord) {
    // fragCoord should be already the adjusted UVs to have the expected rect of the image.
    float variation = 0.5 + 0.5 * simplex2d(25. * fragCoord / imageSize.xx);
    float distance = 8. * variation;
    float aN = foreground.eval(fragCoord + vec2(0., distance)).a;
    float aS = foreground.eval(fragCoord + vec2(0., -distance)).a;
    float dY = (aN - aS) * 0.5;
    dY = max(dY, 0.0);

    float accumulatedSnow = smoothstep(0.1, 1.8, sqrt(dY * dY) * 5.0);
    vec4 color = vec4(0., 0., 0., 1.);
    color.r = accumulatedSnow;
    color.g = random(fragCoord / imageSize.xx);
    color.b = variation;
    return color;
}
Loading