From ad0f386e1b5cd9148ad278c7f016734af00cd0bc Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 8 Mar 2026 23:38:11 +0100 Subject: ntsc effect for real --- src/shaders/render/scratch_lines.wgsl | 36 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/shaders/render/scratch_lines.wgsl') diff --git a/src/shaders/render/scratch_lines.wgsl b/src/shaders/render/scratch_lines.wgsl index 04ed6f8..6123486 100644 --- a/src/shaders/render/scratch_lines.wgsl +++ b/src/shaders/render/scratch_lines.wgsl @@ -12,24 +12,22 @@ #include "math/noise" fn scratch_lines(uv: vec2f, resolution: vec2f, time: f32) -> f32 { - // Quantize to ~24fps to simulate film frame rate - let t = floor(time * 24.0); + // Quantize to ~24fps to simulate film frame rate + let t = floor(time * 24.0); - var intensity = 0.0; - for (var i = 0; i < 8; i++) { - let seed = f32(i) * 17.3 + t; - // ~25% chance this scratch is visible this frame - let visible = step(0.75, hash_1f(seed + 3.1)); - // Random vertical position [0, 1] - let y = hash_1f(seed + 7.9); - // Thickness in pixels [1, 4] - let thickness = hash_1f(seed + 13.5) * 3.0 + 1.0; - // Brightness [0.5, 1.0] - let brightness = hash_1f(seed + 21.7) * 0.5 + 0.5; - // Soft linear falloff from line center - let dy = abs(uv.y - y) * resolution.y; - let line = clamp(1.0 - dy / thickness, 0.0, 1.0); - intensity += line * brightness * visible; - } - return clamp(intensity, 0.0, 1.0); + // Scanlines + let scan = abs(sin(uv.y * uniforms.resolution.y * 3.14159265)); + var intensity = 0.2 * scan; + + // Per-pixel temporal noise + let pixel = floor(uv * uniforms.resolution * .4); + let n = hash_2f(pixel + vec2f(time * 47.3, time * 31.7)) * 0.04 - 0.02; + intensity += n; + + // Horizontal jitter line (random scanline rolling artifact) + let jitter_y = hash_1f(fract(t * 0.37)); + let jitter_band = abs(uv.y - jitter_y); + let scratch = smoothstep(5. / uniforms.resolution.y, 0., jitter_band); + intensity += scratch * 0.11 * hash_1f(uv.x * 100.0 + t); + return clamp(intensity, 0.0, 1.0); } -- cgit v1.2.3