techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/res/sdr/sky_old.fs
diff options
context:
space:
mode:
Diffstat (limited to 'res/sdr/sky_old.fs')
-rw-r--r--res/sdr/sky_old.fs92
1 files changed, 92 insertions, 0 deletions
diff --git a/res/sdr/sky_old.fs b/res/sdr/sky_old.fs
new file mode 100644
index 0000000..039691c
--- /dev/null
+++ b/res/sdr/sky_old.fs
@@ -0,0 +1,92 @@
+#version 330
+
+uniform vec2 resolution;
+uniform vec3 camera_forward;
+uniform vec3 camera_right;
+uniform vec3 camera_up;
+
+uniform vec3 sun_direction;
+
+uniform float aspect_ratio;
+uniform float tan_half_fovy;
+
+out vec4 finalColor;
+
+float
+angular_halo(float alignment, float outer_cos, float inner_cos) {
+ /*
+ * alignment is 1.0 while looking directly at the celestial body.
+ *
+ * outer_cos = cos(outer halo angle)
+ * inner_cos = cos(inner halo angle)
+ */
+ return smoothstep(
+ outer_cos,
+ inner_cos,
+ alignment
+ );
+}
+
+void
+main() {
+ vec2 screen = gl_FragCoord.xy / resolution;
+ vec2 ndc = screen * 2.0 - 1.0;
+
+ vec3 view_direction = normalize(
+ camera_forward +
+ camera_right * ndc.x * aspect_ratio * tan_half_fovy +
+ camera_up * ndc.y * tan_half_fovy
+ );
+
+ /*
+ * Controls the vertical gradient.
+ *
+ * -0.2 includes some colour below the horizon so the transition
+ * remains smooth while looking downward.
+ */
+ float height = smoothstep(-0.20, 0.80, view_direction.y);
+
+ /*
+ * The world becomes mostly daylight shortly after the sun crosses
+ * the horizon, and mostly night shortly after it sets.
+ */
+ float day_amount = smoothstep(-0.10, 0.12, sun_direction.y);
+
+ vec3 night_horizon = vec3(0.055, 0.045, 0.110);
+ vec3 night_zenith = vec3(0.005, 0.008, 0.025);
+
+ vec3 day_horizon = vec3(0.620, 0.780, 0.920);
+ vec3 day_zenith = vec3(0.080, 0.280, 0.620);
+
+ vec3 night_sky = mix(night_horizon, night_zenith, height);
+ vec3 day_sky = mix(day_horizon, day_zenith, height);
+
+ vec3 sky = mix(night_sky, day_sky, day_amount);
+
+ /*
+ * Stylized sunrise/sunset colour.
+ *
+ * This is strongest:
+ * - near the horizon;
+ * - while the sun is near the horizon;
+ * - while looking toward the sun.
+ */
+ float horizon =
+ 1.0 - smoothstep(0.0, 0.35, abs(view_direction.y));
+
+ float twilight =
+ 1.0 - smoothstep(0.02, 0.28, abs(sun_direction.y));
+
+ float sun_facing = max(dot(view_direction, sun_direction), 0.0);
+ float sun_facing_2 = sun_facing * sun_facing;
+ float sun_facing_4 = sun_facing_2 * sun_facing_2;
+
+ vec3 sunset_colour = vec3(0.65, 0.16, 0.035);
+
+ sky += sunset_colour *
+ horizon *
+ twilight *
+ sun_facing_4;
+
+ finalColor = vec4(min(sky, vec3(1.0)), 1.0);
+}