Sunday Under the Leaves
This one didn't compile in your browser.
Sourcejittered-grid elliptical sun-dapple spots with wind sway, low-frequency drifting cloud-shadow mask
precision mediump float;
uniform vec2 u_resolution;
uniform float u_time;
float hash(vec2 p){ return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(vec2 p){
vec2 i = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
float a = hash(i);
float b = hash(i + vec2(1.0, 0.0));
float c = hash(i + vec2(0.0, 1.0));
float d = hash(i + vec2(1.0, 1.0));
return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
}
float dapple(vec2 p, float sc, float t, float seed, float soft){
p *= sc;
vec2 g = floor(p);
float acc = 0.0;
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 3; i++) {
vec2 c = g + vec2(float(i) - 1.0, float(j) - 1.0);
float h = hash(c + seed);
float h2 = hash(c + seed + 7.31);
vec2 o = vec2(h, h2);
o += 0.17 * vec2(sin(t * 0.45 + h * 6.283), 0.6 * sin(t * 0.33 + h2 * 6.283));
vec2 d = p - (c + o);
float ca = 0.8;
float sa = 0.6;
d = vec2(ca * d.x + sa * d.y, -sa * d.x + ca * d.y);
d.x *= 0.78;
float r = 0.2 + 0.18 * h2;
float b = 1.0 - smoothstep(r * soft, r, length(d));
acc += b * step(0.3, h);
}
}
return acc;
}
void main(){
vec2 uv = gl_FragCoord.xy / u_resolution;
vec2 p = (gl_FragCoord.xy - 0.5 * u_resolution) / u_resolution.y;
float t = u_time;
vec3 shadeA = vec3(0.30, 0.36, 0.29);
vec3 shadeB = vec3(0.42, 0.40, 0.31);
float g = noise(p * 1.6 + vec2(3.1, 1.7));
vec3 ground = mix(shadeA, shadeB, g);
float leaf = smoothstep(0.55, 0.8, noise(p * 3.2 + vec2(9.0, 4.0)));
ground = mix(ground, vec3(0.50, 0.33, 0.20), leaf * 0.45);
ground *= 0.92 + 0.12 * uv.y;
float big = dapple(p, 2.6, t, 1.0, 0.25);
float small = dapple(p + vec2(0.37, 0.11), 5.5, t * 1.15, 4.0, 0.5);
float L = clamp(big * 0.55 + small * 0.6, 0.0, 1.1);
vec2 cp = p * 1.1 + vec2(-t * 0.028, -t * 0.009);
float cl = noise(cp) * 0.65 + noise(cp * 2.1 + 5.0) * 0.35;
float cloud = smoothstep(0.42, 0.72, cl);
float sun = mix(1.0, 0.35, cloud);
vec3 light = vec3(0.98, 0.84, 0.56);
vec3 col = mix(ground, light * (0.75 + 0.2 * g), clamp(L * sun * 0.82, 0.0, 0.9));
float glow = smoothstep(1.1, 0.0, length(p - vec2(-0.55, 0.5)));
col += vec3(0.09, 0.07, 0.03) * glow * sun;
col = mix(col, col * vec3(0.92, 0.97, 1.02), cloud * 0.5);
float vig = smoothstep(1.05, 0.35, length(p * vec2(0.85, 1.0)));
col *= 0.78 + 0.22 * vig;
col = clamp(col, 0.06, 0.93);
gl_FragColor = vec4(col, 1.0);
}