From 3e2c30a852452a3ee0a4cf778d85aee55b98c205 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 02:47:14 +0100 Subject: [PATCH] Shader packs, clean room 18: translucent terrain drawn by the pack With a pack whose gbuffers_water (or a fallback down gbuffers_terrain's chain) loads, translucent terrain (water, stained glass) is drawn by it after the deferred programs and before the composites, in place, sorted back to front as the game sorts it, and Horizon's own translucent terrain draw is skipped. - blend. (off, or four GL factors); translucent terrain defaults to SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE ONE_MINUS_SRC_ALPHA, and only blendable buffer formats blend. - depthtex1/depthtex2: depth without translucent terrain, a copy taken just before it when a later program reads them (before it, depthtex0 itself). The hand is drawn after the pack, so depthtex2 = depthtex1. Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1, sections 2.1, 2.3, 3.2 (blend), 6.2 (depthtex1/2); no other loader's code read. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx.rs | 26 ++- crates/horizon-client/src/gfx/pack_post.rs | 213 +++++++++++++++++---- crates/horizon-shaders/src/lib.rs | 4 +- crates/horizon-shaders/src/post.rs | 130 ++++++++++++- crates/horizon-shaders/tests/real_packs.rs | 3 +- 5 files changed, 327 insertions(+), 49 deletions(-) diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index a33d54fa3..9a7356d6e 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -3709,6 +3709,12 @@ impl Renderer { let pack_post = !frame.title && self.pack_post.as_ref().is_some_and(|p| p.1.is_some()); // The pack's program reads the vertices this frame's draws bind. let pack_draws_terrain = pack_terrain && flat_frame == self.pack_terrain_flat; + let pack_draws_water = pack_draws_terrain + && self + .pack_post + .as_ref() + .and_then(|p| p.1.as_ref()) + .is_some_and(|p| p.has_water()); let scaled = self.world_post.prepare( &self.device, [self.config.width, self.config.height], @@ -3940,6 +3946,8 @@ impl Renderer { pass.draw(0..4, debug_depth..debug_depth + debug_top); } match self.flat.as_ref().filter(|_| flat_frame) { + // The pack draws translucent terrain after its deferred programs. + _ if pack_draws_water => {} Some(flat) => { pass.set_pipeline(&flat.translucent); flat.draw(&mut pass, &flat.calls[flat.solid_calls..], |p| { @@ -4016,20 +4024,28 @@ impl Renderer { { let size = self.world_post.size().unwrap_or([1, 1]); let flat = self.flat.as_ref().filter(|_| flat_frame); - let mut terrain = |rp: &mut wgpu::RenderPass<'_>| { + let mut terrain = |rp: &mut wgpu::RenderPass<'_>, translucent: bool| { if !pack_draws_terrain { return; } match flat { Some(flat) => { - flat.draw(rp, &flat.calls[..flat.solid_calls], |p| { - self.arena.buffer(p) - }); + let calls = if translucent { + &flat.calls[flat.solid_calls..] + } else { + &flat.calls[..flat.solid_calls] + }; + flat.draw(rp, calls, |p| self.arena.buffer(p)); } None => { rp.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32); rp.set_vertex_buffer(1, self.instances.slice(..)); - self.draw_sections(rp, &self.indirect, 0, 0, solid_draws); + let (first, count) = if translucent { + (solid_draws, translucent_draws) + } else { + (0, solid_draws) + }; + self.draw_sections(rp, &self.indirect, 0, first, count); } } }; diff --git a/crates/horizon-client/src/gfx/pack_post.rs b/crates/horizon-client/src/gfx/pack_post.rs index 0201c7976..b96da2599 100644 --- a/crates/horizon-client/src/gfx/pack_post.rs +++ b/crates/horizon-client/src/gfx/pack_post.rs @@ -24,6 +24,8 @@ const BUFFERS: usize = horizon_shaders::BUFFERS; enum Source { Color(usize), Depth, + /// `depthtex1`/`depthtex2`: depth without translucent terrain (a copy taken before it). + Depth1, Noise, /// A 1×1 stand-in for names this slice does not provide yet (custom textures...). Dummy, @@ -58,7 +60,7 @@ impl SamplerKind { fn of(source: Source, filtering: bool) -> Self { match source { Source::Color(_) | Source::Dummy if !filtering => Self::Nearest, - Source::Depth => Self::Nearest, + Source::Depth | Source::Depth1 => Self::Nearest, Source::Noise => Self::Repeat, Source::Shadow => Self::Comparison, // Blocks look as the game draws them: nearest texels. @@ -143,6 +145,9 @@ struct Targets { /// A and B of each buffer used. color: [Option<[wgpu::TextureView; 2]>; BUFFERS], depth: wgpu::TextureView, + depth_texture: wgpu::Texture, + /// `depthtex1`, when a program after translucent terrain reads it. + depth1: Option<(wgpu::Texture, wgpu::TextureView)>, } /// What a pack's gbuffers programs read and draw from the game's world. @@ -159,6 +164,10 @@ pub struct PackPost { passes: Vec, /// What draws terrain (`gbuffers_terrain` or its fallback), between `prepare` and `deferred`. terrain: Option, + /// What draws translucent terrain (`gbuffers_water` or its fallback), after `deferred`. + water: Option, + /// A program after translucent terrain reads `depthtex1`: it is copied before water. + depth1: bool, /// `shaders.properties`' custom uniforms, after the frame's in `uniforms.values`. custom: horizon_shaders::Custom, atlas: Option, @@ -231,7 +240,9 @@ fn texture_format(f: Format, features: wgpu::Features) -> wgpu::TextureFormat { fn source(name: &str) -> Source { match name { - "depthtex0" | "gdepthtex" | "depthtex1" | "depthtex2" => Source::Depth, + "depthtex0" | "gdepthtex" => Source::Depth, + // The hand is drawn after the pack, so `depthtex2` (without it) is `depthtex1`. + "depthtex1" | "depthtex2" => Source::Depth1, "noisetex" => Source::Noise, "texture" | "gtexture" | "tex" => Source::Atlas, "lightmap" => Source::Lightmap, @@ -392,6 +403,34 @@ fn texture_entry(binding: u32, sample_type: wgpu::TextureSampleType) -> wgpu::Bi ) } +/// `blend.`'s factors as wgpu's, adding both terms. +fn blend_state(b: horizon_shaders::Blend) -> wgpu::BlendState { + use horizon_shaders::Factor as F; + use wgpu::BlendFactor as W; + let f = |f| match f { + F::Zero => W::Zero, + F::One => W::One, + F::SrcColor => W::Src, + F::OneMinusSrcColor => W::OneMinusSrc, + F::DstColor => W::Dst, + F::OneMinusDstColor => W::OneMinusDst, + F::SrcAlpha => W::SrcAlpha, + F::OneMinusSrcAlpha => W::OneMinusSrcAlpha, + F::DstAlpha => W::DstAlpha, + F::OneMinusDstAlpha => W::OneMinusDstAlpha, + F::SrcAlphaSaturate => W::SrcAlphaSaturated, + }; + let component = |src, dst| wgpu::BlendComponent { + src_factor: f(src), + dst_factor: f(dst), + operation: wgpu::BlendOperation::Add, + }; + wgpu::BlendState { + color: component(b[0], b[1]), + alpha: component(b[2], b[3]), + } +} + fn target(format: wgpu::TextureFormat) -> Option { Some(wgpu::ColorTargetState { format, @@ -462,6 +501,8 @@ fn build_pass( let blank = match src { Source::Atlas => geometry.is_none(), Source::Depth => geometry.is_some(), + // Translucent terrain reads the copy; opaque terrain would read itself. + Source::Depth1 => p.group == Group::Gbuffers, Source::Color(n) => in_place & 1 << n != 0, _ => false, }; @@ -470,7 +511,7 @@ fn build_pass( Source::Color(n) => formats[n] .sample_type(None, Some(features)) .unwrap_or(float), - Source::Depth => wgpu::TextureSampleType::Float { filterable: false }, + Source::Depth | Source::Depth1 => wgpu::TextureSampleType::Float { filterable: false }, // Unfilterable on WebGPU-level devices; the lightmap is sampled at texel centres. Source::Lightmap => float, _ => float, @@ -534,7 +575,17 @@ fn build_pass( targets[0] = target(screen); } } else if let Some(&buffer) = p.buffers.get(l) { - targets[l] = target(formats[buffer as usize]); + let format = formats[buffer as usize]; + let mut state = target(format); + if let (Some(t), Some(b)) = (&mut state, p.blend) + && format + .guaranteed_format_features(features) + .flags + .contains(wgpu::TextureFormatFeatureFlags::BLENDABLE) + { + t.blend = Some(blend_state(b)); + } + targets[l] = state; writes.push((location, buffer as usize)); } } @@ -693,6 +744,10 @@ impl PackPost { .terrain .zip(world.terrain.as_ref()) .and_then(|(p, g)| build(p, Some(g))); + let water = post + .water + .zip(world.terrain.as_ref()) + .and_then(|(p, g)| build(p, Some(g))); // Developers' aid: `HORIZON_SHADER_PACK_SKIP=composite,final` leaves programs out. let skip = std::env::var("HORIZON_SHADER_PACK_SKIP").unwrap_or_default(); let passes: Vec = post @@ -704,25 +759,43 @@ impl PackPost { if let Some(t) = &terrain { notes.push(format!("terrain draws with {}", t.name)); } + if let Some(w) = &water { + notes.push(format!("translucent terrain draws with {}", w.name)); + } + let depth1 = water.is_some() + && passes + .iter() + .filter(|p| matches!(p.group, Group::Composite | Group::Final)) + .chain(&water) + .any(|p| p.samplers.iter().any(|s| s.source == Source::Depth1)); // A clear only matters when a program reads the buffer before one writes all of it // (composite passes cover their whole target, terrain does not); the others are skipped. let mut cleared = Vec::new(); for b in 1..BUFFERS { let bit = 1u16 << b; let touched = |p: &&Pass| (p.reads | p.flip | p.written) & bit != 0; - let first = terrain.iter().find(touched).map(|_| true).or_else(|| { - let p = passes.iter().find(touched)?; - Some(p.reads & bit != 0 || p.written & bit == 0) - }); + // Gbuffers passes cover part of their targets: a clear is needed if they touch it. + let first = terrain + .iter() + .chain(&water) + .find(touched) + .map(|_| true) + .or_else(|| { + let p = passes.iter().find(touched)?; + Some(p.reads & bit != 0 || p.written & bit == 0) + }); if clears[b].is_some() && first == Some(true) { cleared.push(b); } } // Terrain tests against the world's depth (entities...), so the blit copies it then. let blit_depth = terrain.is_some() - || passes - .iter() - .any(|p| p.samplers.iter().any(|s| s.source == Source::Depth)); + || water.is_some() + || passes.iter().any(|p| { + p.samplers + .iter() + .any(|s| matches!(s.source, Source::Depth | Source::Depth1)) + }); let room = 8 - 1; let other_clears = cleared.split_off(room.min(cleared.len())); let float = wgpu::TextureSampleType::Float { filterable: true }; @@ -778,6 +851,8 @@ impl PackPost { notes, passes, terrain, + water, + depth1, custom, atlas: world.atlas.as_ref().map(|a| a.0.clone()), lightmap: world.lightmap, @@ -886,6 +961,18 @@ impl PackPost { .as_ref() .map_or(&self.dummy, |t| &t[usize::from(key & 1 << i != 0)]), Source::Depth => &targets.depth, + // Before translucent terrain the two are the same. + Source::Depth1 => match &targets.depth1 { + Some(d) + if matches!( + pass.group, + Group::Composite | Group::Final | Group::Translucent + ) => + { + &d.1 + } + _ => &targets.depth, + }, Source::Noise => &self.noise, Source::Dummy => &self.dummy, Source::Shadow => &self.shadow.0, @@ -919,19 +1006,36 @@ impl PackPost { group.clone() } - /// Terrain with the pack's program into the buffers it writes, in place, tested against - /// the world's depth; `draw` issues the game's draws. + /// Terrain (or, `translucent`, translucent terrain) with the pack's program into the + /// buffers it writes, in place, tested against the world's depth; `draw` issues the + /// game's draws. fn draw_terrain( &mut self, device: &wgpu::Device, queue: &wgpu::Queue, encoder: &mut wgpu::CommandEncoder, size: [u32; 2], - draw: &mut dyn FnMut(&mut wgpu::RenderPass<'_>), + translucent: bool, + draw: &mut dyn FnMut(&mut wgpu::RenderPass<'_>, bool), ) { - let Some(mut pass) = self.terrain.take() else { + let slot = if translucent { + &mut self.water + } else { + &mut self.terrain + }; + let Some(mut pass) = slot.take() else { return; }; + if translucent + && let Some(t) = &self.targets + && let Some((copy, _)) = &t.depth1 + { + encoder.copy_texture_to_texture( + t.depth_texture.as_image_copy(), + copy.as_image_copy(), + t.depth_texture.size(), + ); + } let group = self.bind(device, queue, &mut pass, size); let targets = self.targets.as_ref().expect("resized"); let load = wgpu::Operations { @@ -964,9 +1068,13 @@ impl PackPost { }); rp.set_pipeline(&pass.pipeline); rp.set_bind_group(0, &group, &[]); - draw(&mut rp); + draw(&mut rp, translucent); + } + if translucent { + self.water = Some(pass); + } else { + self.terrain = Some(pass); } - self.terrain = Some(pass); } /// Whether the pack draws terrain itself. @@ -974,6 +1082,11 @@ impl PackPost { self.terrain.is_some() } + /// Whether the pack draws translucent terrain itself. + pub fn has_water(&self) -> bool { + self.water.is_some() + } + /// The names of the programs that run, in order. pub fn programs(&self) -> Vec<&str> { self.passes.iter().map(|p| p.name.as_str()).collect() @@ -983,23 +1096,24 @@ impl PackPost { if self.targets.as_ref().is_some_and(|t| t.size == size) { return; } + let texture = |label: &str, format, usage| { + device.create_texture(&wgpu::TextureDescriptor { + label: Some(label), + size: wgpu::Extent3d { + width: size[0], + height: size[1], + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format, + usage: usage | wgpu::TextureUsages::TEXTURE_BINDING, + view_formats: &[], + }) + }; let make = |label: &str, format| { - device - .create_texture(&wgpu::TextureDescriptor { - label: Some(label), - size: wgpu::Extent3d { - width: size[0], - height: size[1], - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT - | wgpu::TextureUsages::TEXTURE_BINDING, - view_formats: &[], - }) + texture(label, format, wgpu::TextureUsages::RENDER_ATTACHMENT) .create_view(&Default::default()) }; let color = std::array::from_fn(|i| { @@ -1008,12 +1122,26 @@ impl PackPost { [make(&label, self.formats[i]), make(&label, self.formats[i])] }) }); + let depth32 = wgpu::TextureFormat::Depth32Float; + let depth_texture = texture( + "depthtex0", + depth32, + wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, + ); + let depth1 = self.depth1.then(|| { + let t = texture("depthtex1", depth32, wgpu::TextureUsages::COPY_DST); + let view = t.create_view(&Default::default()); + (t, view) + }); self.targets = Some(Targets { size, color, - depth: make("depthtex0", wgpu::TextureFormat::Depth32Float), + depth: depth_texture.create_view(&Default::default()), + depth_texture, + depth1, }); - for pass in self.passes.iter_mut().chain(&mut self.terrain) { + let gbuffers = self.terrain.iter_mut().chain(&mut self.water); + for pass in self.passes.iter_mut().chain(gbuffers) { pass.groups.clear(); } } @@ -1033,7 +1161,7 @@ impl PackPost { inputs: &PackInputs, size: [u32; 2], window: [u32; 2], - terrain: &mut dyn FnMut(&mut wgpu::RenderPass<'_>), + terrain: &mut dyn FnMut(&mut wgpu::RenderPass<'_>, bool), ) { self.resize(device, size); self.uniforms.update(frame, inputs, size); @@ -1143,10 +1271,15 @@ impl PackPost { let mut seen = (false, false); let mut shown = false; let mut terrain_drawn = self.terrain.is_none(); + let mut water_drawn = self.water.is_none(); for pass in &mut passes { if !terrain_drawn && pass.group != Group::Prepare { terrain_drawn = true; - self.draw_terrain(device, queue, encoder, size, terrain); + self.draw_terrain(device, queue, encoder, size, false, terrain); + } + if !water_drawn && matches!(pass.group, Group::Composite | Group::Final) { + water_drawn = true; + self.draw_terrain(device, queue, encoder, size, true, terrain); } if pass.group == Group::Deferred && !seen.0 { seen.0 = true; @@ -1191,7 +1324,10 @@ impl PackPost { } self.passes = passes; if !terrain_drawn { - self.draw_terrain(device, queue, encoder, size, terrain); + self.draw_terrain(device, queue, encoder, size, false, terrain); + } + if !water_drawn { + self.draw_terrain(device, queue, encoder, size, true, terrain); } let targets = self.targets.as_ref().expect("resized"); let view = |m: u16, i: usize, alt: bool| { @@ -1282,6 +1418,7 @@ mod tests { fn sampler_names() { assert!(source("gaux1") == Source::Color(4)); assert!(source("gdepthtex") == Source::Depth); + assert!(source("depthtex2") == Source::Depth1); assert!(source("noisetex") == Source::Noise); assert!(source("shadowcolor0") == Source::Dummy); } diff --git a/crates/horizon-shaders/src/lib.rs b/crates/horizon-shaders/src/lib.rs index 47cbcca11..f5819d435 100644 --- a/crates/horizon-shaders/src/lib.rs +++ b/crates/horizon-shaders/src/lib.rs @@ -33,7 +33,9 @@ pub use lang::Lang; pub use macros::{MC_VERSION, Macros, RENDER_STAGES}; pub use options::switches_on; pub use pack::{Pack, PackError}; -pub use post::{Group, Post, PostProgram, dimension_folder, load_post}; +pub use post::{ + Blend, Factor, Group, Post, PostProgram, TRANSLUCENT_BLEND, dimension_folder, load_post, +}; pub use preprocess::{Diagnostic, Origin, Preprocessed, preprocess}; pub use properties::{Entry, Note, Properties}; pub use translate::{ diff --git a/crates/horizon-shaders/src/post.rs b/crates/horizon-shaders/src/post.rs index d6142c70a..e50eb4797 100644 --- a/crates/horizon-shaders/src/post.rs +++ b/crates/horizon-shaders/src/post.rs @@ -24,10 +24,67 @@ pub enum Group { Deferred, Composite, Final, - /// A gbuffers program: the game draws its geometry with it. + /// A gbuffers program: the game draws its geometry with it, before deferred. Gbuffers, + /// A gbuffers program drawing translucent geometry, after deferred (2.1). + Translucent, } +/// A blend factor of `blend.` (3.2), as GL names it. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Factor { + Zero, + One, + SrcColor, + OneMinusSrcColor, + DstColor, + OneMinusDstColor, + SrcAlpha, + OneMinusSrcAlpha, + DstAlpha, + OneMinusDstAlpha, + SrcAlphaSaturate, +} + +impl Factor { + fn parse(word: &str) -> Option { + Some(match word { + "ZERO" => Self::Zero, + "ONE" => Self::One, + "SRC_COLOR" => Self::SrcColor, + "ONE_MINUS_SRC_COLOR" => Self::OneMinusSrcColor, + "DST_COLOR" => Self::DstColor, + "ONE_MINUS_DST_COLOR" => Self::OneMinusDstColor, + "SRC_ALPHA" => Self::SrcAlpha, + "ONE_MINUS_SRC_ALPHA" => Self::OneMinusSrcAlpha, + "DST_ALPHA" => Self::DstAlpha, + "ONE_MINUS_DST_ALPHA" => Self::OneMinusDstAlpha, + "SRC_ALPHA_SATURATE" => Self::SrcAlphaSaturate, + _ => return None, + }) + } +} + +/// Source and destination factors for colour, then for alpha. +pub type Blend = [Factor; 4]; + +/// The default blend of translucent geometry (3.2). +pub const TRANSLUCENT_BLEND: Blend = [ + Factor::SrcAlpha, + Factor::OneMinusSrcAlpha, + Factor::One, + Factor::OneMinusSrcAlpha, +]; + +/// `gbuffers_water` and its fallbacks (2.3). +const WATER: [&str; 5] = [ + "gbuffers_water", + "gbuffers_terrain", + "gbuffers_textured_lit", + "gbuffers_textured", + "gbuffers_basic", +]; + /// `gbuffers_terrain` and its fallbacks (2.3). const TERRAIN: [&str; 4] = [ "gbuffers_terrain", @@ -52,6 +109,8 @@ pub struct PostProgram { pub buffers: Vec, /// `flip..`: buffers forced to flip (true) or kept (false) after this program. pub flips: Vec<(u32, bool)>, + /// How a gbuffers program's output blends into its buffers; `None` writes them. + pub blend: Option, } pub struct Post { @@ -63,6 +122,8 @@ pub struct Post { pub composite_pre: Vec<(u32, bool)>, /// What draws solid and cutout terrain, when the game asked for it and one loads. pub terrain: Option, + /// What draws translucent terrain (water, stained glass) after deferred. + pub water: Option, /// The custom uniforms of `shaders.properties` (3.4). pub custom: Custom, pub config: Config, @@ -96,6 +157,7 @@ pub fn load_post( deferred_pre: flips(properties, "deferred_pre"), composite_pre: flips(properties, "composite_pre"), terrain: None, + water: None, custom: Custom::parse(properties), config: Config::default(), notes: Vec::new(), @@ -127,11 +189,24 @@ pub fn load_post( } } if let Some(inputs) = terrain { - loader.post.terrain = TERRAIN.iter().find_map(|name| { - loader.load(name.to_string(), Group::Gbuffers, |v, f| { - translate_gbuffers(v, f, Target::Buffers, inputs) + let mut gbuffers = |names: &[&str], group| { + names.iter().find_map(|name| { + loader.load(name.to_string(), group, |v, f| { + translate_gbuffers(v, f, Target::Buffers, inputs) + }) }) + }; + let terrain = gbuffers(&TERRAIN, Group::Gbuffers); + // gbuffers_water falls back to gbuffers_terrain's chain (2.3). + let water = gbuffers(&WATER, Group::Translucent); + loader.post.terrain = terrain; + loader.post.water = water.map(|mut p| { + p.blend = blend(properties, &p.name).unwrap_or(Some(TRANSLUCENT_BLEND)); + p }); + if let Some(p) = &mut loader.post.terrain { + p.blend = blend(properties, &p.name).flatten(); + } } post.config = std::mem::take(&mut post.config).finish(); post @@ -211,6 +286,7 @@ impl Loader<'_> { group, program, buffers, + blend: None, }) } } @@ -260,6 +336,20 @@ fn enabled( eval_condition(&condition, macros).ok() != Some(0) } +/// `blend.`: `Some(None)` for `off`, `Some(factors)`, or `None` when absent or not +/// four known factors. +fn blend(properties: &Properties, program: &str) -> Option> { + let value = properties.get(&format!("blend.{program}"))?.trim(); + if value == "off" { + return Some(None); + } + let factors: Vec = value + .split_whitespace() + .map(Factor::parse) + .collect::>()?; + Some(Some(factors.try_into().ok()?)) +} + /// `flip..=` keys of one program. fn flips(properties: &Properties, program: &str) -> Vec<(u32, bool)> { let prefix = format!("flip.{program}."); @@ -355,6 +445,38 @@ mod tests { assert!(post.programs.iter().any(|p| p.name == "composite3")); } + /// Water falls back to the terrain chain and blends by default; `blend.*` overrides. + #[test] + fn water_falls_back_to_terrain_and_blends() { + let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/packs/terrain-test"); + let pack = Pack::open(&dir).unwrap(); + let macros = Macros::standard(); + let inputs = crate::GbuffersInputs { + declarations: "layout(location = 0) in vec3 hz_v_pos;".into(), + body: " hz_Vertex = vec4(hz_v_pos, 1.0);\n hz_Color = vec4(1.0);\n".into(), + attributes: Vec::new(), + }; + let post = load_post(&pack, "", &Properties::default(), ¯os, Some(&inputs)); + let (terrain, water) = (post.terrain.unwrap(), post.water.unwrap()); + assert_eq!((terrain.group, terrain.blend), (Group::Gbuffers, None)); + assert_eq!(water.name, "gbuffers_terrain"); + assert_eq!( + (water.group, water.blend), + (Group::Translucent, Some(TRANSLUCENT_BLEND)) + ); + let properties = Properties::parse( + "blend.gbuffers_terrain = ONE ONE ZERO ONE\nblend.gbuffers_water = off\n", + ¯os, + ); + let terrain_blend = blend(&properties, "gbuffers_terrain"); + assert_eq!( + terrain_blend, + Some(Some([Factor::One, Factor::One, Factor::Zero, Factor::One])) + ); + assert_eq!(blend(&properties, "gbuffers_water"), Some(None)); + assert_eq!(blend(&properties, "gbuffers_basic"), None); + } + #[test] fn horizons_test_pack_loads() { let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/packs/post-test"); diff --git a/crates/horizon-shaders/tests/real_packs.rs b/crates/horizon-shaders/tests/real_packs.rs index 78ba97bfb..c5d4defac 100644 --- a/crates/horizon-shaders/tests/real_packs.rs +++ b/crates/horizon-shaders/tests/real_packs.rs @@ -176,9 +176,10 @@ fn real_packs_read() { Some(&terrain), ); println!( - " dimension {id} (folder `{folder}`): {} post programs, terrain {:?}, {} notes, {:.0} ms", + " dimension {id} (folder `{folder}`): {} post programs, terrain {:?}, water {:?}, {} notes, {:.0} ms", post.programs.len(), post.terrain.as_ref().map(|t| &t.name), + post.water.as_ref().map(|t| &t.name), post.notes.len() + post.config.notes.len(), start.elapsed().as_secs_f64() * 1000.0 );