1/* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17uniform shader foreground; 18uniform half imageWidth; 19uniform half snowThickness; 20 21#include "shaders/simplex2d.agsl" 22#include "shaders/utils.agsl" 23 24float random(vec2 uv) { 25 return fract(sin(dot(uv, vec2(14.53898, 56.233))) * 45312.644263742); 26} 27 28vec4 main(float2 fragCoord) { 29 // fragCoord should be already the adjusted UVs to have the expected rect of the image. 30 vec2 uv = fragCoord / imageWidth; 31 float variation = 0.3 + simplex2d(11. * uv); 32 float distance = variation * snowThickness; 33 34 float aN = foreground.eval(fragCoord + vec2(0., distance)).a; 35 float aS = foreground.eval(fragCoord + vec2(0., -distance)).a; 36 float dY = (aN - aS) * 0.5; 37 dY = max(dY, 0.0); 38 39 float accumulatedSnow = smoothstep(0.1, 1.8, dY * 5.0); 40 vec4 color = vec4(0., 0., 0., 1.); 41 color.r = accumulatedSnow; 42 color.g = random(uv); 43 color.b = variation; 44 return color; 45} 46