From fe7bb3a34b54da4792b6f9b201a6e2eb2bd4c9ca Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 23 Oct 2026 14:02:12 +0200 Subject: [PATCH] Java packs: the world goes where the pack's terrain program draws MakeUp's gbuffers write colortex1, and its composites read the world from there: with the world in colortex0, it showed nothing but fog. Iris's fallbacks for terrain pick the program (gbuffers_terrain, then textured_lit, textured, basic); its first draw buffer takes the world. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx/java_stages.rs | 29 ++++++++++------ crates/horizon-client/src/java_pack.rs | 6 +++- crates/horizon-shaderpack/src/pipeline.rs | 18 ++++++++++ crates/horizon-shaderpack/tests/pack.rs | 36 ++++++++++++++++++++ 4 files changed, 77 insertions(+), 12 deletions(-) diff --git a/crates/horizon-client/src/gfx/java_stages.rs b/crates/horizon-client/src/gfx/java_stages.rs index f86055919..5079a8f03 100644 --- a/crates/horizon-client/src/gfx/java_stages.rs +++ b/crates/horizon-client/src/gfx/java_stages.rs @@ -2,7 +2,8 @@ //! Iris's colour targets (`colortex0..`, each with a main and an alternate //! side) and the pack's `begin`, `prepare`, `deferred`, `composite` and //! `final` programs as full-screen passes over them, as Iris's -//! `CompositeRenderer` runs them. Horizon's world enters `colortex0` and +//! `CompositeRenderer` runs them. Horizon's world enters the target the +//! pack's terrain program draws to (`colortex0` for most packs) and //! `depthtex0` after `prepare`, where Iris's gbuffers programs would have //! drawn (`depthtex1`/`depthtex2`: its depth before translucent geometry), //! and the last picture goes to `world_post`. The @@ -249,7 +250,8 @@ struct Bound { /// Per pass, then `final`. groups: Vec, world_in: (wgpu::RenderPipeline, wgpu::BindGroup), - /// The world goes to colortex0's alternate side. + /// The world's target, and whether the world goes to its alternate side. + world_target: u32, world_alt: bool, final_target: Option, present: (wgpu::RenderPipeline, wgpu::BindGroup), @@ -262,6 +264,7 @@ struct Bound { struct Folder { targets: Vec, world_at: usize, + world_target: u32, flipped_after_prepare: BTreeSet, flipped_at_end: BTreeSet, passes: Vec, @@ -326,6 +329,7 @@ impl JavaStages { Ok::<_, String>(Folder { targets: plan.targets.clone(), world_at: plan.world_at, + world_target: plan.world_target, flipped_after_prepare: plan.flipped_after_prepare.clone(), flipped_at_end: plan.flipped_at_end.clone(), passes, @@ -486,8 +490,9 @@ impl JavaStages { let folder = &self.folders[folder_index]; let plan = folder; let all = folder.passes.iter().chain(&folder.final_pass); - // Every target a pass reads or writes, and colortex0 (the world). - let mut used: BTreeSet = [0].into(); + // Every target a pass reads or writes, colortex0 (shown without + // `final`) and the world's. + let mut used: BTreeSet = [0, folder.world_target].into(); for pass in all.clone() { used.extend(pass.draw_buffers.iter().copied()); used.extend(pass.samplers.iter().filter_map(|s| match s.source { @@ -588,15 +593,15 @@ impl JavaStages { }) .collect(); - // The world goes into colortex0's side the gbuffers would write. - let colortex0 = &targets[&0]; + // The world goes into its target's side the gbuffers would write. + let world_target = &targets[&folder.world_target]; let world_pipeline = blit_pipeline( device, &self.common, &self.common.world_layout, "world_in", &[ - colortex0.format, + world_target.format, wgpu::TextureFormat::R32Float, wgpu::TextureFormat::R32Float, ], @@ -630,6 +635,7 @@ impl JavaStages { .create_view(&Default::default()) }); // Without `final`, Iris shows colortex0 as the last pass left it. + let colortex0 = &targets[&0]; let shown = final_target.clone().unwrap_or_else(|| { if plan.flipped_at_end.contains(&0) { colortex0.alt_view.clone() @@ -668,7 +674,8 @@ impl JavaStages { opaque_depth, groups, world_in: (world_pipeline, world_group), - world_alt: plan.flipped_after_prepare.contains(&0), + world_target: folder.world_target, + world_alt: plan.flipped_after_prepare.contains(&folder.world_target), final_target, present: (present_pipeline, present_group), output_view, @@ -679,11 +686,11 @@ impl JavaStages { } fn world_in(encoder: &mut wgpu::CommandEncoder, bound: &Bound) { - let colortex0 = &bound.targets[&0]; + let target = &bound.targets[&bound.world_target]; let side = if bound.world_alt { - &colortex0.alt_view + &target.alt_view } else { - &colortex0.main_view + &target.main_view }; let attachments = [ Some(color_attachment(side, None)), diff --git a/crates/horizon-client/src/java_pack.rs b/crates/horizon-client/src/java_pack.rs index 5e592d1b6..ee4d29d61 100644 --- a/crates/horizon-client/src/java_pack.rs +++ b/crates/horizon-client/src/java_pack.rs @@ -23,8 +23,11 @@ pub struct JavaFolder { /// `begin*`, `prepare*`, `deferred*`, `composite*`, in order. pub passes: Vec, /// How many of `passes` run before the world (`begin*`, `prepare*`): the - /// world's colour and depth enter `colortex0` and `depthtex*` after them. + /// world's colour and depth enter `world_target` and `depthtex*` after them. pub world_at: usize, + /// The colour target the world goes into, where the pack's terrain + /// program draws (MakeUp: colortex1). + pub world_target: u32, /// The targets whose alternate side the world is written to. pub flipped_after_prepare: BTreeSet, pub final_pass: Option, @@ -145,6 +148,7 @@ pub fn load( folder: name.to_owned(), targets: plan.targets, world_at: early.count(), + world_target: plan.world_target, passes, flipped_after_prepare: plan.flipped_after_prepare, final_pass, diff --git a/crates/horizon-shaderpack/src/pipeline.rs b/crates/horizon-shaderpack/src/pipeline.rs index 89898eb07..d851fc23a 100644 --- a/crates/horizon-shaderpack/src/pipeline.rs +++ b/crates/horizon-shaderpack/src/pipeline.rs @@ -313,6 +313,10 @@ pub struct Passes { /// The targets gbuffers programs (and Horizon's world) write on their /// alternate side, before and after translucent geometry. pub flipped_after_prepare: BTreeSet, + /// The target Horizon's world goes into: the first one `gbuffers_terrain` + /// (or the program Iris falls back to for terrain) draws to, `colortex0` + /// without one. + pub world_target: u32, pub deferred: Vec, pub flipped_after_translucent: BTreeSet, pub composite: Vec, @@ -532,6 +536,20 @@ impl JavaPack { out.begin = run(&groups[0], "begin_pre", &mut flipped)?; out.prepare = run(&groups[1], "prepare_pre", &mut flipped)?; out.flipped_after_prepare = flipped.clone(); + // Iris's fallbacks for terrain (`ProgramFallbackResolver`). + let terrain = [ + "gbuffers_terrain", + "gbuffers_textured_lit", + "gbuffers_textured", + "gbuffers_basic", + ] + .into_iter() + .find(|name| exists(name)); + if let Some(name) = terrain { + let buffers = + draw_buffers(&fragment(name)?).map_err(|e| format!("{}: {e}", path(name)))?; + out.world_target = buffers.and_then(|b| b.first().copied()).unwrap_or(0); + } out.deferred = run(&groups[2], "deferred_pre", &mut flipped)?; out.flipped_after_translucent = flipped.clone(); out.composite = run(&groups[3], "composite_pre", &mut flipped)?; diff --git a/crates/horizon-shaderpack/tests/pack.rs b/crates/horizon-shaderpack/tests/pack.rs index c957d7fb4..1e2ee8158 100644 --- a/crates/horizon-shaderpack/tests/pack.rs +++ b/crates/horizon-shaderpack/tests/pack.rs @@ -292,6 +292,8 @@ fn plans_the_full_screen_passes() { assert_eq!(passes.composite[0].mipmapped, [3].into()); assert_eq!(passes.composite[1].scale, 0.5); assert_eq!(passes.flipped_after_prepare, [].into()); + // No gbuffers programs: the world goes into colortex0. + assert_eq!(passes.world_target, 0); assert_eq!(passes.flipped_after_translucent, [3].into()); assert_eq!(passes.flipped_at_end, [1, 2, 3].into()); let final_pass = passes.final_pass.unwrap(); @@ -302,6 +304,40 @@ fn plans_the_full_screen_passes() { assert_eq!(final_pass.reads_alt, [1, 2, 3].into()); } +/// The world enters the target terrain draws to first (MakeUp's colortex1), +/// through Iris's fallbacks when `gbuffers_terrain` is missing or disabled. +#[test] +fn the_world_goes_where_terrain_draws() { + let dir = scratch("world-target"); + let shaders = dir.join("shaders"); + std::fs::create_dir_all(&shaders).unwrap(); + let write = |name: &str, text: &str| std::fs::write(shaders.join(name), text).unwrap(); + for program in ["composite", "gbuffers_terrain", "gbuffers_textured"] { + write(&format!("{program}.vsh"), "void main() {}\n"); + } + write("composite.fsh", "void main() {}\n"); + write( + "gbuffers_textured.fsh", + "void main() {\n/* DRAWBUFFERS:12 */\n gl_FragData[0] = vec4(1.0);\n}\n", + ); + write( + "gbuffers_terrain.fsh", + "void main() {\n#ifdef GRASS\n/* DRAWBUFFERS:42 */\n#else\n/* DRAWBUFFERS:3 */\n#endif\n gl_FragData[0] = vec4(1.0);\n}\n", + ); + let target = |properties: &str| { + write("shaders.properties", properties); + let pack = JavaPack::open(&dir).unwrap(); + let values = pack.values(&BTreeMap::new()); + let properties = pack.properties(&values, &env()).unwrap(); + pack.passes("", &values, &env(), &properties) + .unwrap() + .world_target + }; + assert_eq!(target(""), 3); + assert_eq!(target("program.gbuffers_terrain.enabled = false\n"), 1); + std::fs::remove_dir_all(dir).unwrap(); +} + fn scratch(name: &str) -> PathBuf { std::env::temp_dir().join(format!("horizon-shaderpack-{name}-{}", std::process::id())) }