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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-25 10:44:32 +01:00
committed by socksprox
parent 4032e162ce
commit be378bb773
5 changed files with 29 additions and 24 deletions
@@ -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?)?;
@@ -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"),
+1 -1
View File
@@ -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(),
+1 -1
View File
@@ -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, &[]);
+25 -20
View File
@@ -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<Vec<(ParticleOptions, [f64; 3], [f64; 3])>>,
names: Vec<String>,
rects: Vec<Option<Rect>>,
atlas: HashMap<String, Rect>,
/// `SingleQuadParticle.Layer.bySprite`: named sprites whose texels include
/// 0 < alpha < 255 render on vanilla's translucent particle layer.
translucent: HashSet<String>,
/// Each named sprite, and whether `SingleQuadParticle.Layer.bySprite` puts
/// it on the translucent layer (a texel with 0 < alpha < 255).
atlas: HashMap<String, (Rect, bool)>,
sets: HashMap<ParticleType, u32>,
set_sprites: Vec<Vec<u32>>,
/// `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<String, Rect>, translucent: HashSet<String>) -> Self {
pub fn new(root: &Path, atlas: &HashMap<String, Rect>, translucent: &HashSet<String>) -> 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];