From 54bb3e4fbe869bfc223d0daa2ccf2fa329c721e8 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:19:47 +0100 Subject: [PATCH] Screen effects: one sampler per entry point, so the shader compiles for OpenGL GLSL combines a texture with its sampler, and naga refuses an entry point that reads one texture through two (ImageMultipleSamplers): the BLUR override left both branches in fs_screen and fs_vignette, so creating the screen effect pipelines failed on wgpu's GL backend at startup. Blurred sprites now have their own entry points (fs_screen_blur, fs_vignette_blur); each pipeline still samples once per pixel. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx.rs | 17 +++++++------- crates/horizon-client/src/screen.wgsl | 34 +++++++++++++++++---------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index f2fdfb6b3..b55022510 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -2069,16 +2069,15 @@ impl Renderer { // One per blend and `.png.mcmeta` sampling (screen_effects::SAMPLE_*): // the shader is specialised, so a pixel pays for none of the others. let screen_pipelines: [wgpu::RenderPipeline; 8] = std::array::from_fn(|i| { - let (entry, blend) = if i & 4 == 0 { - ("fs_screen", alpha_blend) - } else { - ("fs_vignette", vignette_blend) + let blur = i as u32 & crate::screen_effects::SAMPLE_BLUR != 0; + let (entry, blend) = match (i & 4 == 0, blur) { + (true, false) => ("fs_screen", alpha_blend), + (true, true) => ("fs_screen_blur", alpha_blend), + (false, false) => ("fs_vignette", vignette_blend), + (false, true) => ("fs_vignette_blur", vignette_blend), }; - let on = |bit: u32| f64::from(u8::from(i as u32 & bit != 0)); - let constants = [ - ("BLUR", on(crate::screen_effects::SAMPLE_BLUR)), - ("CLAMP", on(crate::screen_effects::SAMPLE_CLAMP)), - ]; + let clamp = i as u32 & crate::screen_effects::SAMPLE_CLAMP != 0; + let constants = [("CLAMP", f64::from(u8::from(clamp)))]; let compilation_options = wgpu::PipelineCompilationOptions { constants: &constants, ..Default::default() diff --git a/crates/horizon-client/src/screen.wgsl b/crates/horizon-client/src/screen.wgsl index e70aeb896..1497b36fa 100644 --- a/crates/horizon-client/src/screen.wgsl +++ b/crates/horizon-client/src/screen.wgsl @@ -8,10 +8,12 @@ // atlas, wrapped as repeat reads it (hud.rs), so the hardware's bilinear // sample is GL_LINEAR with repeat; clamp-to-edge keeps the sample point half // a texel inside. Each sampling has its own pipeline (gfx.rs), so a pixel -// costs what it did with nearest and repeat only: one sample. +// costs what it did with nearest and repeat only: one sample. Each entry +// point reads `atlas` through one sampler only: GLSL (wgpu's OpenGL backend) +// combines a texture with its sampler, and an override would not remove the +// other sampler's branch. @group(0) @binding(2) var nearest_sampler: sampler; @group(0) @binding(4) var linear_sampler: sampler; -override BLUR: bool = false; override CLAMP: bool = false; struct Out { @builtin(position) clip: vec4, @@ -32,28 +34,36 @@ struct Out { out.edges = vec4(rect.xy + half, rect.zw - half); return out; } -fn sample(in: Out) -> vec4 { +// The sprite's atlas coordinates of this pixel. +fn atlas_uv(in: Out) -> vec2 { var f = in.uv; if !CLAMP { // Repeat: one period of the sprite. f = fract(f); } - var uv = in.rect.xy + f * (in.rect.zw - in.rect.xy); + let uv = in.rect.xy + f * (in.rect.zw - in.rect.xy); if CLAMP { - uv = clamp(uv, in.edges.xy, in.edges.zw); + return clamp(uv, in.edges.xy, in.edges.zw); } - if BLUR { - return textureSampleLevel(atlas, linear_sampler, uv, 0.0) * in.color; - } - return textureSampleLevel(atlas, nearest_sampler, uv, 0.0) * in.color; + return uv; } -@fragment fn fs_screen(in: Out) -> @location(0) vec4 { - let c = sample(in); +fn screen(c: vec4) -> vec4 { if c.a <= 0.0 { discard; } return c; } +@fragment fn fs_screen(in: Out) -> @location(0) vec4 { + return screen(textureSampleLevel(atlas, nearest_sampler, atlas_uv(in), 0.0) * in.color); +} +@fragment fn fs_screen_blur(in: Out) -> @location(0) vec4 { + return screen(textureSampleLevel(atlas, linear_sampler, atlas_uv(in), 0.0) * in.color); +} // RenderPipelines.VIGNETTE blends ZERO, ONE_MINUS_SRC_COLOR: output the // texture colour; the blend state darkens the frame by it. @fragment fn fs_vignette(in: Out) -> @location(0) vec4 { - return vec4(sample(in).rgb, 1.0); + let c = textureSampleLevel(atlas, nearest_sampler, atlas_uv(in), 0.0) * in.color; + return vec4(c.rgb, 1.0); +} +@fragment fn fs_vignette_blur(in: Out) -> @location(0) vec4 { + let c = textureSampleLevel(atlas, linear_sampler, atlas_uv(in), 0.0) * in.color; + return vec4(c.rgb, 1.0); }