summaryrefslogtreecommitdiff
path: root/shaders/post/crt.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'shaders/post/crt.glsl')
-rw-r--r--shaders/post/crt.glsl40
1 files changed, 22 insertions, 18 deletions
diff --git a/shaders/post/crt.glsl b/shaders/post/crt.glsl
index 16a5cdd9..768157ef 100644
--- a/shaders/post/crt.glsl
+++ b/shaders/post/crt.glsl
@@ -7,19 +7,23 @@
// Shadertoy file: pardes puts its prefix before it (shaders/post/prefix.glsl).
const float TAU = 6.28318530718;
-const float CHROMA_PX = 0.35; // red and blue apart, at the corners
-const float BLOOM_RADIUS_PX = 1.75;
-const float BLOOM_THRESHOLD = 0.60; // linear-light channel peak
+// Level 3 glows wider and from dimmer ink.
+float bloomRadiusPx() { return pardesByLevel(1.75, 1.75, 3.0); }
+float bloomThreshold() { return pardesByLevel(0.6, 0.6, 0.3); } // linear-light channel peak
const float BLOOM_SOFTNESS = 0.25;
-const float BLOOM_STRENGTH = 0.05;
const float SCAN_PERIOD_PX = 3.0;
-const float SCAN_STRENGTH = 0.07;
const float MASK_PERIOD_PX = 3.0;
-const float MASK_STRENGTH = 0.018;
-const float VIGNETTE_STRENGTH = 0.12; // at the far corners only
-const float HUM_STRENGTH = 0.004;
const float HUM_HZ = 0.11;
-const float EXPOSURE = 1.015;
+
+// Each strength at levels 1, 2 and 3 (`Crt 1`..`Crt 3`): 2 is the default,
+// 3 as strong as the old barrel CRT looked.
+float chromaPx() { return pardesByLevel(0.2, 0.35, 2.2); } // red and blue apart, at the corners
+float bloomStrength() { return pardesByLevel(0.03, 0.05, 0.3); }
+float scanStrength() { return pardesByLevel(0.035, 0.07, 0.42); }
+float maskStrength() { return pardesByLevel(0.01, 0.018, 0.12); }
+float vignetteStrength() { return pardesByLevel(0.06, 0.12, 0.42); } // at the far corners only
+float humStrength() { return pardesByLevel(0.002, 0.004, 0.012); }
+float exposure() { return pardesByLevel(1.008, 1.015, 1.1); }
vec3 toLinear(vec3 c) {
return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045)));
@@ -37,7 +41,7 @@ vec3 scene(vec2 uv) {
vec3 brightPass(vec2 uv) {
vec3 c = scene(uv);
float peak = max(c.r, max(c.g, c.b));
- return c * smoothstep(BLOOM_THRESHOLD, BLOOM_THRESHOLD + BLOOM_SOFTNESS, peak);
+ return c * smoothstep(bloomThreshold(), bloomThreshold() + BLOOM_SOFTNESS, peak);
}
// Interleaved gradient noise: a dither with no visible pattern.
@@ -54,24 +58,24 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// The beam converges least at the corners: red and blue drift apart
// there, by a third of a pixel.
- vec2 chroma = cc * (CHROMA_PX * r2 * 0.5) * texel;
+ vec2 chroma = cc * (chromaPx() * r2 * 0.5) * texel;
vec3 col = vec3(scene(uv + chroma).r, scene(uv).g, scene(uv - chroma).b);
- vec2 b = texel * BLOOM_RADIUS_PX;
+ vec2 b = texel * bloomRadiusPx();
vec3 bloom = brightPass(uv + vec2(b.x, 0.0)) + brightPass(uv - vec2(b.x, 0.0)) +
brightPass(uv + vec2(0.0, b.y)) + brightPass(uv - vec2(0.0, b.y));
- col += bloom * (0.25 * BLOOM_STRENGTH);
+ col += bloom * (0.25 * bloomStrength());
// A beam is brightest on its line and falls off between lines; the
// mask is three phosphor stripes a triad. Both average to one, so the
// theme keeps its brightness.
float line = 0.5 + 0.5 * cos(fragCoord.y * TAU / SCAN_PERIOD_PX);
- col *= 1.0 - SCAN_STRENGTH * (line * line - 0.375) / 0.625;
- col *= 1.0 + MASK_STRENGTH * cos(fragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
+ col *= 1.0 - scanStrength() * (line * line - 0.375) / 0.625;
+ col *= 1.0 + maskStrength() * cos(fragCoord.x * TAU / MASK_PERIOD_PX + vec3(0.0, TAU / 3.0, 2.0 * TAU / 3.0));
- float vignette = 1.0 - VIGNETTE_STRENGTH * pow(clamp(r2 * 0.5, 0.0, 1.0), 1.6);
- float hum = 1.0 + HUM_STRENGTH * sin((uv.y * 1.35 - iTime * HUM_HZ) * TAU);
- col *= vignette * hum * EXPOSURE;
+ float vignette = 1.0 - vignetteStrength() * pow(clamp(r2 * 0.5, 0.0, 1.0), 1.6);
+ float hum = 1.0 + humStrength() * sin((uv.y * 1.35 - iTime * HUM_HZ) * TAU);
+ col *= vignette * hum * exposure();
vec3 srgb = toSrgb(col);
srgb += (ign(fragCoord + float(iFrame % 64) * vec2(5.588238, 5.588238)) - 0.5) / 255.0;