From fda4d65a02e566b1e0386d87092b047fadfc42a8 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:05:36 +0200 Subject: [PATCH 1/3] Give the block-entity render oracle an item resolver and an End gateway level Campfires and brushable blocks resolve their items (empty here) through the context's ItemModelResolver, which was null. End gateways read the level for their beam (max y, game time) and visible faces, so they get a stub level with the case's neighbours, light, build height and game time. New cases cover gateways spawning, cooling down and settled against neighbours, and End portals beside the same neighbours. Co-Authored-By: Claude Opus 5.5 --- .../VanillaBlockEntityRenderOracle.java | 78 ++++++++++++++++++- tools/test_block_entity_render_parity.py | 10 +++ 2 files changed, 85 insertions(+), 3 deletions(-) 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 7088eaab8..c7c40a477 100644 --- a/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockEntityRenderOracle.java +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/VanillaBlockEntityRenderOracle.java @@ -45,7 +45,8 @@ import org.joml.Quaternionf; * renderer's extractRenderState and submit, and captures every submitted * model (vertices after setupAnim and the pose stack, sprite-local UVs, tint, * light), text call and item. Level-backed inputs (light, chest lid - * openness, pot wobble) come from the case because the entity has no level. + * openness, pot wobble) come from the case because the entity has no level; + * End gateways, which query theirs, get a stub level built from the case. * * Input lines: case JSON. Output lines: {case, submits:[...]} or {case, error}. */ @@ -206,6 +207,54 @@ public final class VanillaBlockEntityRenderOracle { return (SubmitNodeCollector) Proxy.newProxyInstance(SubmitNodeCollector.class.getClassLoader(), new Class[] {SubmitNodeCollector.class}, handler); } + /** + * The level an End gateway reads: the gateway and the case's neighbour + * blocks (air elsewhere), its light, build height and game time. Allocated without running + * Level's constructor; everything else is unsupported. + */ + static final class CaseLevel extends net.minecraft.world.level.Level { + Map blocks; + int minY, height, sky, block; + long gameTime; + CaseLevel() { super(null, null, null, null, false, false, 0L, 0); } + @Override public BlockState getBlockState(BlockPos p) { return blocks.getOrDefault(p, net.minecraft.world.level.block.Blocks.AIR.defaultBlockState()); } + @Override public int getMinY() { return minY; } + @Override public int getHeight() { return height; } + @Override public long getGameTime() { return gameTime; } + @Override public int getBrightness(net.minecraft.world.level.LightLayer layer, BlockPos p) { return layer == net.minecraft.world.level.LightLayer.SKY ? sky : block; } + @Override public net.minecraft.world.clock.ClockManager clockManager() { throw new UnsupportedOperationException(); } + @Override public void destroyBlockProgress(int p0, BlockPos p1, int p2) { throw new UnsupportedOperationException(); } + @Override public java.util.Collection dragonParts() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.flag.FeatureFlagSet enabledFeatures() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.attribute.EnvironmentAttributeSystem environmentAttributes() { throw new UnsupportedOperationException(); } + @Override public void explode(net.minecraft.world.entity.Entity p0, net.minecraft.world.damagesource.DamageSource p1, net.minecraft.world.level.ExplosionDamageCalculator p2, double p3, double p4, double p5, float p6, boolean p7, net.minecraft.world.level.Level.ExplosionInteraction p8, net.minecraft.core.particles.ParticleOptions p9, net.minecraft.core.particles.ParticleOptions p10, net.minecraft.util.random.WeightedList p11, net.minecraft.core.Holder p12) { throw new UnsupportedOperationException(); } + @Override public void gameEvent(net.minecraft.core.Holder p0, net.minecraft.world.phys.Vec3 p1, net.minecraft.world.level.gameevent.GameEvent.Context p2) { throw new UnsupportedOperationException(); } + @Override public String gatherChunkSourceStats() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.ticks.LevelTickAccess getBlockTicks() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.level.chunk.ChunkSource getChunkSource() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.level.entity.LevelEntityGetter getEntities() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.entity.Entity getEntity(int p0) { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.ticks.LevelTickAccess getFluidTicks() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.level.saveddata.maps.MapItemSavedData getMapData(net.minecraft.world.level.saveddata.maps.MapId p0) { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.level.storage.LevelData.RespawnData getRespawnData() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.scores.Scoreboard getScoreboard() { throw new UnsupportedOperationException(); } + @Override public int getSeaLevel() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.core.Holder getUncachedNoiseBiome(int p0, int p1, int p2) { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.level.border.WorldBorder getWorldBorder() { throw new UnsupportedOperationException(); } + @Override public void levelEvent(net.minecraft.world.entity.Entity p0, int p1, BlockPos p2, int p3) { throw new UnsupportedOperationException(); } + @Override public void playSeededSound(net.minecraft.world.entity.Entity p0, net.minecraft.world.entity.Entity p1, net.minecraft.core.Holder p2, net.minecraft.sounds.SoundSource p3, float p4, float p5, long p6) { throw new UnsupportedOperationException(); } + @Override public void playSeededSound(net.minecraft.world.entity.Entity p0, double p1, double p2, double p3, net.minecraft.core.Holder p4, net.minecraft.sounds.SoundSource p5, float p6, float p7, long p8) { throw new UnsupportedOperationException(); } + @Override public java.util.List players() { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.item.crafting.RecipeAccess recipeAccess() { throw new UnsupportedOperationException(); } + @Override public void sendBlockUpdated(BlockPos p0, BlockState p1, BlockState p2, int p3) { throw new UnsupportedOperationException(); } + @Override public void setRespawnData(net.minecraft.world.level.storage.LevelData.RespawnData p0) { throw new UnsupportedOperationException(); } + @Override public net.minecraft.world.TickRateManager tickRateManager() { throw new UnsupportedOperationException(); } + } + + static BlockState parseState(String spec) throws Exception { + return BlockStateParser.parseForBlock(BuiltInRegistries.BLOCK, spec, false).blockState(); + } + static Field field(Class type, String name) throws NoSuchFieldException { for (Class c = type; c != null; c = c.getSuperclass()) { try { @@ -263,6 +312,26 @@ public final class VanillaBlockEntityRenderOracle { : Optional.of(new ItemStackTemplate(BuiltInRegistries.ITEM.getValue(Identifier.parse(id))))); } field(DecoratedPotBlockEntity.class, "decorations").set(be, new PotDecorations(items.get(0), items.get(1), items.get(2), items.get(3))); + } else if (be instanceof TheEndGatewayBlockEntity) { + // Age and teleportCooldown (synced and ticked by the client), and the level the renderer reads. + var g = c.has("gateway") ? c.getAsJsonObject("gateway") : new JsonObject(); + field(TheEndGatewayBlockEntity.class, "age").setLong(be, g.has("age") ? g.get("age").getAsLong() : 0L); + field(TheEndGatewayBlockEntity.class, "teleportCooldown").setInt(be, g.has("cooldown") ? g.get("cooldown").getAsInt() : 0); + var level = (CaseLevel) allocate.invoke(unsafe, CaseLevel.class); + var height = c.has("level") ? c.getAsJsonArray("level") : null; + level.minY = height == null ? 0 : height.get(0).getAsInt(); + level.height = height == null ? 256 : height.get(1).getAsInt(); + level.gameTime = c.has("gameTime") ? c.get("gameTime").getAsLong() : 0L; + var light = c.getAsJsonArray("light"); + level.sky = light.get(0).getAsInt(); + level.block = light.get(1).getAsInt(); + level.blocks = new HashMap<>(); + level.blocks.put(be.getBlockPos(), be.getBlockState()); + if (c.has("neighbours")) { + for (var e : c.getAsJsonObject("neighbours").entrySet()) + level.blocks.put(be.getBlockPos().relative(Direction.byName(e.getKey())), parseState(e.getValue().getAsString())); + } + be.setLevel(level); } else if (be instanceof BannerBlockEntity && c.has("patterns")) { var builder = new net.minecraft.world.level.block.entity.BannerPatternLayers.Builder(); var registry = ParityData.access.lookupOrThrow(Registries.BANNER_PATTERN); @@ -307,7 +376,10 @@ public final class VanillaBlockEntityRenderOracle { throw new RuntimeException(e); } }; - var context = new BlockEntityRendererProvider.Context(null, null, null, null, models, font, sprites, null); + // Campfires and brushable blocks resolve their (here always empty) items: an empty + // stack only clears the render state and never reaches the model manager. + var items = new net.minecraft.client.renderer.item.ItemModelResolver(null); + var context = new BlockEntityRendererProvider.Context(null, null, items, null, models, font, sprites, null); Map renderers = (Map) BlockEntityRenderers.createEntityRenderers(context); var gson = new Gson(); var out = new StringBuilder(); @@ -317,7 +389,7 @@ public final class VanillaBlockEntityRenderOracle { var result = new JsonObject(); result.add("case", c); try { - BlockState state = BlockStateParser.parseForBlock(BuiltInRegistries.BLOCK, c.get("block").getAsString(), false).blockState(); + BlockState state = parseState(c.get("block").getAsString()); var p = c.getAsJsonArray("pos"); var pos = new BlockPos(p.get(0).getAsInt(), p.get(1).getAsInt(), p.get(2).getAsInt()); var be = ((EntityBlock) state.getBlock()).newBlockEntity(pos, state); diff --git a/tools/test_block_entity_render_parity.py b/tools/test_block_entity_render_parity.py index 35932ba16..e4c32ca2a 100644 --- a/tools/test_block_entity_render_parity.py +++ b/tools/test_block_entity_render_parity.py @@ -122,6 +122,16 @@ def cases(): for block in ['end_portal', 'end_gateway', 'campfire[facing=north]', 'spawner', 'trial_spawner', 'vault', 'suspicious_sand', 'oak_shelf[facing=east]']: add('minecraft:' + block) + # End gateways: the beam while spawning (age < 200) or cooling down, in End and + # Overworld build heights, and the faces Block.shouldRenderFace leaves against neighbours. + neighbours = [{}, {'up': 'minecraft:bedrock', 'down': 'minecraft:bedrock'}, + {'north': 'minecraft:end_gateway', 'east': 'minecraft:glass', 'west': 'minecraft:oak_slab[type=top]', + 'south': 'minecraft:end_stone', 'down': 'minecraft:oak_stairs[facing=east,half=top]'}] + for age, cooldown in [(0, 0), (37, 0), (150, 0), (199, 0), (120, 25), (5000, 1), (5000, 17), (5000, 40), (5000, 0)]: + add('minecraft:end_gateway', gateway={'age': age, 'cooldown': cooldown}, gameTime=rng.randint(0, 10 ** 6), + level=rng.choice([[0, 256], [-64, 384]]), neighbours=rng.choice(neighbours)) + for n in neighbours: + add('minecraft:end_portal', neighbours=n) return out From 613702c0a769baa0a175219ceac027f3137376c2 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:05:36 +0200 Subject: [PATCH 2/3] Render End portals and End gateways as vanilla's block-entity renderers TheEndPortalRenderer and TheEndGatewayRenderer: the position-only portal cube in FaceInfo order (only the vertical faces for portals, the faces Block.shouldRenderFace leaves for gateways) and the gateway beam through a shared submitBeaconBeam. The beacon beam now goes through the same function. The client does not track gateway ages and cooldowns yet, so gateways in game render settled. Co-Authored-By: Claude Opus 5.5 --- .../examples/block_entity_render_fixture.rs | 55 +++- .../horizon-client/src/block_entity_render.rs | 292 ++++++++++++++---- crates/horizon-client/src/game.rs | 15 +- crates/horizon-client/src/game/minecarts.rs | 1 + 4 files changed, 299 insertions(+), 64 deletions(-) diff --git a/crates/horizon-client/examples/block_entity_render_fixture.rs b/crates/horizon-client/examples/block_entity_render_fixture.rs index f29cebc0c..1770c0c89 100644 --- a/crates/horizon-client/examples/block_entity_render_fixture.rs +++ b/crates/horizon-client/examples/block_entity_render_fixture.rs @@ -7,7 +7,9 @@ use glam::{DVec3, Mat4, Quat, Vec3}; use horizon_client::{ assets::Assets, banner::{self, Banners}, - block_entity_render::{BlockAnim, BlockEntityRenderer, Scene, TextCall}, + block_entity_render::{ + BlockAnim, BlockEntityRenderer, END_GATEWAY_LAYER, END_PORTAL_LAYER, Scene, TextCall, + }, chunk::{Chunk, Light}, hud::{HudAtlas, Rect}, signs::{DYE_TEXT, SignData, SignText}, @@ -196,6 +198,25 @@ fn main() -> Result<()> { world.chunks.insert((cx, cz), Arc::new(chunk)); } } + // Neighbour blocks the case sets (End gateway faces). + for (direction, spec) in case["neighbours"].as_object().into_iter().flatten() { + let d = match direction.as_str() { + "down" => [0, -1, 0], + "up" => [0, 1, 0], + "north" => [0, 0, -1], + "south" => [0, 0, 1], + "west" => [-1, 0, 0], + _ => [1, 0, 0], + }; + let neighbour = find_state(registry, spec.as_str().unwrap_or_default()) + .ok_or("unknown neighbour state")?; + world.set( + pos[0] + d[0], + pos[1] + d[1], + pos[2] + d[2], + BlockStateId(neighbour), + )?; + } if let Some(book) = case.get("book") { renderer.set_book( pos, @@ -246,6 +267,15 @@ fn main() -> Result<()> { wobble: case["wobble"] .as_array() .map(|w| (w[0].as_str() == Some("POSITIVE"), float(&w[1]))), + gateway: ( + case["gateway"]["age"].as_i64().unwrap_or(0), + int(&case["gateway"]["cooldown"]), + ), + }; + // The case's level height (minimum y, height): the End's by default. + let max_y = match case["level"].as_array() { + Some(l) => int(&l[0]) + int(&l[1]) - 1, + None => 255, }; let open = float(&case["open"]); let near = case["sign"]["near"].as_bool().unwrap_or(false); @@ -279,7 +309,8 @@ fn main() -> Result<()> { anim: &|_| anim.clone(), texts: Some(&texts), partial: float(&case["partial"]), - game_time: 0, + game_time: case["gameTime"].as_i64().unwrap_or(0), + max_y, world: &world, sprites: &sprites, nether: false, @@ -293,6 +324,26 @@ fn main() -> Result<()> { let quads: Vec = verts .chunks(4) .map(|q| { + // Custom geometry: the End portal shader's position-only cube (its + // render type samples end_sky first) and End gateway beams. + if q[0].layer == END_PORTAL_LAYER || q[0].layer == END_GATEWAY_LAYER { + let v: Vec = q + .iter() + .map(|v| json!([v.pos[0], v.pos[1], v.pos[2], v.uv[0], v.uv[1]])) + .collect(); + return json!({"texture": "environment/end_sky", "v": v, "color": q[0].color, + "light": q[0].light, "custom": true}); + } + if q[0].layer == 6 { + let texture = "entity/end_portal/end_gateway_beam"; + let u0 = sprites.get(texture).map_or(0.0, |r| r.u0); + let v: Vec = q + .iter() + .map(|v| json!([v.pos[0], v.pos[1], v.pos[2], v.uv[0] - u0, v.uv[1]])) + .collect(); + return json!({"texture": texture, "v": v, "color": q[0].color, + "light": q[0].light, "custom": true}); + } let (cu, cv) = ((q[0].uv[0] / 2.0).floor(), (q[0].uv[1] / 2.0).floor()); let texture = names .get(cu as usize + cv as usize * grid) diff --git a/crates/horizon-client/src/block_entity_render.rs b/crates/horizon-client/src/block_entity_render.rs index f3638865b..1619ccba5 100644 --- a/crates/horizon-client/src/block_entity_render.rs +++ b/crates/horizon-client/src/block_entity_render.rs @@ -1,19 +1,23 @@ //! Block-entity renderers (`BlockEntityRenderers`): chests (single, double, //! trapped, ender, copper), shulker boxes, banners, skulls and heads, bells, //! decorated pots, conduits, enchanting-table and lectern books and copper -//! golem statues. Models are vanilla's baked `LayerDefinitions` layers +//! golem statues, End portals and End gateways. Models are vanilla's baked `LayerDefinitions` layers //! (`entity-models.json`); transforms, animation and textures follow each //! vanilla renderer. Faces are lit like the `entity` shader: the lightmap at //! the block plus `minecraft_mix_light` with the level's two diffuse lights. use crate::{hud::Rect, mesher::Vertex, world::World}; use glam::{DVec3, Mat4, Quat, Vec3}; +use horizon_core::geometry::Direction; use horizon_core::{ - geometry::trig::Mth, + geometry::trig::{self, Mth}, random::{LegacyRandom, RandomSource}, }; -use horizon_world::registry::{BlockRegistry, BlockStateId}; +use horizon_world::{ + block_render::FaceVisibility, + registry::{BlockRegistry, BlockStateId}, +}; use serde_json::Value; -use std::{collections::HashMap, f32::consts::PI, path::Path}; +use std::{collections::HashMap, f32::consts::PI, path::Path, sync::Mutex}; /// One baked `ModelPart`: initial pose, textured polygons (pixel units, /// normalized UVs) and named children. @@ -289,6 +293,12 @@ enum Kind { pose: &'static str, facing: &'static str, }, + /// `TheEndPortalRenderer`: the top and bottom faces of a 6/16-tall slab. + EndPortal, + /// `TheEndGatewayRenderer`: the visible faces of the cube and the beam. + EndGateway { + state: u32, + }, /// Sign text (`StandingSignRenderer` / `HangingSignRenderer`); the boards are block models. Sign { hanging: bool, @@ -413,6 +423,8 @@ fn classify(name: &str, prop: &dyn Fn(&str) -> Option) -> Kind { }; } "conduit" => return Kind::Conduit, + "end_portal" => return Kind::EndPortal, + "end_gateway" => return Kind::EndGateway { state: 0 }, "enchanting_table" => return Kind::EnchantingTable, "lectern" => { return if prop("has_book").as_deref() == Some("true") { @@ -737,6 +749,8 @@ pub struct BlockAnim { pub sherds: [Option; 4], /// `DecoratedPotRenderState` wobble style (positive) and progress. pub wobble: Option<(bool, f32)>, + /// `TheEndGatewayBlockEntity` age and teleportCooldown. + pub gateway: (i64, i32), } /// One `submitText` call (`AbstractSignRenderer.submitSignText`). @@ -765,6 +779,8 @@ pub struct Scene<'a> { pub texts: Option<&'a std::cell::RefCell>>, pub partial: f32, pub game_time: i64, + /// `Level.getMaxY` (End gateway beams while spawning). + pub max_y: i32, pub world: &'a World, pub sprites: &'a HashMap, pub nether: bool, @@ -785,6 +801,8 @@ pub struct BlockEntityRenderer { random: LegacyRandom, /// Item id to its `PROVIDES_POTTERY_PATTERN` side texture (`Sheets.DECORATED_POT_MAPPER`). pot_patterns: HashMap, + /// `Block.shouldRenderFace` for End gateway faces (its occlusion pair cache needs a lock). + visibility: Option>, } const MODELS: [(&str, &str); 27] = [ ("chest", "minecraft:chest#main"), @@ -835,6 +853,7 @@ impl BlockEntityRenderer { .filter_map(|(key, layer)| all.get(*layer).map(|v| (*key, ModelPart::parse(v)))) .collect(); let mut renderer = Self::new(models, registry); + renderer.visibility = Some(Mutex::new(crate::models::load_visibility(root, registry)?)); // Sherd items: provides_pottery_pattern -> decorated_pot_pattern asset id. if let Ok(bytes) = std::fs::read(root.join("items.json")) { let items: Value = serde_json::from_slice(&bytes)?; @@ -864,7 +883,10 @@ impl BlockEntityRenderer { .map(|id| { registry.state(BlockStateId(id)).map_or(Kind::None, |s| { let prop = |k: &str| s.properties.get(k).cloned(); - classify(&s.name, &prop) + match classify(&s.name, &prop) { + Kind::EndGateway { .. } => Kind::EndGateway { state: id }, + kind => kind, + } }) }) .collect(); @@ -874,6 +896,7 @@ impl BlockEntityRenderer { books: HashMap::new(), random: LegacyRandom::new(0x5EED_B00C), pot_patterns: HashMap::new(), + visibility: None, } } /// The standing banner's pole-and-bar and flag models (`BannerRenderer.submitSpecial`). @@ -921,7 +944,13 @@ impl BlockEntityRenderer { f64::from(pos[1]) + 0.5, f64::from(pos[2]) + 0.5, ); - if center.distance_squared(scene.camera) > VIEW_DISTANCE * VIEW_DISTANCE { + // BlockEntityRenderer.getViewDistance: 256 for End gateways. + let distance = if matches!(kind, Kind::EndGateway { .. }) { + 256.0 + } else { + VIEW_DISTANCE + }; + if center.distance_squared(scene.camera) > distance * distance { continue; } let origin = (DVec3::new(f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])) @@ -1291,6 +1320,73 @@ impl BlockEntityRenderer { } } } + Kind::EndPortal => { + // TheEndPortalRenderer.TRANSFORMATION: y from 6/16 to 12/16; only the + // vertical faces (TheEndPortalBlockEntity.shouldRenderFace). + let m = base + * Mat4::from_translation(Vec3::new(0.0, 0.375, 0.0)) + * Mat4::from_scale(Vec3::new(1.0, 0.375, 1.0)); + portal_cube(m, &[Direction::Down, Direction::Up], END_PORTAL_LAYER, out); + } + Kind::EndGateway { state } => { + let anim = (scene.anim)(pos); + let (age, cooldown) = anim.gateway; + // TheEndGatewayRenderer.extractRenderState. + let spawning = age < 200; + if spawning || cooldown > 0 { + let a = scene.partial; + let percent = if spawning { + ((age as f32 + a) / 200.0).clamp(0.0, 1.0) + } else { + 1.0 - ((cooldown as f32 - a) / 40.0).clamp(0.0, 1.0) + }; + let distance = if spawning { + f64::from(scene.max_y) + } else { + 50.0 + }; + let scale = trig::sin(f64::from(percent * PI)); + let height = (f64::from(scale) * distance).floor() as i32; + // DyeColor.MAGENTA / PURPLE getTextureDiffuseColor. + let color = if spawning { 0xC7_4EBD } else { 0x89_32B8 }; + let time = scene.game_time.rem_euclid(40) as f32 + a; + if height > 0 + && let Some(s) = sprite("entity/end_portal/end_gateway_beam") + { + beam( + base, + BeamShape { + scale, + time, + start: -height, + height: height * 2, + color, + solid_radius: 0.15, + glow_radius: 0.175, + }, + s, + out, + ); + } + } + // AbstractEndPortalRenderer.extractRenderState: TheEndGatewayBlockEntity.shouldRenderFace. + let faces: Vec = Direction::ALL + .into_iter() + .filter(|&d| { + let [dx, dy, dz] = d.normal(); + let neighbor = scene.world.block(pos[0] + dx, pos[1] + dy, pos[2] + dz); + self.visibility.as_ref().is_none_or(|v| { + v.lock() + .map(|mut v| { + v.should_render_face(BlockStateId(*state), neighbor, d, true) + .unwrap_or(true) + }) + .unwrap_or(true) + }) + }) + .collect(); + portal_cube(base, &faces, END_GATEWAY_LAYER, out); + } Kind::Conduit => { let (ticks, active, hunting, raw_rotation) = (scene.anim)(pos).conduit; // ConduitRenderer.extractRenderState. @@ -1438,8 +1534,7 @@ impl BlockEntityRenderer { /// 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). +/// the radius scale. pub fn beacon_beam( origin: Vec3, sections: &[(u32, i32)], @@ -1448,9 +1543,7 @@ pub fn beacon_beam( 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 base = Mat4::from_translation(origin); let mut start = 0i32; for (i, &(color, height)) in sections.iter().enumerate() { let height = if i == sections.len() - 1 { @@ -1458,63 +1551,140 @@ pub fn beacon_beam( } 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; + let shape = BeamShape { + scale: 1.0, + time, + start, + height, + color, + solid_radius: 0.2 * scale, + glow_radius: 0.25 * scale, + }; + beam(base, shape, s, out); + start += height; } } -/// `BeaconRenderer.renderPart`: four quads between the corners (wn, en, ws, es). -#[allow(clippy::too_many_arguments)] -fn beam_part( - out: &mut Vec, - o: Vec3, +/// The arguments of `BeaconRenderer.submitBeaconBeam`. +pub struct BeamShape { + /// Scales the v range (End gateways shrink and grow their beam with it). + pub scale: f32, + /// Animation time: game time mod 40 plus the partial tick. + pub time: f32, + pub start: i32, + pub height: i32, + /// RGB. + pub color: u32, + pub solid_radius: f32, + pub glow_radius: f32, +} +/// `BeaconRenderer.submitBeaconBeam` under `base` (the block's corner): the +/// rotating solid beam and its translucent glow. The sprite's v range rides +/// in the light bytes (the entity shader wraps v for layer 6). +pub fn beam(base: Mat4, b: BeamShape, 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 color = b.color; + let end = b.start + b.height; + let scroll = if b.height < 0 { b.time } else { -b.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, rotated with time. + let r = b.solid_radius; + let rot = glam::Mat3::from_rotation_y((b.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 = b.height as f32 * b.scale * (0.5 / r) + v2; + let part = BeamPart { + base, + start: b.start, + end, + s, + wrap, + }; + part.emit(out, corners, [v1, v2], abgr(255)); + // Glow, translucent. + let g = b.glow_radius; + 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 = b.height as f32 * b.scale + v2; + part.emit(out, corners, [v1, v2], abgr(32)); +} +struct BeamPart { + base: Mat4, 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]), - ] { +} +impl BeamPart { + /// `BeaconRenderer.renderPart`: four quads between the corners (wn, en, ws, es). + fn emit( + &self, + out: &mut Vec, + [wn, en, ws, es]: [Vec3; 4], + [v1, v2]: [f32; 2], + color: u32, + ) { + let s = self.s; + for (a, b) in [(wn, en), (es, ws), (en, es), (ws, wn)] { + let at = |c: Vec3, y: i32| { + self.base + .transform_point3(Vec3::new(0.5, 0.0, 0.5) + c + Vec3::new(0.0, y as f32, 0.0)) + }; + for (p, uv) in [ + (at(a, self.end), [s.u1, v1]), + (at(a, self.start), [s.u1, v2]), + (at(b, self.start), [s.u0, v2]), + (at(b, self.end), [s.u0, v1]), + ] { + out.push(Vertex { + pos: p.to_array(), + uv, + layer: 6, + color, + light: self.wrap, + }); + } + } + } +} + +/// Entity-shader layers for `rendertype_end_portal`: end portals draw 15 +/// layers of `end_portal.png` over `end_sky.png`, End gateways 16. +pub const END_PORTAL_LAYER: u32 = 9; +pub const END_GATEWAY_LAYER: u32 = 10; +/// `AbstractEndPortalRenderer.FACES`: the unit cube's corners for each face +/// (`Direction` order) in `FaceInfo` vertex order. +#[rustfmt::skip] +const PORTAL_FACES: [[[f32; 3]; 4]; 6] = [ + [[0.0, 0.0, 1.0], [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 0.0, 1.0]], + [[0.0, 1.0, 0.0], [0.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 0.0]], + [[1.0, 1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 1.0, 0.0]], + [[0.0, 1.0, 1.0], [0.0, 0.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0]], + [[0.0, 1.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0], [0.0, 1.0, 1.0]], + [[1.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]], +]; +/// `AbstractEndPortalRenderer.submitCube`: position-only quads (the portal +/// shader projects its textures from the screen; uv, colour and light are unused). +fn portal_cube(m: Mat4, faces: &[Direction], layer: u32, out: &mut Vec) { + for &d in faces { + for c in PORTAL_FACES[d as usize] { out.push(Vertex { - pos: p.to_array(), - uv, - layer: 6, - color, - light: wrap, + pos: m.transform_point3(Vec3::from(c)).to_array(), + uv: [0.0; 2], + layer, + color: 0, + light: 0, }); } } diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 667e7d911..697cccc36 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -780,6 +780,13 @@ impl Dim { _ => Self::Overworld, } } + /// `Level.getMaxY`: the dimension type's minimum y plus height, less one. + fn max_y(self) -> i32 { + match self { + Self::Overworld => MIN_Y + HEIGHT - 1, + Self::Nether | Self::End => 255, + } + } } fn facing_offset(facing: &str) -> [i32; 3] { match facing { @@ -4126,10 +4133,16 @@ impl Game<'_> { -view_pitch.to_radians(), 0.0, ), - anim: &|_| horizon_client::block_entity_render::BlockAnim::default(), + // The client does not track End gateway ages and cooldowns yet: + // gateways render as settled (no beam). + anim: &|_| horizon_client::block_entity_render::BlockAnim { + gateway: (i64::MAX, 0), + ..Default::default() + }, texts: None, partial: alpha as f32, game_time: self.world.game_time, + max_y: self.dim.max_y(), world: &self.world, sprites: &self.res.atlas.sprites, nether: self.dim == Dim::Nether, diff --git a/crates/horizon-client/src/game/minecarts.rs b/crates/horizon-client/src/game/minecarts.rs index 967bef7e4..439097c6c 100644 --- a/crates/horizon-client/src/game/minecarts.rs +++ b/crates/horizon-client/src/game/minecarts.rs @@ -1236,6 +1236,7 @@ impl Game<'_> { texts: None, partial: 0.0, game_time: self.world.game_time, + max_y: self.dim.max_y(), world: &self.world, sprites: &self.res.atlas.sprites, nether: self.dim == super::Dim::Nether, From 51d4598632507bc2d1974fc10ca4ef57af560d07 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 12 Oct 2026 13:16:32 +0200 Subject: [PATCH 3/3] Draw End portals and gateways with vanilla's end portal shader The entity shader gains rendertype_end_portal as layers 9 (15 portal layers) and 10 (16 for gateways): end_sky and the rotating, scrolling layers of end_portal.png projected from the screen, repeated inside their atlas sprites, with vanilla's GameTime uniform. The world-space approximation and its portal block scan are gone; the block-entity renderer draws both blocks. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/entity.wgsl | 53 +++++- crates/horizon-client/src/game.rs | 8 + crates/horizon-client/src/game/end.rs | 223 +------------------------ crates/horizon-client/src/gfx.rs | 11 ++ crates/horizon-client/src/terrain.wgsl | 4 + 5 files changed, 78 insertions(+), 221 deletions(-) diff --git a/crates/horizon-client/src/entity.wgsl b/crates/horizon-client/src/entity.wgsl index 043723cbf..8a8a598f7 100644 --- a/crates/horizon-client/src/entity.wgsl +++ b/crates/horizon-client/src/entity.wgsl @@ -11,6 +11,10 @@ struct Globals { sun: vec4, // x: sky fog end, y: cloud fog end fog_ends: vec4, + // Atlas rects (u0, v0, width, height) of end_sky.png and end_portal.png. + end_portal_sprites: array, 2>, + // x: vanilla's GameTime ((game time % 24000 + partial tick) / 24000) + time: vec4, } @group(0) @binding(0) var globals: Globals; @group(0) @binding(1) var atlas: texture_2d; @@ -27,11 +31,14 @@ struct Out { @location(4) @interpolate(flat) overlay: u32, // Overlay 6: the sprite's v origin and height, for v repeated inside it. @location(6) @interpolate(flat) wrap: vec2, + // Overlays 9 and 10: projection_from_position(gl_Position), the End portal's texProj0. + @location(7) proj: vec4, } @vertex fn vs_entity(@location(0) position: vec3, @location(1) uv: vec2, @location(2) overlay: u32, @location(3) color: vec4, @location(4) light: vec4) -> Out { var out: Out; out.clip = globals.view_proj * vec4(position, 1.0); + out.proj = vec4(out.clip.xy * 0.5 + out.clip.w * 0.5, out.clip.zw); out.uv = uv; let l = vec2(f32(light.y), f32(light.x)); let lm = textureSampleLevel(lightmap, lightmap_sampler, @@ -52,6 +59,41 @@ struct Out { if overlay == 4u { out.spherical = length(position); } return out; } +// rendertype_end_portal.fsh: the layer colours. +const PORTAL_COLORS = array, 16>( + vec3(0.022087, 0.098399, 0.110818), + vec3(0.011892, 0.095924, 0.089485), + vec3(0.027636, 0.101689, 0.100326), + vec3(0.046564, 0.109883, 0.114838), + vec3(0.064901, 0.117696, 0.097189), + vec3(0.063761, 0.086895, 0.123646), + vec3(0.084817, 0.111994, 0.166380), + vec3(0.097489, 0.154120, 0.091064), + vec3(0.106152, 0.131144, 0.195191), + vec3(0.097721, 0.110188, 0.187229), + vec3(0.133516, 0.138278, 0.148582), + vec3(0.070006, 0.243332, 0.235792), + vec3(0.196766, 0.142899, 0.214696), + vec3(0.047281, 0.315338, 0.321970), + vec3(0.204675, 0.390010, 0.302066), + vec3(0.080955, 0.314821, 0.661491), +); +// textureProj on a repeating texture that lives in the atlas at `rect`. +fn portal_sample(rect: vec4, p: vec4) -> vec3 { + let st = fract(p.xy / p.w); + return textureSampleLevel(atlas, atlas_sampler, rect.xy + st * rect.zw, 0.0).rgb; +} +// texProj0 * end_portal_layer(layer): the row vector through mat4(scale * rotate), +// translate and SCALE_TRANSLATE in turn. +fn portal_layer(p: vec4, layer: f32) -> vec4 { + let a = radians((layer * layer * 4321.0 + layer * 9.0) * 2.0); + let c = cos(a); + let s = sin(a); + let k = (4.5 - layer / 4.0) * 2.0; + var v = vec4(k * (c * p.x - s * p.y), k * (s * p.x + c * p.y), p.z, p.w); + v = vec4(v.x + 17.0 / layer * v.w, v.y + (2.0 + layer / 1.5) * (globals.time.x * 1.5) * v.w, v.z, v.w); + return vec4(0.5 * v.x + 0.25 * v.w, 0.5 * v.y + 0.25 * v.w, v.z, v.w); +} fn linear_fog(d: f32, start: f32, end: f32) -> f32 { if d <= start { return 0.0; } if d >= end { return 1.0; } @@ -61,7 +103,16 @@ fn linear_fog(d: f32, start: f32, end: f32) -> f32 { var uv = in.uv; if in.overlay == 6u { uv.y = in.wrap.x + fract(in.uv.y) * in.wrap.y; } var color = textureSample(atlas, atlas_sampler, uv) * in.color; - if in.overlay == 4u { + if in.overlay == 9u || in.overlay == 10u { + // rendertype_end_portal: end_sky and PORTAL_LAYERS (15 for portals, 16 + // for gateways) layers of end_portal.png projected from the screen. + let layers = select(15, 16, in.overlay == 10u); + var c = portal_sample(globals.end_portal_sprites[0], in.proj) * PORTAL_COLORS[0]; + for (var i = 0; i < layers; i++) { + c += portal_sample(globals.end_portal_sprites[1], portal_layer(in.proj, f32(i + 1))) * PORTAL_COLORS[i]; + } + color = vec4(c, 1.0); + } else if in.overlay == 4u { // clouds.fsh: alpha fades out towards the cloud fog end. return vec4(color.rgb, color.a * (1.0 - linear_fog(in.spherical, 0.0, globals.fog_ends.y))); } diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 697cccc36..ff8e69082 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7080,6 +7080,14 @@ impl Game<'_> { hand: &hand, screen: &screen, game_time: self.world.game_time as f32, + shader_game_time: ((self.world.game_time % 24000) as f32 + alpha as f32) / 24000.0, + end_portal_sprites: ["environment/end_sky", "entity/end_portal/end_portal"].map(|n| { + self.res + .atlas + .sprites + .get(n) + .map_or([0.0; 4], |r| [r.u0, r.v0, r.u1 - r.u0, r.v1 - r.v0]) + }), ticks: self.ticks, darkness: self.darkness_lighting(alpha as f32), night_vision: self.night_vision_intensity(), diff --git a/crates/horizon-client/src/game/end.rs b/crates/horizon-client/src/game/end.rs index 080525a43..e1a848a25 100644 --- a/crates/horizon-client/src/game/end.rs +++ b/crates/horizon-client/src/game/end.rs @@ -37,10 +37,6 @@ pub(super) struct EndState { job: Option, /// Ticks until the player can use a gateway again (TheEndGatewayBlockEntity cooldown). gateway_cooldown: u32, - /// End portal and gateway blocks per loaded chunk (true = gateway), for rendering. - portals: HashMap<(i32, i32), Vec<([i32; 3], bool)>>, - /// Chunks left to scan for portal blocks in the current round. - scan: Vec<(i32, i32)>, /// The Overworld generator, for stronghold positions (ServerLevel.findNearestMapStructure). locator: std::sync::Mutex>>, /// Thrown eyes of ender in flight. @@ -132,11 +128,6 @@ impl EyeOfEnder { } } -/// Chunks scanned for portal blocks per tick. -const SCAN_PER_TICK: usize = 6; -/// Radius (chunks) around the player in which portal blocks are rendered. -const PORTAL_RADIUS: i32 = 10; - impl Game<'_> { /// The environment attributes of the current dimension. pub(super) fn dim_environment(&self) -> &Environment { @@ -295,7 +286,6 @@ impl Game<'_> { )?; } } - self.rescan_portals_around(c, 1); // Global LevelEvent 1038: END_PORTAL_SPAWN. self.audio .play("minecraft:block.end_portal.spawn", None, 1.0, 1.0); @@ -350,7 +340,6 @@ impl Game<'_> { self.tick_fight(); self.tick_dragon_fireballs(); } - self.scan_portals(); self.tick_eyes(); if self.dim == Dim::End { self.end.flash.tick(self.world.game_time); @@ -645,7 +634,6 @@ impl Game<'_> { let id = registry.resolve(&state)?; self.level_set([origin[0] + d[0], origin[1] + 2, origin[2] + d[1]], id)?; } - self.rescan_portals_around(origin, 4); Ok(()) } @@ -669,7 +657,6 @@ impl Game<'_> { } } } - self.rescan_portals_around(origin, 0); Ok(()) } @@ -887,214 +874,10 @@ impl Game<'_> { Ok(()) } - /// Scan a few loaded chunks per tick for End portal and gateway blocks. - fn scan_portals(&mut self) { - let Some(p) = self.player.as_ref() else { - return; - }; - let (pcx, pcz) = ( - (p.position.x.floor() as i32) >> 4, - (p.position.z.floor() as i32) >> 4, - ); - let chunks = &self.world.chunks; - self.end.portals.retain(|k, _| chunks.contains_key(k)); - if self.end.scan.is_empty() { - let mut queue: Vec<(i32, i32)> = chunks - .keys() - .copied() - .filter(|&(x, z)| { - (x - pcx).abs() <= PORTAL_RADIUS && (z - pcz).abs() <= PORTAL_RADIUS - }) - .collect(); - // Nearest last: they are popped first. - queue.sort_by_key(|&(x, z)| std::cmp::Reverse((x - pcx).pow(2) + (z - pcz).pow(2))); - self.end.scan = queue; - } - for _ in 0..SCAN_PER_TICK { - let Some((cx, cz)) = self.end.scan.pop() else { - break; - }; - self.scan_portal_chunk(cx, cz); - } - } - - fn scan_portal_chunk(&mut self, cx: i32, cz: i32) { - let registry = self.res.assets.registry; - let (Some(portal), Some(gateway)) = ( - registry.default_state("minecraft:end_portal"), - registry.default_state("minecraft:end_gateway"), - ) else { - return; - }; - let (portal, gateway) = (portal.0 as u16, gateway.0 as u16); - let Some(chunk) = self.world.chunks.get(&(cx, cz)) else { - self.end.portals.remove(&(cx, cz)); - return; - }; - let mut found = Vec::new(); - for (s, section) in chunk.sections.iter().enumerate() { - if !section - .blocks - .maybe_has(|v| v == u32::from(portal) || v == u32::from(gateway)) - { - continue; - } - let mut blocks = Box::new([0u16; 4096]); - section.unpack(&mut blocks); - for (i, &b) in blocks.iter().enumerate() { - if b == portal || b == gateway { - let y = horizon_client::chunk::MIN_Y + s as i32 * 16 + (i >> 8) as i32; - found.push(( - [ - cx * 16 + (i & 15) as i32, - y, - cz * 16 + ((i >> 4) & 15) as i32, - ], - b == gateway, - )); - } - } - } - if found.is_empty() { - self.end.portals.remove(&(cx, cz)); - } else { - self.end.portals.insert((cx, cz), found); - } - } - - fn rescan_portals_around(&mut self, p: [i32; 3], r: i32) { - for cz in (p[2] - r) >> 4..=(p[2] + r) >> 4 { - for cx in (p[0] - r) >> 4..=(p[0] + r) >> 4 { - self.scan_portal_chunk(cx, cz); - } - } - } - - /// End portal and gateway surfaces (TheEndPortalRenderer: the starfield - /// approximated by end_portal.png in world space, unanimated) and the End - /// crystals on the spikes, as camera-relative entity geometry. + /// The End crystals on the spikes and thrown eyes of ender, as + /// camera-relative entity geometry (End portals and gateways are block + /// entities). pub(super) fn end_geometry(&self, camera: glam::DVec3, out: &mut Vec) { - let atlas = &self.res.atlas; - if let Some(r) = atlas.sprites.get("entity/end_portal/end_portal").copied() { - let full = (15 * 16) | ((15 * 16) << 8); - // Each block shows a quarter of the texture so neighbours join up. - let quarter = |a: i32, b: i32| { - let (fa, fb) = (a.rem_euclid(4) as f32 / 4.0, b.rem_euclid(4) as f32 / 4.0); - let (du, dv) = (r.u1 - r.u0, r.v1 - r.v0); - ( - r.u0 + du * fa, - r.u0 + du * (fa + 0.25), - r.v0 + dv * fb, - r.v0 + dv * (fb + 0.25), - ) - }; - for blocks in self.end.portals.values() { - for &(p, gateway) in blocks { - let base = glam::DVec3::new(f64::from(p[0]), f64::from(p[1]), f64::from(p[2])) - - camera; - if base.length_squared() > 160.0 * 160.0 { - continue; - } - let b = base.as_vec3(); - // Portal: top face at 12/16 and bottom at 6/16; gateway: the whole cube. - let (y0, y1) = if gateway { (0.0, 1.0) } else { (0.375, 0.75) }; - let color = if gateway { 0xFFE0_E0A0 } else { 0xFFD0_E070 }; - let mut quad = - |corners: [glam::Vec3; 4], (u0, u1, v0, v1): (f32, f32, f32, f32)| { - let uv = [[u0, v0], [u1, v0], [u1, v1], [u0, v1]]; - for (c, uv) in corners.into_iter().zip(uv) { - out.push(Vertex { - pos: (b + c).to_array(), - uv, - layer: 0, - color, - light: full, - }); - } - }; - let v = glam::Vec3::new; - let open = |d: [i32; 3]| { - let n = [p[0] + d[0], p[1] + d[1], p[2] + d[2]]; - !self - .res - .facts - .get(self.world.block(n[0], n[1], n[2])) - .solid_render - }; - let uv_xz = quarter(p[0], p[2]); - if !gateway || open([0, 1, 0]) { - quad( - [ - v(0.0, y1, 0.0), - v(1.0, y1, 0.0), - v(1.0, y1, 1.0), - v(0.0, y1, 1.0), - ], - uv_xz, - ); - } - if !gateway || open([0, -1, 0]) { - quad( - [ - v(0.0, y0, 0.0), - v(1.0, y0, 0.0), - v(1.0, y0, 1.0), - v(0.0, y0, 1.0), - ], - uv_xz, - ); - } - if gateway { - let uv_x = quarter(p[2], p[1]); - let uv_z = quarter(p[0], p[1]); - if open([-1, 0, 0]) { - quad( - [ - v(0.0, 0.0, 0.0), - v(0.0, 0.0, 1.0), - v(0.0, 1.0, 1.0), - v(0.0, 1.0, 0.0), - ], - uv_x, - ); - } - if open([1, 0, 0]) { - quad( - [ - v(1.0, 0.0, 0.0), - v(1.0, 0.0, 1.0), - v(1.0, 1.0, 1.0), - v(1.0, 1.0, 0.0), - ], - uv_x, - ); - } - if open([0, 0, -1]) { - quad( - [ - v(0.0, 0.0, 0.0), - v(1.0, 0.0, 0.0), - v(1.0, 1.0, 0.0), - v(0.0, 1.0, 0.0), - ], - uv_z, - ); - } - if open([0, 0, 1]) { - quad( - [ - v(0.0, 0.0, 1.0), - v(1.0, 0.0, 1.0), - v(1.0, 1.0, 1.0), - v(0.0, 1.0, 1.0), - ], - uv_z, - ); - } - } - } - } - } if self.dim == Dim::End { self.end_crystal_geometry(camera, out); } diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 9654d9ca3..0d3fb6007 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -26,6 +26,10 @@ struct Globals { sun: [f32; 4], /// x: sky fog end, y: cloud fog end, z: dark disc (camera below the horizon), w: unused. fog_ends: [f32; 4], + /// Atlas rects (u0, v0, width, height) of end_sky.png and end_portal.png. + end_portal_sprites: [[f32; 4]; 2], + /// x: vanilla's `GameTime` uniform; yzw unused. + time: [f32; 4], } pub type SectionKey = (i32, i32, i32); struct SectionGpu { @@ -77,6 +81,11 @@ pub struct Frame<'a> { /// Full-screen camera effects drawn over the world and hand, under the HUD. pub screen: &'a [crate::screen_effects::ScreenQuad], pub game_time: f32, + /// `GlobalSettingsUniform` GameTime: (game time % 24000 + partial tick) / 24000. + pub shader_game_time: f32, + /// Atlas rects (u0, v0, width, height) of end_sky.png and end_portal.png + /// (`rendertype_end_portal`'s Sampler0 and Sampler1). + pub end_portal_sprites: [[f32; 4]; 2], pub ticks: u64, /// The darkness effect on the lightmap: the brightness it takes off the /// gamma option and the pulsing scale subtracted from the light. @@ -1281,6 +1290,8 @@ impl Renderer { if frame.dark_disc { 1.0 } else { 0.0 }, 0.0, ], + end_portal_sprites: frame.end_portal_sprites, + time: [frame.shader_game_time, 0.0, 0.0, 0.0], }; self.queue .write_buffer(&self.globals, 0, bytemuck::bytes_of(&globals)); diff --git a/crates/horizon-client/src/terrain.wgsl b/crates/horizon-client/src/terrain.wgsl index 806d5e845..ffef6d640 100644 --- a/crates/horizon-client/src/terrain.wgsl +++ b/crates/horizon-client/src/terrain.wgsl @@ -14,6 +14,10 @@ struct Globals { sun: vec4, // x: sky fog end, y: cloud fog end, z: dark disc flag fog_ends: vec4, + // Atlas rects (u0, v0, width, height) of end_sky.png and end_portal.png. + end_portal_sprites: array, 2>, + // x: vanilla's GameTime ((game time % 24000 + partial tick) / 24000) + time: vec4, } @group(0) @binding(0) var globals: Globals; @group(0) @binding(1) var sprites: texture_2d_array;