summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-03-07 20:03:30 +0100
committerskal <pascal.massimino@gmail.com>2026-03-07 20:03:30 +0100
commitad9ee515d162d2aa23b64263e043d45add95615f (patch)
tree4e0e2d71d3f8675b3b63901c97a01a070cde53cb /src
parente4851ae9f310b44dab25eb979733281002c8953d (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')
-rw-r--r--src/effects/ntsc.wgsl62
-rw-r--r--src/effects/ntsc_effect.h12
-rw-r--r--src/effects/shaders.cc1
-rw-r--r--src/effects/shaders.h1
-rw-r--r--src/gpu/demo_effects.h1
-rw-r--r--src/tests/gpu/test_demo_effects.cc3
6 files changed, 80 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);
+}
diff --git a/src/effects/ntsc_effect.h b/src/effects/ntsc_effect.h
new file mode 100644
index 0000000..d8624ea
--- /dev/null
+++ b/src/effects/ntsc_effect.h
@@ -0,0 +1,12 @@
+// NTSC post-process effect with fisheye distortion
+#pragma once
+#include "effects/shaders.h"
+#include "gpu/wgsl_effect.h"
+
+struct Ntsc : public WgslEffect {
+ Ntsc(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : WgslEffect(ctx, inputs, outputs, start_time, end_time,
+ ntsc_shader_wgsl) {}
+};
diff --git a/src/effects/shaders.cc b/src/effects/shaders.cc
index e4b9b25..1b93a03 100644
--- a/src/effects/shaders.cc
+++ b/src/effects/shaders.cc
@@ -100,6 +100,7 @@ const char* flash_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_FLASH);
const char* scene1_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_SCENE1);
const char* scene2_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_SCENE2);
const char* scratch_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_SCRATCH);
+const char* ntsc_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_NTSC);
// Compute shaders
const char* gen_noise_compute_wgsl =
diff --git a/src/effects/shaders.h b/src/effects/shaders.h
index 76b5d96..0686b7e 100644
--- a/src/effects/shaders.h
+++ b/src/effects/shaders.h
@@ -17,6 +17,7 @@ extern const char* flash_shader_wgsl;
extern const char* scene1_shader_wgsl;
extern const char* scene2_shader_wgsl;
extern const char* scratch_shader_wgsl;
+extern const char* ntsc_shader_wgsl;
// Compute shaders
extern const char* gen_noise_compute_wgsl;
diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h
index a2500e7..9d794aa 100644
--- a/src/gpu/demo_effects.h
+++ b/src/gpu/demo_effects.h
@@ -30,6 +30,7 @@
#include "effects/scene1_effect.h"
#include "effects/scene2_effect.h"
#include "effects/scratch_effect.h"
+#include "effects/ntsc_effect.h"
// TODO: Port CNN effects
// #include "../../cnn_v1/src/cnn_v1_effect.h"
diff --git a/src/tests/gpu/test_demo_effects.cc b/src/tests/gpu/test_demo_effects.cc
index 3aa6230..b9d1463 100644
--- a/src/tests/gpu/test_demo_effects.cc
+++ b/src/tests/gpu/test_demo_effects.cc
@@ -73,6 +73,9 @@ static void test_effects() {
{"Scratch", std::make_shared<Scratch>(
fixture.ctx(), std::vector<std::string>{"source"},
std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"Ntsc", std::make_shared<Ntsc>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
};
int passed = 0;