feat(shaders): sistema de shaders runtime amb presets externs

- Afegir GpuShaderPreset i ShaderManager per carregar shaders des de data/shaders/
- Implementar preset ntsc-md-rainbows (2 passos: encode + decode MAME NTSC)
- Render loop multi-pass per shaders externs (targets intermedis R16G16B16A16_FLOAT)
- cycleShader(): cicla OFF→PostFX natius→shaders externs amb tecla X
- --shader <nom> per arrancar directament amb un preset extern
- CMake auto-descubreix i compila data/shaders/**/*.vert/.frag → .spv
- HUD F1 mostra 'Shader: <nom>' quan hi ha shader extern actiu

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-20 13:37:22 +01:00
parent e3f29c864b
commit f272bab296
19 changed files with 1004 additions and 23 deletions

View File

@@ -0,0 +1,69 @@
#version 450
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz,ImJezze
// Adapted from mame_ntsc_encode.slang for SDL3 GPU / Vulkan SPIRV
layout(location=0) in vec2 v_uv;
layout(location=0) out vec4 FragColor;
layout(set=2, binding=0) uniform sampler2D Source;
layout(set=3, binding=0) uniform NTSCParams {
float source_width;
float source_height;
float a_value;
float b_value;
float cc_value;
float scan_time;
float notch_width;
float y_freq;
float i_freq;
float q_freq;
float _pad0;
float _pad1;
} u;
const float PI = 3.1415927;
const float PI2 = PI * 2.0;
void main() {
vec2 source_dims = vec2(u.source_width, u.source_height);
// p_value=1: one texel step per sub-sample (no horizontal stretch)
vec2 PValueSourceTexel = vec2(1.0, 0.0) / source_dims;
vec2 C0 = v_uv + PValueSourceTexel * vec2(0.00, 0.0);
vec2 C1 = v_uv + PValueSourceTexel * vec2(0.25, 0.0);
vec2 C2 = v_uv + PValueSourceTexel * vec2(0.50, 0.0);
vec2 C3 = v_uv + PValueSourceTexel * vec2(0.75, 0.0);
vec4 Cx = vec4(C0.x, C1.x, C2.x, C3.x);
vec4 Cy = vec4(C0.y, C1.y, C2.y, C3.y);
vec4 Texel0 = texture(Source, C0);
vec4 Texel1 = texture(Source, C1);
vec4 Texel2 = texture(Source, C2);
vec4 Texel3 = texture(Source, C3);
vec4 HPosition = Cx;
vec4 VPosition = Cy;
const vec4 YDot = vec4(0.299, 0.587, 0.114, 0.0);
const vec4 IDot = vec4(0.595716, -0.274453, -0.321263, 0.0);
const vec4 QDot = vec4(0.211456, -0.522591, 0.311135, 0.0);
vec4 Y = vec4(dot(Texel0, YDot), dot(Texel1, YDot), dot(Texel2, YDot), dot(Texel3, YDot));
vec4 I = vec4(dot(Texel0, IDot), dot(Texel1, IDot), dot(Texel2, IDot), dot(Texel3, IDot));
vec4 Q = vec4(dot(Texel0, QDot), dot(Texel1, QDot), dot(Texel2, QDot), dot(Texel3, QDot));
float W = PI2 * u.cc_value * u.scan_time;
float WoPI = W / PI;
float HOffset = u.a_value / WoPI;
float VScale = u.b_value * source_dims.y / WoPI;
vec4 T = HPosition + vec4(HOffset) + VPosition * vec4(VScale);
vec4 TW = T * W;
FragColor = Y + I * cos(TW) + Q * sin(TW);
}