From be378bb77361b611b9451f76033daf97e0c8d75e Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:44:32 +0100 Subject: [PATCH] Particles: vault connections are translucent, shadows keep their range - FlyTowardsPositionParticle puts vault_connection on the translucent layer: its LifetimeAlpha(0, 0.6, 0.25, 1) is not opaque. - The shadow draw started at world_quads - shadow_quads; with the new bucket after it, that drew translucent particles with the shadow pipeline and dropped as many shadows. - One atlas lookup per named-sprite particle and frame: the engine keeps each sprite's layer beside its rect instead of hashing the name twice. Co-Authored-By: Claude Opus 5.5 --- .../examples/probe/marker_particles_probe.rs | 2 +- .../probe/particle_providers_probe.rs | 2 +- crates/horizon-client/src/game.rs | 2 +- crates/horizon-client/src/gfx.rs | 2 +- crates/horizon-client/src/particles.rs | 45 ++++++++++--------- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/crates/horizon-client/examples/probe/marker_particles_probe.rs b/crates/horizon-client/examples/probe/marker_particles_probe.rs index 6b05af356..72ebaff22 100644 --- a/crates/horizon-client/examples/probe/marker_particles_probe.rs +++ b/crates/horizon-client/examples/probe/marker_particles_probe.rs @@ -49,7 +49,7 @@ pub fn main() -> Result<()> { } } } - let mut engine = ParticleEngine::new(root, &HashMap::new(), Default::default()); + let mut engine = ParticleEngine::new(root, &HashMap::new(), &Default::default()); let mut out = BufWriter::new(File::create(&args[2])?); for line in BufReader::new(File::open(&args[1])?).lines() { let case: Value = serde_json::from_str(&line?)?; diff --git a/crates/horizon-client/examples/probe/particle_providers_probe.rs b/crates/horizon-client/examples/probe/particle_providers_probe.rs index 067648e95..68f23f3af 100644 --- a/crates/horizon-client/examples/probe/particle_providers_probe.rs +++ b/crates/horizon-client/examples/probe/particle_providers_probe.rs @@ -152,7 +152,7 @@ pub fn main() -> Result<()> { world(&assets, &facts, false, true)?, world(&assets, &facts, true, true)?, ]; - let mut engine = ParticleEngine::new(root, &HashMap::new(), Default::default()); + let mut engine = ParticleEngine::new(root, &HashMap::new(), &Default::default()); for (ty, item) in [ (ParticleType::ItemSlime, "item_slime_ball"), (ParticleType::ItemSnowball, "item_snowball"), diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index cfb3ad433..f6b1bf828 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -11693,7 +11693,7 @@ impl<'a> Game<'a> { let particles = horizon_client::particles::ParticleEngine::new( &root, &gui.atlas.sprites, - gui.atlas.translucent.clone(), + &gui.atlas.translucent, ); Ok(Game { res: res.clone(), diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 6af750b62..f8cd8acd8 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -3761,7 +3761,7 @@ impl Renderer { pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); pass.draw_indexed( 0..shadow_quads * 6, - ((world_quads - shadow_quads) * 4) as i32, + ((world_quads - translucent_particle_quads - shadow_quads) * 4) as i32, 0..1, ); pass.set_bind_group(0, &self.group, &[]); diff --git a/crates/horizon-client/src/particles.rs b/crates/horizon-client/src/particles.rs index 62127808a..be7f32551 100644 --- a/crates/horizon-client/src/particles.rs +++ b/crates/horizon-client/src/particles.rs @@ -222,7 +222,9 @@ impl ParticleType { // SimpleAnimatedParticle and its subclasses: EndRodParticle, // SparkParticle (firework), SquidInkParticle, TotemParticle. | Self::EndRod | Self::Firework | Self::SquidInk | Self::GlowSquidInk - | Self::TotemOfUndying => true, + | Self::TotemOfUndying + // FlyTowardsPositionParticle: its LifetimeAlpha(0, 0.6, 0.25, 1) is not opaque. + | Self::VaultConnection => true, _ => false, } } @@ -1177,10 +1179,9 @@ pub struct ParticleEngine { pub requested: Option>, names: Vec, rects: Vec>, - atlas: HashMap, - /// `SingleQuadParticle.Layer.bySprite`: named sprites whose texels include - /// 0 < alpha < 255 render on vanilla's translucent particle layer. - translucent: HashSet, + /// Each named sprite, and whether `SingleQuadParticle.Layer.bySprite` puts + /// it on the translucent layer (a texel with 0 < alpha < 255). + atlas: HashMap, sets: HashMap, set_sprites: Vec>, /// `TrackingEmitter`s: particle type, entity feet position, width, height, ticks left. @@ -1200,7 +1201,7 @@ pub struct ParticleEngine { /// `ParticleGroup.MAX_PARTICLES` (per render group; one group here). const MAX_PARTICLES: usize = 16384; impl ParticleEngine { - pub fn new(root: &Path, atlas: &HashMap, translucent: HashSet) -> Self { + pub fn new(root: &Path, atlas: &HashMap, translucent: &HashSet) -> Self { let mut engine = Self { particles: Vec::new(), pending: Vec::new(), @@ -1211,8 +1212,10 @@ impl ParticleEngine { requested: None, names: Vec::new(), rects: Vec::new(), - atlas: atlas.clone(), - translucent, + atlas: atlas + .iter() + .map(|(name, &rect)| (name.clone(), (rect, translucent.contains(name)))) + .collect(), sets: HashMap::new(), set_sprites: Vec::new(), emitters: Vec::new(), @@ -1254,7 +1257,7 @@ impl ParticleEngine { return i as u32; } self.names.push(name.to_owned()); - self.rects.push(self.atlas.get(name).copied()); + self.rects.push(self.atlas.get(name).map(|&(rect, _)| rect)); (self.names.len() - 1) as u32 } pub fn len(&self) -> usize { @@ -3794,18 +3797,20 @@ impl ParticleEngine { { continue; } - let rect = match &p.sprite { - Sprite::Index(i) => self.rects.get(*i as usize).copied().flatten(), - Sprite::Named(name) => self.atlas.get(name).copied(), - }; - let Some(r) = rect else { continue }; // `SubmitNodeCollection.submitQuadParticleGroup`: the translucent // layer draws after translucent terrain, so a crumb of stained // glass cannot hide the glass behind it (`getLayer`). - let layer = match &p.sprite { - Sprite::Index(_) => p.ty.translucent_layer(), - Sprite::Named(name) => self.translucent.contains(name), + let (rect, layer) = match &p.sprite { + Sprite::Index(i) => ( + self.rects.get(*i as usize).copied().flatten(), + p.ty.translucent_layer(), + ), + Sprite::Named(name) => match self.atlas.get(name) { + Some(&(rect, translucent)) => (Some(rect), translucent), + None => (None, false), + }, }; + let Some(r) = rect else { continue }; let a = f64::from(partial); let pos = DVec3::new( p.previous[0] + (p.position[0] - p.previous[0]) * a, @@ -3936,7 +3941,7 @@ mod tests { #[test] fn egg_teleport_unpacks_offsets_and_preserves_seeded_draw_order() { - let mut engine = ParticleEngine::new(Path::new(""), &HashMap::new(), HashSet::new()); + let mut engine = ParticleEngine::new(Path::new(""), &HashMap::new(), &HashSet::new()); engine.seed_randoms(0, 0, 0); // Destination offset (-15, 7, 15); the unused top byte is ignored. engine.block_teleportation([4, 12, -5], 0xff01_0f1fu32 as i32, [16, 8, 16], 0); @@ -3961,7 +3966,7 @@ mod tests { #[test] fn consume_teleport_unpacks_offsets_within_127() { - let mut engine = ParticleEngine::new(Path::new(""), &HashMap::new(), HashSet::new()); + let mut engine = ParticleEngine::new(Path::new(""), &HashMap::new(), &HashSet::new()); engine.seed_randoms(0, 0, 0); // TeleportRandomlyConsumeEffect: BlockUtil.clampedPackDifferenceInPosition // of the move (-7, -3, 9) with radii 127, from (4, 12, -5) to (-3, 9, 4). @@ -3987,7 +3992,7 @@ mod tests { ] { for distant in [false, true] { let mut engine = - ParticleEngine::new(Path::new(""), &HashMap::new(), HashSet::new()); + ParticleEngine::new(Path::new(""), &HashMap::new(), &HashSet::new()); engine.seed_randoms(0, 0, 0); if distant { engine.camera = [1000.0; 3];