// Calm painted sky: smooth gradient, slow clouds, steady sun and moon. // Uses the continuous clock (skyTime) instead of the 12 fps boil. in vec3 Direction; layout (location = 0) out vec4 OutColor; layout (location = 1) out vec4 OutNormalDepth; uniform vec3 sunDirection; uniform vec3 lightColor; uniform vec3 skyTop; uniform vec3 skyHorizon; uniform float dayFactor; uniform float skyTime; uniform float overcast; // 0 clear .. 1 clouded over (rain) const float SKY_DEPTH = 1000.0; // the ink pass treats this depth as sky void main() { vec3 dir = normalize(Direction); vec3 sun = normalize(sunDirection); float sunDot = dot(dir, sun); // Gradient with a few faint horizontal brush strokes, flowing very slowly float brush = (fbm3(vec3(dir.x * 1.5, dir.y * 6.0, dir.z * 1.5) + skyTime * 0.002) - 0.5) * 0.05; vec3 color = mix(skyHorizon, skyTop, smoothstep(-0.05, 0.75, dir.y + brush)); color = mix(color, skyHorizon * 0.7, smoothstep(0.0, -0.4, dir.y)); // below the horizon // Warm glow around a low sun float lowSun = 1.0 - smoothstep(0.0, 0.6, sun.y); color += lightColor * 0.25 * pow(max(sunDot, 0.0), 6.0) * lowSun * step(-0.2, sun.y) * (1.0 - overcast); // Soft clouds: the noise field is warped by itself and both drift, // so shapes flow and fold like slow watercolor instead of sliding. if (dir.y > 0.0) { vec2 plane = dir.xz / (dir.y + 0.25) * 0.3; float t = skyTime * 0.01; vec2 warp = vec2(fbm3(vec3(plane, t)), fbm3(vec3(plane + 5.2, t + 1.3))) - 0.5; float c = fbm3(vec3(plane + warp * 1.4 + vec2(t * 0.8, t * 0.3), t * 0.5)); // clouding over: more of them, thicker, a darker grey underneath float cloud = smoothstep(0.45 - 0.4 * overcast, 0.8 - 0.35 * overcast, c) * smoothstep(0.02 - 0.15 * overcast, 0.3, dir.y); vec3 tint = mix(skyHorizon, vec3(1.0), 0.35) * mix(vec3(1.0), lightColor, 0.4); vec3 grey = skyHorizon * mix(0.95, 0.6, smoothstep(0.4, 0.9, c)); // (heavy rain clouds: dark bellies) tint = mix(tint, grey, overcast); color = mix(color, tint, cloud * mix(0.55, 0.95, overcast)); color = mix(color, skyHorizon * 0.85, 0.45 * overcast); // (the whole sky a veil) } // Sun: steady disc with a soft halo float sunDisc = smoothstep(0.9975, 0.9985, sunDot) + pow(max(sunDot, 0.0), 64.0) * 0.35; float clear = 1.0 - smoothstep(0.2, 0.7, overcast); // (behind the clouds: no sun, moon or stars) color += (lightColor * 0.5 + 0.5) * sunDisc * smoothstep(-0.1, 0.05, sun.y) * clear; // Moon opposite the sun, at night float moonDisc = smoothstep(0.9988, 0.9993, dot(dir, -sun)); color = mix(color, vec3(0.92, 0.90, 0.80), moonDisc * (1.0 - dayFactor) * clear); // Sparse, steady stars float star = step(0.997, hash13(floor(dir * 120.0))) * smoothstep(0.0, 0.2, dir.y); color += star * 0.5 * (1.0 - dayFactor) * clear; OutColor = vec4(color, 1.0); OutNormalDepth = vec4(0.0, 0.0, 0.0, SKY_DEPTH); }