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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 14:02:12 +02:00
parent eafe97da74
commit fe7bb3a34b
4 changed files with 77 additions and 12 deletions
+18 -11
View File
@@ -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<wgpu::BindGroup>,
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<wgpu::TextureView>,
present: (wgpu::RenderPipeline, wgpu::BindGroup),
@@ -262,6 +264,7 @@ struct Bound {
struct Folder {
targets: Vec<TargetSettings>,
world_at: usize,
world_target: u32,
flipped_after_prepare: BTreeSet<u32>,
flipped_at_end: BTreeSet<u32>,
passes: Vec<PassGpu>,
@@ -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<u32> = [0].into();
// Every target a pass reads or writes, colortex0 (shown without
// `final`) and the world's.
let mut used: BTreeSet<u32> = [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)),
+5 -1
View File
@@ -23,8 +23,11 @@ pub struct JavaFolder {
/// `begin*`, `prepare*`, `deferred*`, `composite*`, in order.
pub passes: Vec<Program>,
/// 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<u32>,
pub final_pass: Option<Program>,
@@ -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,
+18
View File
@@ -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<u32>,
/// 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<Pass>,
pub flipped_after_translucent: BTreeSet<u32>,
pub composite: Vec<Pass>,
@@ -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)?;
+36
View File
@@ -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()))
}