Merge pull request #1769 from ludovic111/feat/shader-packs-entity-spans
🤖 Agent: shader packs clean room: main merged into the stack (merge commits), verify passed on this head, parity skipped by parity-scope.
This commit is contained in:
@@ -1243,6 +1243,11 @@ struct Game<'a> {
|
||||
luminance: Option<horizon_client::dynamic_light::Luminance>,
|
||||
/// Name tags drawn over everything (`RenderPipelines.TEXT_SEE_THROUGH`).
|
||||
see_through_vertices: Vec<Vertex>,
|
||||
/// Runs of `entity_vertices` by entity, for a shader pack's per-entity draws; recorded only
|
||||
/// while `pack_ids` is set (game/shader_packs.rs).
|
||||
entity_spans: std::cell::RefCell<Vec<horizon_client::gfx::pack_draw::EntitySpan>>,
|
||||
/// The shader pack's entity and block entity ids, while one draws entities.
|
||||
pack_ids: Option<shader_packs::PackIds>,
|
||||
started: Instant,
|
||||
previous: Instant,
|
||||
/// FramerateLimitTracker.latestInputTime.
|
||||
@@ -6760,8 +6765,10 @@ impl Game<'_> {
|
||||
alpha: f64,
|
||||
mut out: Vec<Vertex>,
|
||||
) -> Vec<Vertex> {
|
||||
self.entity_spans.borrow_mut().clear();
|
||||
self.prepare_entity_culling(camera);
|
||||
self.prepare_trims();
|
||||
self.mark_entity(out.len(), "minecraft:entity_flame");
|
||||
let fire_yaw = if self.camera_type == perspective::CameraType::ThirdPersonFront {
|
||||
self.yaw + 180.0
|
||||
} else {
|
||||
@@ -6853,21 +6860,28 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
// `ItemEntityRenderer`.
|
||||
self.mark_entity(out.len(), "minecraft:item");
|
||||
self.dropped_item_geometry(camera, alpha, &mut out);
|
||||
// `VaultRenderer`.
|
||||
self.mark_entity(out.len(), "");
|
||||
self.vault_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:ominous_item_spawner");
|
||||
self.ominous_item_spawner_geometry(camera, alpha, &mut out);
|
||||
// Mobs and their projectiles.
|
||||
// Mobs and their projectiles (a span each).
|
||||
self.mob_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:player");
|
||||
self.player_model_geometry(camera, self.clock.camera_fraction(), &mut out);
|
||||
self.guest_model_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:evoker_fangs");
|
||||
self.fangs_geometry(camera, alpha, &mut out);
|
||||
let mut see_through = std::mem::take(&mut self.see_through_vertices);
|
||||
see_through.clear();
|
||||
self.mark_entity(out.len(), "minecraft:name_tag");
|
||||
self.name_tag_geometry(camera, alpha, &mut out, &mut see_through);
|
||||
self.text_display_geometry(camera, alpha, &mut out, &mut see_through);
|
||||
self.see_through_vertices = see_through;
|
||||
// Entity shadows (EntityRenderer.extractShadow).
|
||||
self.mark_entity(out.len(), "minecraft:entity_shadow");
|
||||
if let Some(sprite) = self.gui.atlas.sprites.get("misc/shadow").copied() {
|
||||
let ambient = if self.dim == Dim::Nether { 0.1 } else { 0.0 };
|
||||
let darken = self.sky_darken();
|
||||
@@ -6961,13 +6975,14 @@ impl Game<'_> {
|
||||
v.intersects(o - glam::Vec3::ONE, o + glam::Vec3::splat(2.0))
|
||||
})
|
||||
});
|
||||
if self.entity_culler.is_some() {
|
||||
if self.entity_culler.is_some() || self.pack_ids.is_some() {
|
||||
for block in visible {
|
||||
let start = out.len();
|
||||
self.mark_block_entity(start, block.1);
|
||||
self.res
|
||||
.block_entity_render()
|
||||
.render(&scene, std::iter::once(block), &mut out);
|
||||
if !off_screen(block.1) {
|
||||
if !off_screen(block.1) && self.entity_culler.is_some() {
|
||||
self.cull_entity_vertices(&mut out, start);
|
||||
}
|
||||
}
|
||||
@@ -6976,6 +6991,7 @@ impl Game<'_> {
|
||||
.block_entity_render()
|
||||
.render(&scene, visible, &mut out);
|
||||
}
|
||||
self.mark_stage(out.len(), "DESTROY");
|
||||
for (pos, stage) in self.cracks(camera) {
|
||||
let state = self.world.block(pos[0], pos[1], pos[2]);
|
||||
self.res
|
||||
@@ -6984,6 +7000,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
// Experience orbs (ExperienceOrbRenderer): pulsing billboards from a 4x4 icon sheet.
|
||||
self.mark_entity(out.len(), "minecraft:experience_orb");
|
||||
if let Some(r) = self
|
||||
.gui
|
||||
.atlas
|
||||
@@ -7047,6 +7064,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
// Falling blocks use their baked model, including non-cubic shapes.
|
||||
self.mark_entity(out.len(), "minecraft:falling_block");
|
||||
for f in &self.falling {
|
||||
let Some((_, tint)) = self.block_face_sprite(f.state) else {
|
||||
continue;
|
||||
@@ -7077,20 +7095,34 @@ impl Game<'_> {
|
||||
vertex.color = horizon_client::hud_layout::multiply(vertex.color, tint);
|
||||
}
|
||||
}
|
||||
self.mark_entity(out.len(), "");
|
||||
self.moving_piston_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:tnt");
|
||||
self.tnt_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:painting");
|
||||
self.painting_geometry(camera, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:item_frame");
|
||||
self.frame_geometry(camera, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:armor_stand");
|
||||
self.armor_stand_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:oak_boat");
|
||||
self.boat_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:minecart");
|
||||
self.cart_geometry(camera, alpha, &mut out);
|
||||
self.mark_stage(out.len(), "BLOCK_ENTITIES");
|
||||
self.beacon_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:fishing_bobber");
|
||||
self.fishing_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:leash_knot");
|
||||
self.leash_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:trident");
|
||||
self.trident_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:firework_rocket");
|
||||
self.rocket_geometry(camera, alpha, &mut out);
|
||||
self.mark_entity(out.len(), "minecraft:splash_potion");
|
||||
self.thrown_potion_geometry(camera, alpha, &mut out);
|
||||
// Particles (ParticleEngine.extract): camera-facing quads.
|
||||
self.mark_stage(out.len(), "PARTICLES");
|
||||
let world = &self.world;
|
||||
self.particles.render(
|
||||
camera,
|
||||
@@ -7101,6 +7133,7 @@ impl Game<'_> {
|
||||
&mut out,
|
||||
);
|
||||
// Breaking progress overlays (destroy_stage_0..9): ours and the other players'.
|
||||
self.mark_stage(out.len(), "DESTROY");
|
||||
for (pos, stage) in self.cracks(camera) {
|
||||
let o = (glam::DVec3::new(f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2]))
|
||||
- camera)
|
||||
@@ -10212,6 +10245,7 @@ impl Game<'_> {
|
||||
} else {
|
||||
self.shader_pack_inputs(camera, alpha as f32)
|
||||
};
|
||||
let entity_spans = std::mem::take(self.entity_spans.get_mut());
|
||||
let frame = Frame {
|
||||
weather: &weather,
|
||||
weather_time: horizon_client::weather::Time::new(self.world.game_time, alpha as f32),
|
||||
@@ -10276,6 +10310,7 @@ impl Game<'_> {
|
||||
color: sky.cloud_color,
|
||||
}),
|
||||
entities: &entities,
|
||||
entity_spans: &entity_spans,
|
||||
dynamic_lights: &self.dynamic_lights,
|
||||
lightning: horizon_client::gfx::lightning::Input {
|
||||
bolts: &bolts,
|
||||
@@ -10327,6 +10362,7 @@ impl Game<'_> {
|
||||
};
|
||||
// Restore storage even when rendering fails (for example, a lost surface).
|
||||
self.entity_vertices = entities;
|
||||
*self.entity_spans.get_mut() = entity_spans;
|
||||
self.see_through_vertices = see_through;
|
||||
result
|
||||
}
|
||||
@@ -11922,6 +11958,8 @@ impl<'a> Game<'a> {
|
||||
dynamic_lights: Vec::new(),
|
||||
luminance: None,
|
||||
see_through_vertices: Vec::new(),
|
||||
entity_spans: Default::default(),
|
||||
pack_ids: None,
|
||||
health_hud: hud_layout::HealthHud::default(),
|
||||
started: now,
|
||||
previous: now,
|
||||
@@ -12857,6 +12895,7 @@ fn loading_frame(hud: &HudBatch) -> Frame<'_> {
|
||||
hud,
|
||||
nether_lighting: false,
|
||||
entities: &[],
|
||||
entity_spans: &[],
|
||||
dynamic_lights: &[],
|
||||
clouds: None,
|
||||
lightning: Default::default(),
|
||||
|
||||
@@ -3031,6 +3031,7 @@ impl Game<'_> {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
self.mark_entity(entity_start, &mob.kind.id);
|
||||
let light = self.world.light(
|
||||
mob.position.x.floor() as i32,
|
||||
(mob.position.y + mob.eye_height()).floor() as i32,
|
||||
|
||||
@@ -7,6 +7,21 @@ use horizon_client::gfx::pack_uniforms::PackInputs;
|
||||
use horizon_shaders::{BlockIds, Macros, Pack, Properties, dimension_folder, load_post};
|
||||
|
||||
use super::{Dim, Game};
|
||||
use horizon_client::gfx::pack_draw::EntitySpan;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// The ids a pack gives entities and block entities (4.1, 5.3), for the spans of the entity
|
||||
/// geometry.
|
||||
pub(super) struct PackIds {
|
||||
entities: HashMap<String, i32>,
|
||||
blocks: BlockIds,
|
||||
/// `blockEntityId` by block state, filled as states are drawn.
|
||||
block_states: RefCell<HashMap<u32, i32>>,
|
||||
/// The id of a name the file lacks: 65535, or 0 without the file.
|
||||
missing_entity: i32,
|
||||
missing_block: i32,
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// Loads the pack for the current dimension when it changed, and returns this frame's
|
||||
@@ -52,6 +67,18 @@ impl Game<'_> {
|
||||
for note in &ids.notes {
|
||||
log::warn!("shader pack {name}: block.properties: {note}");
|
||||
}
|
||||
let text = pack.read_text("entity.properties");
|
||||
let entities = BlockIds::parse_kind(
|
||||
&Properties::parse(text.as_deref().unwrap_or_default(), ¯os),
|
||||
"entity",
|
||||
);
|
||||
self.pack_ids = Some(PackIds {
|
||||
entities: entities.plain(),
|
||||
missing_entity: if text.is_some() { 65535 } else { 0 },
|
||||
missing_block: if ids.is_empty() { 0 } else { 65535 },
|
||||
blocks: ids.clone(),
|
||||
block_states: RefCell::default(),
|
||||
});
|
||||
let started_ids = std::time::Instant::now();
|
||||
let table = block_id_table(&self.pack, &ids);
|
||||
log::info!(
|
||||
@@ -75,6 +102,7 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
self.pack_ids = None;
|
||||
log::warn!("shader pack {name}: {e}");
|
||||
renderer.set_shader_pack(dimension, None, &[]);
|
||||
}
|
||||
@@ -114,6 +142,58 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// Starts a span of the entity geometry at vertex `start` for entity type `name`
|
||||
/// (`minecraft:zombie`; "" for one the pack cannot name). Nothing without a pack.
|
||||
pub(super) fn mark_entity(&self, start: usize, name: &str) {
|
||||
if let Some(ids) = &self.pack_ids {
|
||||
let id = ids.entities.get(name).copied();
|
||||
self.push_span(start, "ENTITIES", id.unwrap_or(ids.missing_entity));
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts a span for the block entity of block state `state`.
|
||||
pub(super) fn mark_block_entity(&self, start: usize, state: u32) {
|
||||
let Some(ids) = &self.pack_ids else { return };
|
||||
let id = *ids
|
||||
.block_states
|
||||
.borrow_mut()
|
||||
.entry(state)
|
||||
.or_insert_with(|| {
|
||||
let registry = self.pack.assets.registry;
|
||||
registry
|
||||
.state(horizon_world::registry::BlockStateId(state))
|
||||
.and_then(|s| {
|
||||
ids.blocks
|
||||
.id(&s.name, |k| s.properties.get(k).map(String::as_str))
|
||||
})
|
||||
.unwrap_or(ids.missing_block)
|
||||
});
|
||||
self.push_span(start, "BLOCK_ENTITIES", id);
|
||||
}
|
||||
|
||||
/// Starts a span of geometry that is not an entity (`PARTICLES`, `DESTROY`...).
|
||||
pub(super) fn mark_stage(&self, start: usize, stage: &str) {
|
||||
if self.pack_ids.is_some() {
|
||||
self.push_span(start, stage, 0);
|
||||
}
|
||||
}
|
||||
|
||||
fn push_span(&self, start: usize, stage: &str, id: i32) {
|
||||
let mut spans = self.entity_spans.borrow_mut();
|
||||
let span = EntitySpan {
|
||||
start: start as u32,
|
||||
stage: horizon_shaders::render_stage(stage),
|
||||
id,
|
||||
};
|
||||
// A span that drew nothing gives way to the next.
|
||||
match spans.last_mut() {
|
||||
Some(last) if last.start == span.start => *last = span,
|
||||
_ => spans.push(span),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `mc_Entity` (x, y) of each block sprite layer, as (id, fluid) pairs: terrain vertices carry
|
||||
/// their sprite layer, not their block. A layer takes the id of the block named like its sprite
|
||||
/// (`block/oak_leaves` for `oak_leaves`), else the id most blocks drawing it share (ties: the
|
||||
|
||||
@@ -69,7 +69,7 @@ pub mod lightning;
|
||||
mod lod;
|
||||
mod occlusion;
|
||||
mod pack_atlas;
|
||||
mod pack_draw;
|
||||
pub mod pack_draw;
|
||||
mod pack_post;
|
||||
mod pack_sky;
|
||||
mod pack_timing;
|
||||
@@ -248,6 +248,8 @@ pub struct Frame<'a> {
|
||||
pub nether_lighting: bool,
|
||||
/// Camera-relative entity geometry textured from the shared atlas.
|
||||
pub entities: &'a [Vertex],
|
||||
/// Runs of `entities` by entity, while a shader pack draws them (`pack_draw::EntitySpan`).
|
||||
pub entity_spans: &'a [pack_draw::EntitySpan],
|
||||
pub weather: &'a [crate::weather::Vertex],
|
||||
pub weather_time: crate::weather::Time,
|
||||
/// Horizon Extras' dynamic lights, nearest first (`dynamic_light::select`); empty when off.
|
||||
|
||||
@@ -4,6 +4,20 @@
|
||||
|
||||
use horizon_shaders::{RENDER_STAGES, render_stage};
|
||||
|
||||
/// Where a run of `Frame::entities` begins, and what it is (slice 7): the run lasts until the
|
||||
/// next span. Recorded only while a shader pack draws entities, so Horizon's own frames carry
|
||||
/// none; Horizon itself still draws the whole list at once.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct EntitySpan {
|
||||
/// The first vertex.
|
||||
pub start: u32,
|
||||
/// The render stage (5.4: `ENTITIES`, `BLOCK_ENTITIES`, `PARTICLES`, `DESTROY`), which picks
|
||||
/// the program.
|
||||
pub stage: u32,
|
||||
/// `entityId` for entities, `blockEntityId` for block entities (5.3), else 0.
|
||||
pub id: i32,
|
||||
}
|
||||
|
||||
/// `HzDraw`'s size: `renderStage`, `entityId`, `blockEntityId`, a pad, `entityColor`.
|
||||
const SIZE: u32 = 32;
|
||||
|
||||
|
||||
@@ -23,9 +23,16 @@ pub struct BlockIds {
|
||||
|
||||
impl BlockIds {
|
||||
pub fn parse(properties: &Properties) -> Self {
|
||||
Self::parse_kind(properties, "block")
|
||||
}
|
||||
|
||||
/// The same for `<kind>.<id>=` lines: `entity` in `entity.properties`, `item` in
|
||||
/// `item.properties` (4.1); names there carry no state filters.
|
||||
pub fn parse_kind(properties: &Properties, kind: &str) -> Self {
|
||||
let mut out = Self::default();
|
||||
let prefix = format!("{kind}.");
|
||||
for e in &properties.entries {
|
||||
let Some(id) = e.key.strip_prefix("block.") else {
|
||||
let Some(id) = e.key.strip_prefix(prefix.as_str()) else {
|
||||
continue;
|
||||
};
|
||||
let Ok(id) = id.parse::<i32>() else {
|
||||
@@ -78,6 +85,16 @@ impl BlockIds {
|
||||
.map(|r| r.id)
|
||||
}
|
||||
|
||||
/// Every name without state filters and its id (the first line naming it wins): what
|
||||
/// `entity.properties` and `item.properties` hold.
|
||||
pub fn plain(&self) -> std::collections::HashMap<String, i32> {
|
||||
let mut out = std::collections::HashMap::new();
|
||||
for r in self.rules.iter().filter(|r| r.filters.is_empty()) {
|
||||
out.entry(r.name.clone()).or_insert(r.id);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.rules.is_empty()
|
||||
}
|
||||
@@ -117,4 +134,18 @@ mod tests {
|
||||
assert_eq!(ids.id("minecraft:oak_leaves", leaves("false", "1")), None);
|
||||
assert_eq!(ids.notes.len(), 1, "{:?}", ids.notes);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entity_lines_by_name() {
|
||||
let text = "entity.10=zombie minecraft:husk\nentity.11=zombie mod:thing\nblock.5=stone\n";
|
||||
let ids = BlockIds::parse_kind(&Properties::parse(text, &Macros::standard()), "entity");
|
||||
let plain = ids.plain();
|
||||
assert_eq!(
|
||||
plain["minecraft:zombie"], 10,
|
||||
"the first line naming it wins"
|
||||
);
|
||||
assert_eq!(plain["minecraft:husk"], 10);
|
||||
assert_eq!(plain["mod:thing"], 11);
|
||||
assert!(!plain.contains_key("minecraft:stone"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user