Snowfall
glint · Examples · Tutorials · Gallery
Snow falling over a moonlit forest, in layers: near flakes big, fast and out of focus, far ones small and slow (parallax).

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.
The code
One pass, in GLSL.
fragment shader
#version 300 es
precision highp float;
uniform float time;
uniform vec2 resolution;
in vec2 v_texcoord;
out vec4 fragColor;
float hash(float n) { return fract(sin(n * 127.1) * 43758.5453); }
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec2 hash2(float n) { return fract(sin(vec2(n * 127.1, n * 269.5)) * 43758.5453); }
mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, s, -s, c); }
vec3 pal(float t) { return 0.5 + 0.5 * cos(6.28318 * (t + vec3(0.0, 0.33, 0.67))); }
float noise(float x) { float i = floor(x), f = fract(x); return mix(hash(i), hash(i + 1.0), f * f * (3.0 - 2.0 * f)); }
void main() {
vec2 uv = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
vec3 col = mix(vec3(0.15, 0.2, 0.35), vec3(0.01, 0.02, 0.06), uv.y + 0.5);
col += vec3(0.6, 0.7, 0.9) * (smoothstep(0.08, 0.075, length(uv - vec2(0.45, 0.25))) + 0.2 * exp(-length(uv - vec2(0.45, 0.25)) * 5.0));
// Two ridges of pine trees.
for (int l = 0; l < 2; l++) {
float fl = float(l);
float x = uv.x * (6.0 + fl * 4.0) + fl * 5.0;
float tree = abs(fract(x) - 0.5) * (1.2 + noise(floor(x) * 3.0)) ;
float top = -0.12 - fl * 0.12 + noise(x * 0.3) * 0.08 - tree * 0.5;
col = mix(col, vec3(0.02, 0.04, 0.06) + fl * 0.01, step(uv.y, top));
}
// Snow, far layers first.
for (int i = 0; i < 6; i++) {
float depth = 1.0 + float(i);
vec2 p = uv * (3.0 + depth * 2.0);
p.y += time * (1.2 / depth + 0.1);
p.x += sin(time * 0.5 + p.y * 0.8 + depth) * 0.3;
vec2 id = floor(p), f = fract(p) - 0.5;
vec2 at = (hash2(hash(id) * 100.0 + depth) - 0.5) * 0.6;
float size = 0.06 / sqrt(depth) * (0.5 + hash(id + 3.0));
float blur = 0.01 + 0.04 / depth;
col += vec3(0.9, 0.95, 1.0) * smoothstep(size + blur, size - blur, length(f - at)) * (0.9 / depth + 0.1);
}
fragColor = vec4(col, 1.0);
}More More GLSL examples
Julia set · Mandelbrot zoom · Lava lamp · Circuit board · Ink in water · Infinite spheres · Night sky · Dithered retro