diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-07 20:03:30 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-07 20:03:30 +0100 |
| commit | ad9ee515d162d2aa23b64263e043d45add95615f (patch) | |
| tree | 4e0e2d71d3f8675b3b63901c97a01a070cde53cb /src/effects/ntsc.wgsl | |
| parent | e4851ae9f310b44dab25eb979733281002c8953d (diff) | |
feat(effects): add Ntsc post-process effect with fisheye distortion
WGSL-only WgslEffect implementing barrel/fisheye distortion, RGB chroma
separation, scanlines, per-pixel temporal noise, rolling jitter line,
vignette, and warm NTSC phosphor tint. Applied across all main sequences.
handoff(Gemini): Ntsc effect added; 13 effects total, 35+1 tests expected.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/effects/ntsc.wgsl')
| -rw-r--r-- | src/effects/ntsc.wgsl | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/effects/ntsc.wgsl b/src/effects/ntsc.wgsl new file mode 100644 index 0000000..f357b17 --- /dev/null +++ b/src/effects/ntsc.wgsl @@ -0,0 +1,62 @@ +// NTSC post-process effect with fisheye/barrel distortion +#include "sequence_uniforms" +#include "render/fullscreen_uv_vs" +#include "math/noise" + +@group(0) @binding(0) var input_sampler: sampler; +@group(0) @binding(1) var input_texture: texture_2d<f32>; +@group(0) @binding(2) var<uniform> uniforms: UniformsSequenceParams; + +// Barrel (fisheye) distortion: strength > 0 = barrel, < 0 = pincushion +fn fisheye(uv: vec2f, strength: f32) -> vec2f { + let c = uv * 2.0 - 1.0; + let r2 = dot(c, c); + let distorted = c * (1.0 + strength * r2); + return distorted * 0.5 + 0.5; +} + +@fragment fn fs_main(in: VertexOutput) -> @location(0) vec4f { + let t = uniforms.time; + + // Fisheye/barrel distortion + let uv = fisheye(in.uv, 0.18); + + // Black outside screen edges + if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) { + return vec4f(0.0, 0.0, 0.0, 1.0); + } + + // Chroma separation (horizontal RGB bleeding) + let bleed = 2.5 / uniforms.resolution.x; + let r = textureSample(input_texture, input_sampler, uv + vec2f( bleed, 0.0)).r; + let g = textureSample(input_texture, input_sampler, uv ).g; + let b = textureSample(input_texture, input_sampler, uv - vec2f( bleed, 0.0)).b; + var col = vec3f(r, g, b); + + // Scanlines + let scan = sin(uv.y * uniforms.resolution.y * 3.14159265) * 0.5 + 0.5; + col *= 0.82 + 0.18 * scan; + + // Per-pixel temporal noise + let pixel = floor(uv * uniforms.resolution); + let n = hash_2f(pixel + vec2f(t * 47.3, t * 31.7)) * 0.08 - 0.04; + col += n; + + // Horizontal jitter line (random scanline rolling artifact) + let jitter_y = fract(t * 0.37); + let jitter_band = abs(uv.y - jitter_y); + if (jitter_band < 0.003) { + col += hash_1f(uv.x * 100.0 + t) * 0.15; + } + + // Vignette (stronger at corners due to fisheye) + let vig = in.uv * 2.0 - 1.0; + col *= 1.0 - dot(vig, vig) * 0.45; + + // Slight NTSC warm tint (boost red/green, attenuate blue) + col.r *= 1.04; + col.g *= 1.01; + col.b *= 0.94; + + return vec4f(clamp(col, vec3f(0.0), vec3f(1.0)), 1.0); +} |
