diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-02 15:55:03 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-02 15:55:03 +0100 |
| commit | c194f59e171a1e58ce1704f37d99ffcd09a42433 (patch) | |
| tree | f77a32f2c4c23b335209b8df11cc82920388b51a /src/gpu/effects/shaders.cc | |
| parent | 316825883c705ed0fe927c32e072f98141d3eaa3 (diff) | |
fix(gpu): Resolve high-DPI squished rendering and 3D shadow bugs
- Implemented dynamic resolution support in all shaders and effects.
- Added explicit viewport setting for all render passes to ensure correct scaling.
- Fixed 3D shadow mapping by adding PLANE support and standardizing soft shadow logic.
- Propagated resize events through the Effect hierarchy.
- Applied project-wide code formatting.
Diffstat (limited to 'src/gpu/effects/shaders.cc')
| -rw-r--r-- | src/gpu/effects/shaders.cc | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/gpu/effects/shaders.cc b/src/gpu/effects/shaders.cc index 0e80230..ac0bba9 100644 --- a/src/gpu/effects/shaders.cc +++ b/src/gpu/effects/shaders.cc @@ -122,6 +122,15 @@ const char* passthrough_shader_wgsl = R"( @group(0) @binding(0) var smplr: sampler; @group(0) @binding(1) var txt: texture_2d<f32>; +struct Uniforms { + time: f32, + beat: f32, + intensity: f32, + aspect_ratio: f32, + resolution: vec2<f32>, +}; +@group(0) @binding(2) var<uniform> uniforms: Uniforms; + @vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4<f32> { var pos = array<vec2<f32>, 3>( vec2<f32>(-1, -1), @@ -132,7 +141,7 @@ const char* passthrough_shader_wgsl = R"( } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - return textureSample(txt, smplr, p.xy / vec2<f32>(1280.0, 720.0)); + return textureSample(txt, smplr, p.xy / uniforms.resolution); })"; const char* ellipse_shader_wgsl = R"( @@ -141,6 +150,7 @@ struct Uniforms { beat: f32, intensity: f32, aspect_ratio: f32, + resolution: vec2<f32>, }; @group(0) @binding(0) var<uniform> uniforms: Uniforms; @@ -187,7 +197,7 @@ fn sdEllipse(p: vec2<f32>, ab: vec2<f32>) -> f32 { } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - let uv = (p.xy / vec2<f32>(1280.0, 720.0) - 0.5) * 2.0; + let uv = (p.xy / uniforms.resolution - 0.5) * 2.0; let movement = vec2<f32>(sin(uniforms.time * 0.7), cos(uniforms.time * 0.5)); let d = sdEllipse((uv * vec2<f32>(uniforms.aspect_ratio, 1.0)) - movement, vec2<f32>(0.5, 0.3) * (1.0 + uniforms.beat * 0.2)); return mix(vec4<f32>(0.2, 0.8, 0.4, 1.0), vec4<f32>(0.0), smoothstep(0.0, 0.01, d)); @@ -244,6 +254,7 @@ struct Uniforms { beat: f32, intensity: f32, aspect_ratio: f32, + resolution: vec2<f32>, }; @group(0) @binding(2) var<uniform> uniforms: Uniforms; @@ -258,12 +269,12 @@ struct Uniforms { } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - let uv = p.xy / vec2<f32>(1280.0, 720.0); + let uv = p.xy / uniforms.resolution; var res = vec4<f32>(0.0); let size = 5.0 * uniforms.intensity; for (var x: f32 = -2.0; x <= 2.0; x += 1.0) { for (var y: f32 = -2.0; y <= 2.0; y += 1.0) { - res += textureSample(txt, smplr, uv + vec2<f32>(x, y) * size / 1280.0); + res += textureSample(txt, smplr, uv + vec2<f32>(x, y) * size / uniforms.resolution.x); } } return res / 25.0; @@ -278,6 +289,7 @@ struct Uniforms { beat: f32, intensity: f32, aspect_ratio: f32, + resolution: vec2<f32>, }; @group(0) @binding(2) var<uniform> uniforms: Uniforms; @@ -292,7 +304,7 @@ struct Uniforms { } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - let uv = p.xy / vec2<f32>(1280.0, 720.0); + let uv = p.xy / uniforms.resolution; var col = textureSample(txt, smplr, uv); let thr = 0.5 + 0.3 * sin(uniforms.time); if (col.r < thr) { @@ -316,6 +328,7 @@ struct Uniforms { beat: f32, intensity: f32, aspect_ratio: f32, + resolution: vec2<f32>, }; @group(0) @binding(2) var<uniform> uniforms: Uniforms; @@ -330,7 +343,7 @@ struct Uniforms { } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - let uv = p.xy / vec2<f32>(1280.0, 720.0); + let uv = p.xy / uniforms.resolution; let dist = 0.1 * uniforms.intensity * sin(uv.y * 20.0 + uniforms.time * 5.0); return textureSample(txt, smplr, uv + vec2<f32>(dist, 0.0)); })"; @@ -344,6 +357,7 @@ struct Uniforms { beat: f32, intensity: f32, aspect_ratio: f32, + resolution: vec2<f32>, }; @group(0) @binding(2) var<uniform> uniforms: Uniforms; @@ -358,7 +372,7 @@ struct Uniforms { } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - let uv = p.xy / vec2<f32>(1280.0, 720.0); + let uv = p.xy / uniforms.resolution; let off = 0.02 * uniforms.intensity; let r = textureSample(txt, smplr, uv + vec2<f32>(off, 0.0)).r; let g = textureSample(txt, smplr, uv).g; |
