From f6db8b1f56227da23ff72407c8af3e8ca081f6a5 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 22:44:16 +0100 Subject: [PATCH] Scroll and add the energy swirl of charged creepers and powered withers --- crates/horizon-client/src/entity.wgsl | 14 ++++++ crates/horizon-client/src/gfx.rs | 47 +++++++++++++++++- crates/horizon-client/src/gfx/entity_batch.rs | 21 +++++--- .../horizon-client/src/gfx/pack_entities.rs | 6 +-- crates/horizon-client/src/mobs/render.rs | 48 +++++++++++++++---- 5 files changed, 116 insertions(+), 20 deletions(-) diff --git a/crates/horizon-client/src/entity.wgsl b/crates/horizon-client/src/entity.wgsl index 79e11719f..ae89c4a66 100644 --- a/crates/horizon-client/src/entity.wgsl +++ b/crates/horizon-client/src/entity.wgsl @@ -224,6 +224,20 @@ fn crumbling_uv(uv: vec2, packed_origin: vec2, sprite_size: vec2, return color; } +// RenderPipelines.ENERGY_SWIRL (entity.fsh with EMISSIVE and NO_OVERLAY): the sprite, scrolled by +// the UV and repeated within itself, times the layer colour 0xFF808080, unlit; the pipeline adds +// it to the frame. The light bytes carry the sprite's origin and the colour bytes its size, both +// as breaking::stage_light packs them. +@fragment fn fs_energy_swirl(in: Out) -> @location(0) vec4 { + let bytes = round(in.color * 255.0); + let size = vec2(bytes.x + bytes.y * 256.0, bytes.z + bytes.w * 256.0) / 65535.0; + let color = textureSample(atlas, atlas_sampler, crumbling_uv(in.uv, in.wrap, size, textureDimensions(atlas))); + if color.a < 0.1 { discard; } + let f = max(linear_fog(in.spherical, globals.fog.x, globals.fog.y), + linear_fog(in.cylindrical, globals.fog.z, globals.fog.w)); + return vec4(mix(color.rgb * (128.0 / 255.0), globals.fog_color.rgb, f * globals.fog_color.a), color.a); +} + // RenderPipelines.WATER_MASK: depth only (the pipeline masks the colour off). @fragment fn fs_water_mask() -> @location(0) vec4 { return vec4(0.0); diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 70d882a98..fe8baeaae 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -37,7 +37,9 @@ mod crumbling_tests; mod entity_batch; mod weather; use entity_batch::EntityBatch; -pub use entity_batch::{SHADOW_OVERLAY, TRANSLUCENT_PARTICLE_OVERLAY, WATER_MASK_OVERLAY}; +pub use entity_batch::{ + ENERGY_SWIRL_OVERLAY, SHADOW_OVERLAY, TRANSLUCENT_PARTICLE_OVERLAY, WATER_MASK_OVERLAY, +}; /// Window.getAppropriateLineWidth, in framebuffer pixels. pub fn outline_width(width: u32) -> f32 { @@ -400,6 +402,8 @@ pub struct Renderer { cloud_uniform: wgpu::Buffer, cloud_group: wgpu::BindGroup, additive_pipeline: wgpu::RenderPipeline, + /// `RenderPipelines.ENERGY_SWIRL`: additive, unlit, the sprite repeated within itself. + energy_swirl_pipeline: wgpu::RenderPipeline, lightning_pipeline: wgpu::RenderPipeline, lightning: lightning::Renderer, see_through_pipeline: wgpu::RenderPipeline, @@ -1865,6 +1869,27 @@ impl Renderer { alpha_blend, false, ); + // RenderPipelines.ENERGY_SWIRL: BlendFunction.ADDITIVE (one, one), no culling; no depth + // writes either: vanilla sorts the quads far to near, so every face passes the test. + let one_one = wgpu::BlendComponent { + src_factor: wgpu::BlendFactor::One, + dst_factor: wgpu::BlendFactor::One, + operation: wgpu::BlendOperation::Add, + }; + let energy_swirl_pipeline = entity_pipeline_with( + "Energy swirls", + None, + false, + wgpu::CompareFunction::GreaterEqual, + Default::default(), + wgpu::BlendState { + color: one_one, + alpha: one_one, + }, + false, + "fs_energy_swirl", + wgpu::ColorWrites::ALL, + ); let lightning_attributes = wgpu::vertex_attr_array![6=>Float32x3]; let lightning_vertex = [ entity_vertex[0].clone(), @@ -2379,6 +2404,7 @@ impl Renderer { cloud_uniform, cloud_group, additive_pipeline, + energy_swirl_pipeline, lightning_pipeline, lightning: lightning::Renderer::new(), see_through_pipeline, @@ -3979,6 +4005,7 @@ impl Renderer { crumbling_quads, translucent_crumbling_quads, water_mask_quads, + swirl_quads, shadow_quads, translucent_particle_quads, ] = self @@ -3989,6 +4016,7 @@ impl Renderer { + crumbling_quads + translucent_crumbling_quads + water_mask_quads + + swirl_quads + shadow_quads + translucent_particle_quads; let cloud_quads = if let Some(input) = &frame.clouds { @@ -4554,6 +4582,21 @@ impl Renderer { self.lightning.draw(&mut pass, &frame.lightning); pass.set_bind_group(0, &self.group, &[]); } + if swirl_quads > 0 { + pass.set_pipeline(&self.energy_swirl_pipeline); + pass.set_bind_group(0, &self.entity_group, &[]); + pass.set_vertex_buffer(0, self.entity_buffer.slice(..)); + pass.draw_indexed( + 0..swirl_quads * 6, + ((entity_quads + + crumbling_quads + + translucent_crumbling_quads + + water_mask_quads) + * 4) as i32, + 0..1, + ); + pass.set_bind_group(0, &self.group, &[]); + } if additive_quads > 0 { pass.set_pipeline(&self.additive_pipeline); pass.set_bind_group(0, &self.entity_group, &[]); @@ -5240,7 +5283,7 @@ mod tests { let mut batch = super::EntityBatch::default(); let counts = batch.update(&entities, &quad(3, 5), &quad(0, 6), &quad(0, 8)); let vertices = &batch.combined; - assert_eq!(counts, [4, 1, 1, 0, 1, 1]); + assert_eq!(counts, [4, 1, 1, 0, 0, 1, 1]); assert_eq!( vertices .as_chunks::<4>() diff --git a/crates/horizon-client/src/gfx/entity_batch.rs b/crates/horizon-client/src/gfx/entity_batch.rs index 8153699fc..d00ac3d43 100644 --- a/crates/horizon-client/src/gfx/entity_batch.rs +++ b/crates/horizon-client/src/gfx/entity_batch.rs @@ -3,12 +3,17 @@ use super::Vertex; /// Entity materials by a quad's overlay (`Vertex::layer`), in draw order: /// ordinary entities, breaking cracks (11), translucent breaking cracks (12), -/// the boat water mask (13, `RenderPipelines.WATER_MASK`), entity shadows -/// (14, `RenderPipelines.ENTITY_SHADOW`) and translucent-layer particles (15, -/// drawn after translucent terrain: `SubmitNodeCollection.submitQuadParticleGroup`). -const MATERIALS: usize = 6; +/// the boat water mask (13, `RenderPipelines.WATER_MASK`), energy swirls +/// (32, `RenderPipelines.ENERGY_SWIRL`), entity shadows (14, +/// `RenderPipelines.ENTITY_SHADOW`) and translucent-layer particles (15, drawn +/// after translucent terrain: `SubmitNodeCollection.submitQuadParticleGroup`). +const MATERIALS: usize = 7; /// The overlay of depth-only quads that hide water (`RenderTypes.waterMask`). pub const WATER_MASK_OVERLAY: u32 = 13; +/// The overlay of energy swirl quads (`RenderTypes.energySwirl`: the charged creeper's and the +/// powered wither's armour). The light bytes carry the sprite's origin and the colour bytes its +/// size (`breaking::stage_light`), the UV the scrolled position in the sprite. +pub const ENERGY_SWIRL_OVERLAY: u32 = 32; /// The overlay of entity shadow quads (`RenderTypes.entityShadow`). pub const SHADOW_OVERLAY: u32 = 14; /// The overlay of translucent-layer particles (`SingleQuadParticle.Layer.translucent`). @@ -43,8 +48,9 @@ impl EntityBatch { 11 => 1, 12 => 2, WATER_MASK_OVERLAY => 3, - SHADOW_OVERLAY => 4, - TRANSLUCENT_PARTICLE_OVERLAY => 5, + ENERGY_SWIRL_OVERLAY => 4, + SHADOW_OVERLAY => 5, + TRANSLUCENT_PARTICLE_OVERLAY => 6, _ => 0, }; self.buckets[material][counts[material]] = index; @@ -96,12 +102,13 @@ mod tests { ) -> (Vec, [u32; MATERIALS]) { let mut combined = Vec::with_capacity(entities.len() + additive.len() + hand.len()); let mut counts = [0; MATERIALS]; - for (i, layer) in [0, 11, 12, 13, 14, 15].into_iter().enumerate() { + for (i, layer) in [0, 11, 12, 13, 32, 14, 15].into_iter().enumerate() { for quad in entities.as_chunks::<4>().0 { let material = match quad[0].layer { 11 => 11, 12 => 12, 13 => 13, + 32 => 32, 14 => 14, 15 => 15, _ => 0, diff --git a/crates/horizon-client/src/gfx/pack_entities.rs b/crates/horizon-client/src/gfx/pack_entities.rs index ab3c66c69..c2cc5fe72 100644 --- a/crates/horizon-client/src/gfx/pack_entities.rs +++ b/crates/horizon-client/src/gfx/pack_entities.rs @@ -405,12 +405,12 @@ pub(super) fn quad_indices(device: &wgpu::Device, quads: u32) -> wgpu::Buffer { } /// Whether a run holds only geometry a gbuffers program can draw from the shared atlas: no -/// celestial body, cloud, beam, End portal or crack (overlay codes Horizon's entity shader -/// draws in its own way; entity.wgsl). +/// celestial body, cloud, beam, End portal, crack or energy swirl (overlay codes Horizon's entity +/// shader draws in its own way; entity.wgsl). fn plain(run: &[Vertex]) -> bool { run.iter() .step_by(4) - .all(|v| !matches!(v.layer, 2 | 4 | 6 | 9 | 10 | 11 | 12)) + .all(|v| !matches!(v.layer, 2 | 4 | 6 | 9 | 10 | 11 | 12 | 32)) } /// The programs of entity runs, in the order they draw. diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs index 077fd38a6..2f6275d37 100644 --- a/crates/horizon-client/src/mobs/render.rs +++ b/crates/horizon-client/src/mobs/render.rs @@ -601,14 +601,6 @@ pub fn layers(m: &Mob) -> Vec { white, false, ), - // EnergySwirlLayer (the scroll is not reproduced: atlas sprites do not wrap). - S::Creeper if m.extra.charged => push( - &mut v, - "creeper#armor", - "entity/creeper/creeper_armor", - 0x80FF_FFFF, - true, - ), S::TropicalFish => { // TropicalFishPatternLayer: the pattern tinted with the pattern colour. let (model, letter, n) = if m.extra.variant < 6 { @@ -1151,10 +1143,50 @@ fn render_visible( } } } + // EnergySwirlLayer: the armour model, additive, scrolling over the sprite. + if let Some((model, texture, x_offset)) = energy_swirl(m, s.age) + && let Some(part) = m.kind.layer(model) + && let Some([u0, v0, u1, v1]) = atlas(texture) + { + layer_poses.reset(part); + anim::setup(m, &s, &mut layer_poses, &data.animations); + // `RenderTypes.energySwirl`'s texture offset, as the sprite-local UV. + let (du, dv) = (x_offset % 1.0, s.age * 0.01 % 1.0); + let start = out.len(); + draw( + part, + base, + &layer_poses, + [du, dv, 1.0 + du, 1.0 + dv], + crate::breaking::stage_light([u1 - u0, v1 - v0]), + crate::breaking::stage_light([u0, v0]), + crate::gfx::ENERGY_SWIRL_OVERLAY, + out, + ); + // No lighting: the colour bytes carry the sprite's size (fs_energy_swirl). + for vertex in &mut out[start..] { + vertex.normal = [0; 4]; + } + } if shell_last { draw_body(out); } } +/// `EnergySwirlLayer`'s model, texture and `xOffset(t)` for a charged creeper +/// (`CreeperPowerLayer`) or a powered wither (`WitherArmorLayer`); `t` is `ageInTicks`. +fn energy_swirl(m: &Mob, t: f32) -> Option<(&'static str, &'static str, f32)> { + match m.species() { + Species::Creeper if m.extra.charged => { + Some(("creeper#armor", "entity/creeper/creeper_armor", t * 0.01)) + } + Species::Wither if super::wither::powered(m) => Some(( + "wither#armor", + "entity/wither/wither_armor", + (t * 0.02).mcos() * 3.0, + )), + _ => None, + } +} /// The equipment slot of a `HumanoidArmorLayer` model (`zombie#helmet`). fn armor_slot(model: &str) -> Option { Some(match model.rsplit('#').next()? {