Merge pull request #2521 from kacpherek/feat/energy-swirl

🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19). Thanks @kacpherek: Scroll and add the energy swirl of charged creepers and powered withers. I checked it against vanilla 26.3, merged main in, and it passed every harness it reaches in a union with your other PRs.
This commit is contained in:
Ludovic Marie
2026-10-27 12:13:48 +01:00
committed by GitHub
5 changed files with 115 additions and 21 deletions
+14
View File
@@ -244,6 +244,20 @@ fn celestial_color(in: Out) -> vec4<f32> {
return vec4(added, smoothstep(0.1, 0.3, max(added.r, max(added.g, added.b))));
}
// 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<f32> {
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<f32> {
return vec4(0.0);
+43 -2
View File
@@ -39,7 +39,7 @@ mod entity_outline;
mod weather;
use entity_batch::EntityBatch;
pub use entity_batch::{
SHADOW_OVERLAY, TRANSLUCENT_GLINT_ITEM_OVERLAY, TRANSLUCENT_ITEM_OVERLAY,
ENERGY_SWIRL_OVERLAY, SHADOW_OVERLAY, TRANSLUCENT_GLINT_ITEM_OVERLAY, TRANSLUCENT_ITEM_OVERLAY,
TRANSLUCENT_PARTICLE_OVERLAY, WATER_MASK_OVERLAY,
};
@@ -411,6 +411,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,
@@ -1899,6 +1901,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(),
@@ -2421,6 +2444,7 @@ impl Renderer {
cloud_uniform,
cloud_group,
additive_pipeline,
energy_swirl_pipeline,
lightning_pipeline,
lightning: lightning::Renderer::new(),
see_through_pipeline,
@@ -4053,6 +4077,7 @@ impl Renderer {
crumbling_quads,
translucent_crumbling_quads,
water_mask_quads,
swirl_quads,
shadow_quads,
translucent_particle_quads,
translucent_item_quads,
@@ -4064,6 +4089,7 @@ impl Renderer {
+ crumbling_quads
+ translucent_crumbling_quads
+ water_mask_quads
+ swirl_quads
+ shadow_quads
+ translucent_particle_quads
+ translucent_item_quads;
@@ -4653,6 +4679,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, &[]);
@@ -5343,7 +5384,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, 0]);
assert_eq!(counts, [4, 1, 1, 0, 0, 1, 1, 0]);
assert_eq!(
vertices
.as_chunks::<4>()
+15 -8
View File
@@ -3,13 +3,18 @@ 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`)
/// the boat water mask (13, `RenderPipelines.WATER_MASK`), energy swirls
/// (34, `RenderPipelines.ENERGY_SWIRL`), entity shadows (14,
/// `RenderPipelines.ENTITY_SHADOW`), translucent-layer particles (15, drawn
/// after translucent terrain: `SubmitNodeCollection.submitQuadParticleGroup`)
/// and translucent item quads (32, drawn without depth writes).
const MATERIALS: usize = 7;
const MATERIALS: usize = 8;
/// 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 = 34;
/// The overlay of entity shadow quads (`RenderTypes.entityShadow`).
pub const SHADOW_OVERLAY: u32 = 14;
/// The overlay of translucent-layer particles (`SingleQuadParticle.Layer.translucent`).
@@ -49,9 +54,10 @@ impl EntityBatch {
11 => 1,
12 => 2,
WATER_MASK_OVERLAY => 3,
SHADOW_OVERLAY => 4,
TRANSLUCENT_PARTICLE_OVERLAY => 5,
TRANSLUCENT_ITEM_OVERLAY | TRANSLUCENT_GLINT_ITEM_OVERLAY => 6,
ENERGY_SWIRL_OVERLAY => 4,
SHADOW_OVERLAY => 5,
TRANSLUCENT_PARTICLE_OVERLAY => 6,
TRANSLUCENT_ITEM_OVERLAY | TRANSLUCENT_GLINT_ITEM_OVERLAY => 7,
_ => 0,
};
self.buckets[material][counts[material]] = index;
@@ -103,12 +109,13 @@ mod tests {
) -> (Vec<Vertex>, [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, 34, 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,
34 => 34,
14 => 14,
15 => 15,
_ => 0,
@@ -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 | 34))
}
/// The programs of entity runs, in the order they draw.
+40 -8
View File
@@ -664,14 +664,6 @@ pub fn layers(m: &Mob) -> Vec<Layer> {
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 {
@@ -1226,10 +1218,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<usize> {
Some(match model.rsplit('#').next()? {