#version 330 uniform vec2 resolution; uniform vec3 camera_forward; uniform vec3 camera_right; uniform vec3 camera_up; uniform vec3 sun_direction; uniform vec3 horizon_colour; uniform vec3 zenith_colour; uniform float day_amount; uniform float twilight_amount; uniform float tan_half_fovy; out vec4 finalColor; void main() { vec2 ndc = gl_FragCoord.xy / resolution * 2.0 - 1.0; float aspect_ratio = resolution.x / resolution.y; vec3 view_direction = normalize( camera_forward + camera_right * ndc.x * aspect_ratio * tan_half_fovy + camera_up * ndc.y * tan_half_fovy ); float height = smoothstep(-0.20, 0.80, view_direction.y); float horizon = 1.0 - smoothstep(0.0, 0.35, abs(view_direction.y)); vec3 sky = mix(horizon_colour, zenith_colour, height); float sun_alignment = dot(view_direction, sun_direction); float sun_facing = max(sun_alignment, 0.0); float sun_facing_2 = sun_facing * sun_facing; float sun_facing_4 = sun_facing_2 * sun_facing_2; sky += vec3(0.65, 0.16, 0.035) * horizon * twilight_amount * sun_facing_4; float sun_wide = smoothstep(0.9510565, 0.9986295, sun_alignment); float sun_core = smoothstep(0.9925462, 0.9998477, sun_alignment); float moon_alignment = -sun_alignment; float moon_wide = smoothstep(0.9702957, 0.9993908, moon_alignment); float moon_core = smoothstep(0.9961947, 0.9999619, moon_alignment); float sun_visibility = smoothstep(-0.12, 0.04, sun_direction.y); float moon_visibility = smoothstep(-0.10, 0.04, -sun_direction.y); vec3 sun_glow_colour = mix( vec3(1.00, 0.82, 0.38), vec3(1.00, 0.25, 0.035), twilight_amount ); vec3 moon_glow_colour = vec3(0.32, 0.46, 0.82); float sun_glow = (sun_wide * 0.13 + sun_core * 0.32) * sun_visibility; float moon_glow = (moon_wide * 0.08 + moon_core * 0.17) * moon_visibility * (1.0 - day_amount); sky += (1.0 - sky) * sun_glow_colour * sun_glow; sky += (1.0 - sky) * moon_glow_colour * moon_glow; finalColor = vec4(clamp(sky, 0.0, 1.0), 1.0); }