diff options
Diffstat (limited to 'shaders/post')
| -rw-r--r-- | shaders/post/crt.glsl | 40 | ||||
| -rw-r--r-- | shaders/post/glitch.glsl | 36 | ||||
| -rw-r--r-- | shaders/post/prefix.glsl | 11 | ||||
| -rw-r--r-- | shaders/post/ripple.glsl | 23 |
4 files changed, 64 insertions, 46 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; diff --git a/shaders/post/glitch.glsl b/shaders/post/glitch.glsl index ff9ebcb8..8f420d9c 100644 --- a/shaders/post/glitch.glsl +++ b/shaders/post/glitch.glsl @@ -1,4 +1,5 @@ -// Glitch: now and then the signal slips. Every couple of seconds a short +// Glitch: now and then the signal slips. At the default level, every couple +// of seconds a short // burst tears a few horizontal bands sideways and pulls their red and blue // apart; the bands are sized in pixels and the burst eases in and out over // a fraction of a second, so it reads as one event rather than a flicker, @@ -7,12 +8,15 @@ // A torn band's brightness dips in linear light. It is a Shadertoy file: // pardes puts its prefix before it. -const float PERIOD = 2.4; // seconds between bursts, on average -const float BURST = 0.28; // seconds a burst lasts -const float STEP_HZ = 24.0; // how often a burst re-tears -const float SHIFT_PX = 14.0; -const float SPLIT_PX = 2.5; -const float DIP = 0.12; +// Each at levels 1, 2 and 3 (`Glitch 1`..`Glitch 3`); 2 is the default. A +// higher level slips more often and harder. +float period() { return pardesByLevel(4.5, 2.4, 0.55); } // seconds between bursts, on average +float burst() { return pardesByLevel(0.2, 0.28, 0.5); } // seconds a burst lasts +float stepHz() { return pardesByLevel(20.0, 24.0, 30.0); } // how often a burst re-tears +float shiftPx() { return pardesByLevel(8.0, 14.0, 34.0); } +float splitPx() { return pardesByLevel(1.5, 2.5, 6.0); } +float dip() { return pardesByLevel(0.08, 0.12, 0.22); } +float tearFrom() { return pardesByLevel(0.8, 0.72, 0.35); } // how few bands tear float hash(vec2 p) { vec3 q = fract(vec3(p.xyx) * 0.1031); @@ -34,27 +38,27 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) { vec2 uv = fragCoord / size; // Which burst window this is, when in it the burst starts, and how far // into the burst we are: 0 outside one. - float window = floor(iTime / PERIOD); - float start = window * PERIOD + hash(vec2(window, 7.0)) * (PERIOD - BURST); - float t = (iTime - start) / BURST; + float window = floor(iTime / period()); + float start = window * period() + hash(vec2(window, 7.0)) * (period() - burst()); + float t = (iTime - start) / burst(); float live = step(0.0, t) * step(t, 1.0); float envelope = live * sin(3.14159265 * clamp(t, 0.0, 1.0)); if (envelope <= 0.0) { fragColor = texture(iChannel0, uv); return; } - // Bands of 6 to 40 px, re-cut at STEP_HZ during the burst; about one + // Bands of 6 to 40 px, re-cut at stepHz() during the burst; about one // band in four tears. - float tick = floor(iTime * STEP_HZ); + float tick = floor(iTime * stepHz()); float band_px = mix(6.0, 40.0, hash(vec2(tick, 3.0))); float band = floor(fragCoord.y / band_px); float roll = hash(vec2(band, tick)); - float tear = smoothstep(0.72, 0.9, roll) * envelope; - float shift = (hash(vec2(tick, band + 11.0)) - 0.5) * 2.0 * SHIFT_PX * tear; + float tear = smoothstep(tearFrom(), tearFrom() + 0.18, roll) * envelope; + float shift = (hash(vec2(tick, band + 11.0)) - 0.5) * 2.0 * shiftPx() * tear; vec2 at = vec2(fragCoord.x + shift, fragCoord.y); - vec2 split = vec2(SPLIT_PX * tear, 0.0); + vec2 split = vec2(splitPx() * tear, 0.0); vec4 center = texture(iChannel0, at / size); vec3 col = vec3(texture(iChannel0, (at + split) / size).r, center.g, texture(iChannel0, (at - split) / size).b); - col = toSrgb(toLinear(col) * (1.0 - DIP * tear)); + col = toSrgb(toLinear(col) * (1.0 - dip() * tear)); fragColor = vec4(col, center.a); } diff --git a/shaders/post/prefix.glsl b/shaders/post/prefix.glsl index efa49483..e718a98f 100644 --- a/shaders/post/prefix.glsl +++ b/shaders/post/prefix.glsl @@ -39,12 +39,19 @@ layout(set = 3, binding = 0, std140) uniform Globals { uniform vec3 iSelectionBackgroundColor; }; -// pardes's own: 1 when the window is opaque, so a pass cannot punch holes -// in it through its alpha. +// pardes's own: pardesOpaque is 1 when the window is opaque, so a pass +// cannot punch holes in it through its alpha; pardesLevel is a bundled +// pass's strength, 1 to 3 (`Crt 3`), and 0 for a user's file. layout(set = 3, binding = 1, std140) uniform PardesPost { float pardesOpaque; + float pardesLevel; }; +// A bundled pass's constant at levels 1, 2 and 3. +float pardesByLevel(float one, float two, float three) { + return pardesLevel < 1.5 ? one : (pardesLevel < 2.5 ? two : three); +} + #define CURSORSTYLE_BLOCK 0 #define CURSORSTYLE_BLOCK_HOLLOW 1 #define CURSORSTYLE_BAR 2 diff --git a/shaders/post/ripple.glsl b/shaders/post/ripple.glsl index ffecbf70..3236d339 100644 --- a/shaders/post/ripple.glsl +++ b/shaders/post/ripple.glsl @@ -1,18 +1,21 @@ // Ripple: the page as a still pool a slow swell crosses. Rings travel out // from the middle of the window at a fixed speed in pixels, so they look -// the same at any size and frame rate; the displacement is at most a couple -// of pixels, so text stays readable, and it eases in over its first half +// the same at any size and frame rate; at the default level the displacement +// is at most a couple of pixels, so text stays readable, and it eases in over its first half // second instead of snapping on. Each ring catches the light a little on its // rising side, in linear light, and the result is dithered so the shading // never bands. It is a Shadertoy file: pardes puts its prefix before it. const float TAU = 6.28318530718; -const float WAVELENGTH_PX = 150.0; -const float SPEED_PX = 55.0; // outward, per second -const float AMPLITUDE_PX = 2.2; -const float SHADE = 0.035; // light on a slope, linear const float EASE_IN = 0.5; // seconds +// Each at levels 1, 2 and 3 (`Ripple 1`..`Ripple 3`); 2 is the default. +float wavelengthPx() { return pardesByLevel(170.0, 150.0, 120.0); } +float speedPx() { return pardesByLevel(40.0, 55.0, 80.0); } // outward, per second +float amplitudePx() { return pardesByLevel(1.2, 2.2, 5.0); } +float shade() { return pardesByLevel(0.02, 0.035, 0.09); } // light on a slope, linear +float reachEnd() { return pardesByLevel(0.85, 0.95, 1.3); } // how far out it dies away + vec3 toLinear(vec3 c) { return mix(pow((c + 0.055) / 1.055, vec3(2.4)), c / 12.92, lessThanEqual(c, vec3(0.04045))); } @@ -34,16 +37,16 @@ void mainImage(out vec4 fragColor, in vec2 fragCoord) { float reach = 0.5 * length(size); // Strongest a third of the way out, fading to nothing at the middle // and at the edges, so the window's frame never wobbles. - float envelope = smoothstep(0.0, 0.18, radius / reach) * (1.0 - smoothstep(0.35, 0.95, radius / reach)); + float envelope = smoothstep(0.0, 0.18, radius / reach) * (1.0 - smoothstep(0.35, reachEnd(), radius / reach)); float ease = smoothstep(0.0, EASE_IN, iTime); - float phase = (radius - iTime * SPEED_PX) * TAU / WAVELENGTH_PX; + float phase = (radius - iTime * speedPx()) * TAU / wavelengthPx(); float height = sin(phase); float slope = cos(phase); vec2 dir = offset / max(radius, 1e-3); - vec2 moved = fragCoord + dir * height * AMPLITUDE_PX * envelope * ease; + vec2 moved = fragCoord + dir * height * amplitudePx() * envelope * ease; vec4 s = texture(iChannel0, moved / size); - vec3 col = toLinear(s.rgb) * (1.0 + SHADE * slope * envelope * ease); + vec3 col = toLinear(s.rgb) * (1.0 + shade() * slope * envelope * ease); vec3 srgb = toSrgb(col) + (ign(fragCoord + float(iFrame % 64) * 5.588238) - 0.5) / 255.0; fragColor = vec4(clamp(srgb, 0.0, 1.0), s.a); } |
