diff options
Diffstat (limited to 'weathereffects/assets/shaders/snow_accumulation.agsl')
-rw-r--r-- | weathereffects/assets/shaders/snow_accumulation.agsl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/weathereffects/assets/shaders/snow_accumulation.agsl b/weathereffects/assets/shaders/snow_accumulation.agsl new file mode 100644 index 0000000..baa34e6 --- /dev/null +++ b/weathereffects/assets/shaders/snow_accumulation.agsl @@ -0,0 +1,42 @@ +/* + * 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; +} |