From d088140c0d2b0a4cda495160258cd85f4f437a6a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 10 Oct 2026 22:02:40 +0200 Subject: [PATCH] Compare beacon beams with BeaconRenderer Move the beam geometry into block_entity_render::beacon_beam so the block entity render harness can replay it against vanilla submit calls (positions, UVs and colours of the solid beam and glow per section). Co-Authored-By: Claude Opus 5.5 --- .../examples/block_entity_render_fixture.rs | 46 +++++++++- .../horizon-client/src/block_entity_render.rs | 86 +++++++++++++++++++ crates/horizon-client/src/game/beacon.rs | 83 +++--------------- .../VanillaBlockEntityRenderOracle.java | 10 +++ tools/test_block_entity_render_parity.py | 21 ++++- 5 files changed, 169 insertions(+), 77 deletions(-) diff --git a/crates/horizon-client/examples/block_entity_render_fixture.rs b/crates/horizon-client/examples/block_entity_render_fixture.rs index df8a694a6..f29cebc0c 100644 --- a/crates/horizon-client/examples/block_entity_render_fixture.rs +++ b/crates/horizon-client/examples/block_entity_render_fixture.rs @@ -3,7 +3,7 @@ //! through `BlockEntityRenderer` at the block origin and writes the quads //! (texture, sprite-local UVs, baked colour, light) and sign text calls. #![forbid(unsafe_code)] -use glam::{DVec3, Mat4, Quat}; +use glam::{DVec3, Mat4, Quat, Vec3}; use horizon_client::{ assets::Assets, banner::{self, Banners}, @@ -125,6 +125,50 @@ fn main() -> Result<()> { { let case: Value = serde_json::from_str(line)?; let block = case["block"].as_str().unwrap_or_default(); + if block == "minecraft:beacon" { + // BeaconRenderer: the beam sections from the case, as Horizon's beacon keeps them. + let int = |v: &Value| v.as_i64().unwrap_or(0); + let pos = [ + int(&case["pos"][0]), + int(&case["pos"][1]), + int(&case["pos"][2]), + ]; + let partial = case["partial"].as_f64().unwrap_or(0.0) as f32; + let time = int(&case["gameTime"]).rem_euclid(40) as f32 + partial; + let cam = &case["camera"]; + let dx = cam[0].as_f64().unwrap_or(0.0) - (pos[0] as f64 + 0.5); + let dz = cam[2].as_f64().unwrap_or(0.0) - (pos[2] as f64 + 0.5); + let scale = ((dx * dx + dz * dz).sqrt() as f32 / 96.0).max(1.0); + let sections: Vec<(u32, i32)> = case["beam"] + .as_array() + .into_iter() + .flatten() + .map(|s| (int(&s[0]) as u32 & 0xFF_FFFF, int(&s[1]) as i32)) + .collect(); + let texture = "entity/beacon/beacon_beam"; + let rect = sprites.get(texture).copied().ok_or("no beam sprite")?; + let mut verts = Vec::new(); + horizon_client::block_entity_render::beacon_beam( + Vec3::ZERO, + §ions, + time, + scale, + rect, + &mut verts, + ); + let quads: Vec = verts + .chunks(4) + .map(|q| { + let v: Vec = q + .iter() + .map(|v| json!([v.pos[0], v.pos[1], v.pos[2], v.uv[0] - rect.u0, v.uv[1]])) + .collect(); + json!({"texture": texture, "v": v, "color": q[0].color, "light": q[0].light, "custom": true}) + }) + .collect(); + writeln!(out, "{}", json!({"quads": quads, "texts": []}))?; + continue; + } let Some(state) = find_state(registry, block) else { writeln!(out, "{}", json!({"skip": "unknown block state"}))?; continue; diff --git a/crates/horizon-client/src/block_entity_render.rs b/crates/horizon-client/src/block_entity_render.rs index 1f6f805ba..4e2a7704b 100644 --- a/crates/horizon-client/src/block_entity_render.rs +++ b/crates/horizon-client/src/block_entity_render.rs @@ -1560,3 +1560,89 @@ mod tests { assert_eq!(out[2].uv, [0.5, 0.5]); } } + +/// `BeaconRenderer.submit`: for each beam section (ARGB colour, height) the +/// rotating solid beam and its translucent glow, the last section 2048 +/// blocks tall. `origin` is the beacon block's corner relative to the camera, +/// `time` the animation time (game time mod 40 plus partial tick) and `scale` +/// the radius scale. The sprite's v range rides in the light bytes (the +/// entity shader wraps v for layer 6). +pub fn beacon_beam( + origin: Vec3, + sections: &[(u32, i32)], + time: f32, + scale: f32, + s: Rect, + out: &mut Vec, +) { + let q = |v: f32| (v * 65535.0).round().clamp(0.0, 65535.0) as u32; + let wrap = q(s.v0) | q(s.v1 - s.v0) << 16; + let o = origin + Vec3::new(0.5, 0.0, 0.5); + let mut start = 0i32; + for (i, &(color, height)) in sections.iter().enumerate() { + let height = if i == sections.len() - 1 { + 2048 + } else { + height + }; + let end = start + height; + let scroll = if height < 0 { time } else { -time }; + let v_off = frac(scroll * 0.2 - (scroll * 0.1).floor()); + let abgr = + |a: u32| a << 24 | (color & 255) << 16 | (color >> 8 & 255) << 8 | (color >> 16 & 255); + // Solid beam: radius 0.2 * scale, rotated with time. + let r = 0.2 * scale; + let rot = glam::Mat3::from_rotation_y((time * 2.25 - 45.0).to_radians()); + let corners = [ + rot * Vec3::new(0.0, 0.0, r), + rot * Vec3::new(r, 0.0, 0.0), + rot * Vec3::new(-r, 0.0, 0.0), + rot * Vec3::new(0.0, 0.0, -r), + ]; + let v2 = -1.0 + v_off; + let v1 = height as f32 * (0.5 / r) + v2; + beam_part(out, o, start, end, corners, [v1, v2], abgr(255), s, wrap); + // Glow: radius 0.25 * scale, translucent. + let g = 0.25 * scale; + let corners = [ + Vec3::new(-g, 0.0, -g), + Vec3::new(g, 0.0, -g), + Vec3::new(-g, 0.0, g), + Vec3::new(g, 0.0, g), + ]; + let v1 = height as f32 + v2; + beam_part(out, o, start, end, corners, [v1, v2], abgr(32), s, wrap); + start = end; + } +} +/// `BeaconRenderer.renderPart`: four quads between the corners (wn, en, ws, es). +#[allow(clippy::too_many_arguments)] +fn beam_part( + out: &mut Vec, + o: Vec3, + start: i32, + end: i32, + [wn, en, ws, es]: [Vec3; 4], + [v1, v2]: [f32; 2], + color: u32, + s: Rect, + wrap: u32, +) { + for (a, b) in [(wn, en), (es, ws), (en, es), (ws, wn)] { + let at = |c: Vec3, y: i32| o + c + Vec3::new(0.0, y as f32, 0.0); + for (p, uv) in [ + (at(a, end), [s.u1, v1]), + (at(a, start), [s.u1, v2]), + (at(b, start), [s.u0, v2]), + (at(b, end), [s.u0, v1]), + ] { + out.push(Vertex { + pos: p.to_array(), + uv, + layer: 6, + color, + light: wrap, + }); + } + } +} diff --git a/crates/horizon-client/src/game/beacon.rs b/crates/horizon-client/src/game/beacon.rs index 89216e7e1..943fb9e9d 100644 --- a/crates/horizon-client/src/game/beacon.rs +++ b/crates/horizon-client/src/game/beacon.rs @@ -522,9 +522,6 @@ impl Game<'_> { else { return; }; - // The sprite's v range rides in the light bytes (entity shader overlay 6). - let q = |v: f32| (v * 65535.0).round().clamp(0.0, 65535.0) as u32; - let wrap = q(s.v0) | q(s.v1 - s.v0) << 16; let time = (self.world.game_time.rem_euclid(40)) as f32 + alpha as f32; let scoping = self.scoping(); for (k, e) in &self.world.block_entities { @@ -539,75 +536,17 @@ impl Game<'_> { } else { (distance / 96.0).max(1.0) }; - let o = (base - camera).as_vec3(); - let mut start = 0i32; - for (i, &(color, height)) in b.sections.iter().enumerate() { - let height = if i == b.sections.len() - 1 { - 2048 - } else { - height - }; - let end = start + height; - let scroll = -time; - let v_off = (scroll * 0.2 - (scroll * 0.1).floor()).rem_euclid(1.0); - let rgb = |a: u32| { - a << 24 | (color & 255) << 16 | (color >> 8 & 255) << 8 | (color >> 16 & 255) - }; - // Solid beam: radius 0.2, rotated with time. - let r = 0.2 * scale; - let rot = glam::Mat3::from_rotation_y((time * 2.25 - 45.0).to_radians()); - let corners = [ - rot * glam::Vec3::new(0.0, 0.0, r), - rot * glam::Vec3::new(r, 0.0, 0.0), - rot * glam::Vec3::new(-r, 0.0, 0.0), - rot * glam::Vec3::new(0.0, 0.0, -r), - ]; - let v2 = -1.0 + v_off; - let v1 = height as f32 * (0.5 / r) + v2; - beam_part(out, o, start, end, corners, [v1, v2], rgb(255), s, wrap); - // Glow: radius 0.25, translucent. - let g = 0.25 * scale; - let corners = [ - glam::Vec3::new(-g, 0.0, -g), - glam::Vec3::new(g, 0.0, -g), - glam::Vec3::new(-g, 0.0, g), - glam::Vec3::new(g, 0.0, g), - ]; - let v1 = height as f32 + v2; - beam_part(out, o, start, end, corners, [v1, v2], rgb(32), s, wrap); - start = end; - } - } - } -} -/// `renderPart`: four quads between the corners (wn, en, ws, es). -#[allow(clippy::too_many_arguments)] -fn beam_part( - out: &mut Vec, - o: glam::Vec3, - start: i32, - end: i32, - [wn, en, ws, es]: [glam::Vec3; 4], - [v1, v2]: [f32; 2], - color: u32, - s: horizon_client::hud::Rect, - wrap: u32, -) { - for (a, b) in [(wn, en), (es, ws), (en, es), (ws, wn)] { - let at = |c: glam::Vec3, y: i32| o + c + glam::Vec3::new(0.0, y as f32, 0.0); - for (p, uv) in [ - (at(a, end), [s.u1, v1]), - (at(a, start), [s.u1, v2]), - (at(b, start), [s.u0, v2]), - (at(b, end), [s.u0, v1]), - ] { - out.push(Vertex { - pos: p.to_array(), - uv, - layer: 6, - color, - light: wrap, - }); + let origin = (glam::DVec3::new(f64::from(k.0), f64::from(k.1), f64::from(k.2)) + - camera) + .as_vec3(); + horizon_client::block_entity_render::beacon_beam( + origin, + &b.sections, + time, + scale, + s, + out, + ); } } } diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockEntityRenderOracle.java b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockEntityRenderOracle.java index 5f42922af..7088eaab8 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockEntityRenderOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockEntityRenderOracle.java @@ -329,6 +329,16 @@ public final class VanillaBlockEntityRenderOracle { var cam = c.getAsJsonArray("camera"); var cameraPos = new Vec3(cam.get(0).getAsDouble(), cam.get(1).getAsDouble(), cam.get(2).getAsDouble()); var rs = (BlockEntityRenderState) renderer.createRenderState(); + if (rs instanceof BeaconRenderState beacon) { + // BeaconRenderer.extract reads Minecraft.getInstance().player (scoping); its level-free part: + BlockEntityRenderState.extractBase(be, rs, null); + beacon.animationTime = Math.floorMod(c.get("gameTime").getAsLong(), 40) + partial; + var sections = new ArrayList(); + for (var e : c.getAsJsonArray("beam")) sections.add(new BeaconRenderState.Section(e.getAsJsonArray().get(0).getAsInt(), e.getAsJsonArray().get(1).getAsInt())); + beacon.sections = sections; + float distance = (float) cameraPos.subtract(Vec3.atCenterOf(pos)).horizontalDistance(); + beacon.beamRadiusScale = Math.max(1.0F, distance / 96.0F); + } else if (rs instanceof SignRenderState sign) { // AbstractSignRenderer.extractRenderState reads Minecraft.getInstance(); its level-free part: var signBe = (SignBlockEntity) be; diff --git a/tools/test_block_entity_render_parity.py b/tools/test_block_entity_render_parity.py index 672138543..35932ba16 100644 --- a/tools/test_block_entity_render_parity.py +++ b/tools/test_block_entity_render_parity.py @@ -115,7 +115,11 @@ def cases(): for prefix in ['', 'exposed_', 'weathered_', 'oxidized_', 'waxed_']: for pose in ['standing', 'running', 'sitting', 'star']: add(f'minecraft:{prefix}copper_golem_statue[facing={rng.choice(HORIZONTAL)},copper_golem_pose={pose}]') - for block in ['end_portal', 'end_gateway', 'beacon', 'campfire[facing=north]', 'spawner', + for _ in range(8): + add('minecraft:beacon', gameTime=rng.randint(0, 10 ** 6), + camera=[rng.uniform(-300, 300), 70.0, rng.uniform(-300, 300)], + beam=[[0xFF000000 | rng.randint(0, 0xFFFFFF), rng.randint(1, 30)] for _ in range(rng.randint(1, 3))]) + for block in ['end_portal', 'end_gateway', 'campfire[facing=north]', 'spawner', 'trial_spawner', 'vault', 'suspicious_sand', 'oak_shelf[facing=east]']: add('minecraft:' + block) return out @@ -144,18 +148,20 @@ def mix(normal): def vanilla_quads(submits): quads, other = [], [] for s in submits: - if s['type'] != 'submitModel': + custom = s['type'] == 'submitCustomGeometry' + if s['type'] != 'submitModel' and not custom: other.append(s) continue verts = s['vertices'] for i in range(0, len(verts), 4): q = verts[i:i + 4] tint = q[0][3] & 0xFFFFFFFF - b = mix(q[0][8:11]) + # Custom geometry (beacon beams) is unlit; models get the entity shader's mix light. + b = 1.0 if custom else mix(q[0][8:11]) ch = lambda shift: int(((tint >> shift) & 255) * b) quads.append({'texture': s['texture'], 'v': [v[:3] + v[4:6] for v in q], 'rgb': [ch(16), ch(8), ch(0)], 'alpha': tint >> 24, 'light': q[0][7], - 'overlay': q[0][6], 'type': s['renderType']}) + 'overlay': q[0][6], 'type': s['renderType'], 'custom': custom}) return quads, other @@ -210,6 +216,13 @@ def compare_case(v, r, tol): if bad: problems.append(f'{a["texture"]} vertices {a["v"]} != {b["v"]}') break + if a['custom']: + # Horizon packs the beam sprite's v range into the light bytes (its shader wraps v). + got = b['color'] + if [got & 255, (got >> 8) & 255, (got >> 16) & 255, got >> 24] != a['rgb'] + [a['alpha']]: + problems.append(f'{a["texture"]} colour {a["rgb"]}/{a["alpha"]} != {got:#x}') + break + continue if a['overlay'] != NO_OVERLAY: problems.append(f'overlay {a["overlay"]}') got = b['color']