// Horizontal film scratch lines utility // Returns scratch intensity [0,1] to additively overlay on a color buffer. // // Parameters: // uv - normalized texture coordinates [0,1] // resolution - screen size in pixels (used for sub-pixel thickness) // time - physical time in seconds // // Simulates aged/damaged film: ~8 random horizontal lines per frame, // each with independent position, thickness, brightness and on/off state. // Time is quantized to 24 buckets/sec so scratches flicker like film frames. #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); // 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); }