Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

OptiFine emissive textures: armour stands, elytra and the dragon glow too

some-du6ed27c2b4f8b01
diff --git a/crates/horizon-client-render/src/hud.rs b/crates/horizon-client-render/src/hud.rs
index 1e4270dbb..0e9680767 100644
--- a/crates/horizon-client-render/src/hud.rs
+++ b/crates/horizon-client-render/src/hud.rs
@@ -144,6 +144,18 @@ pub fn decode_bytes(data: &[u8]) -> Result<(u32, u32, Vec<u8>)> {
/// The most texels of OptiFine random entity variants the entity atlas packs: 2048 rows of
/// its 4096, which keeps the default atlas (4096x5120) under the 8192 rows many GPUs take.
const RANDOM_TEXELS: u64 = 4096 * 2048;
+/// The variant images (and `overlays`) the atlas packs: every variant before any overlay, by
+/// name, while their sizes add up to at most `budget` texels. A full budget drops glows before
+/// looks.
+fn budgeted<'a>(
+ files: impl Iterator<Item = &'a PathBuf>,
+ overlays: &HashSet<PathBuf>,
+ budget: u64,
+) -> HashSet<PathBuf> {
+ let mut files: Vec<&PathBuf> = files.collect();
+ files.sort_by_key(|p| (overlays.contains(*p), *p));
+ within_budget(&files, budget)
+}
/// The `files` (in order) whose sizes add up to at most `budget` texels.
fn within_budget(files: &[&PathBuf], budget: u64) -> HashSet<PathBuf> {
let mut texels = 0u64;
@@ -761,15 +773,12 @@ impl HudAtlas {
// A pack's variants can't grow the shared atlas past what a GPU takes: every variant
// (those beside their texture too) counts, in name order, and those past the budget
// stay out (their mobs wear the texture itself), not the whole pack.
- // Overlays only after every variant: a full budget drops glows, not looks.
let overlays: HashSet<PathBuf> = emissive.files().map(|(f, _)| root.join(f)).collect();
- let mut variants: Vec<&PathBuf> = named.keys().collect();
- variants.sort_by_key(|p| (overlays.contains(*p), *p));
- let kept = within_budget(&variants, RANDOM_TEXELS);
- if kept.len() < variants.len() {
+ let kept = budgeted(named.keys(), &overlays, RANDOM_TEXELS);
+ if kept.len() < named.len() {
log::warn!(
"{} random entity textures left out of the atlas: past its budget",
- variants.len() - kept.len()
+ named.len() - kept.len()
);
}
files.retain(|p| !named.contains_key(p) || kept.contains(p));
@@ -2591,6 +2600,13 @@ mod tests {
let kept = within_budget(&refs, 600);
assert_eq!(kept, files[..2].iter().cloned().collect());
assert_eq!(within_budget(&refs, 768).len(), 3);
+ // a2's overlay sorts before a3 by name, but every variant comes first.
+ let overlay = dir.join("a2_e.png");
+ write_strip(&overlay, 16, 16, &[[1, 2, 3, 255]], None);
+ let overlays: HashSet<PathBuf> = [overlay.clone()].into();
+ let all = [&files[0], &overlay, &files[1]];
+ let kept = budgeted(all.into_iter(), &overlays, 600);
+ assert_eq!(kept, [files[0].clone(), files[1].clone()].into());
fs::remove_dir_all(&dir).unwrap();
}
#[test]
diff --git a/crates/horizon-client/src/game/armor_stands.rs b/crates/horizon-client/src/game/armor_stands.rs
index 12654be7d..329c5513b 100644
--- a/crates/horizon-client/src/game/armor_stands.rs
+++ b/crates/horizon-client/src/game/armor_stands.rs
@@ -816,6 +816,12 @@ impl Game<'_> {
alpha: f64,
out: &mut Vec<Vertex>,
) {
+ let emissive = self
+ .res
+ .mob_data()
+ .emissive
+ .read()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
for a in &self.armor_stands {
let entity_start = out.len();
// ArmorStand.shouldRenderAtSqrDistance: 256 times the box's mean
@@ -990,6 +996,19 @@ impl Game<'_> {
if i == 0 { overlay } else { 0 },
out,
);
+ // The layer's OptiFine emissive overlay, full bright without the glint.
+ if let Some(glow) = emissive.overlay(texture).and_then(|e| uv_of(e)) {
+ horizon_client::mobs::render::draw(
+ part,
+ base,
+ &layer_poses,
+ glow,
+ color,
+ horizon_client::mobs::render::FULL_BRIGHT,
+ 0,
+ out,
+ );
+ }
}
// EquipmentLayerRenderer: the trim layer over the armour.
if let Some(trim) = assets
diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs
index 45ae1cc4a..cc1d5da7b 100644
--- a/crates/horizon-client/src/game/dragon.rs
+++ b/crates/horizon-client/src/game/dragon.rs
@@ -2752,6 +2752,19 @@ impl Game<'_> {
if let Some(mask) = mask {
dissolve_mask(&mut out[first..], skin, mask);
}
+ // The skin's OptiFine emissive overlay, full bright.
+ let glow = self
+ .res
+ .mob_data()
+ .emissive
+ .read()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .overlay("entity/enderdragon/dragon")
+ .and_then(|e| sprite(e));
+ if let Some(glow) = glow.filter(|_| mask.is_none()) {
+ let full = horizon_client::mobs::render::FULL_BRIGHT;
+ horizon_client::mobs::render::draw(model, base, &poses, glow, color, full, 0, out);
+ }
// RenderTypes.eyes: the glowing eyes, added on top.
let mut eye_quads = Vec::new();
horizon_client::mobs::render::draw(
diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs
index 235b37d17..f3d7968a4 100644
--- a/crates/horizon-client/src/game/perspective.rs
+++ b/crates/horizon-client/src/game/perspective.rs
@@ -897,25 +897,54 @@ impl Game<'_> {
return;
};
let base = base * glam::Mat4::from_translation(glam::Vec3::new(0.0, 0.0, 0.125));
+ let pose = |part: &horizon_client::mobs::Part| {
+ let mut p = part.pose;
+ if part.name == "left_wing" || part.name == "right_wing" {
+ let invert = if part.name == "left_wing" { 1.0 } else { -1.0 };
+ p[1] = if crouching { 3.0 } else { 0.0 };
+ p[3] = angles[0];
+ p[4] = invert * angles[1];
+ p[5] = invert * angles[2];
+ }
+ p
+ };
horizon_client::mobs::render_model(
model,
base,
- &|part| {
- let mut p = part.pose;
- if part.name == "left_wing" || part.name == "right_wing" {
- let invert = if part.name == "left_wing" { 1.0 } else { -1.0 };
- p[1] = if crouching { 3.0 } else { 0.0 };
- p[3] = angles[0];
- p[4] = invert * angles[1];
- p[5] = invert * angles[2];
- }
- p
- },
+ &pose,
[rect.u0, rect.v0, rect.u1, rect.v1],
light,
overlay,
out,
);
+ // The elytra texture's OptiFine emissive overlay (not a cape's), full bright.
+ let glow = cape
+ .and_then(|c| sprites.get(c))
+ .is_none()
+ .then(|| {
+ let emissive = self
+ .res
+ .mob_data()
+ .emissive
+ .read()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ emissive
+ .overlay(texture)
+ .and_then(|e| sprites.get(e))
+ .copied()
+ })
+ .flatten();
+ if let Some(g) = glow {
+ horizon_client::mobs::render_model(
+ model,
+ base,
+ &pose,
+ [g.u0, g.v0, g.u1, g.v1],
+ horizon_client::mobs::render::FULL_BRIGHT,
+ 0,
+ out,
+ );
+ }
}
/// `CapeLayer` for a player wearing `chest`: no cape under an elytra's
/// wings, and moved out over a chestplate.
diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs
index 4e3002bbc..5f29dcda2 100644
--- a/crates/horizon-client/src/mobs/render.rs
+++ b/crates/horizon-client/src/mobs/render.rs
@@ -39,7 +39,7 @@ fn scroll_u(u: f32, scroll: f32) -> f32 {
if scroll == 0.0 { u } else { (u + scroll) % 1.0 }
}
/// Full sky and block light in a vertex's `light`.
-const FULL_BRIGHT: u32 = 240 | 240 << 8;
+pub const FULL_BRIGHT: u32 = 240 | 240 << 8;
/// How brightly the eyes render type's layers (spiders', endermen's and
/// phantoms' eyes, the breeze's, the creaking's, the copper golem's) shine in
/// HDR output, as `mesher::hdr_tier`.
@@ -3306,10 +3306,36 @@ mod emissive_tests {
assert_eq!(v.len(), 8);
assert!(inside(&v[4..], 0.75), "its own overlay, not silverfish_e");
} else {
- assert_eq!(v.len(), 4, "zombie_e.png doesn't glow over zombie3.png");
+ assert_eq!(v.len(), 4, "silverfish_e doesn't glow over silverfish2");
}
}
}
+
+ #[test]
+ fn worn_armour_glows_when_its_extra_layer_says_so() {
+ let m = silverfish();
+ let data = data(&[]);
+ let atlas = |_: &str| Some([0.0, 0.0, 0.5, 0.5]);
+ let part = m.kind.model.clone();
+ let extra = [
+ (part.as_ref(), [0.5, 0.0, 1.0, 0.5], 0xFFFF_FFFF, 0, false),
+ (part.as_ref(), [0.5, 0.5, 1.0, 1.0], 0xFFFF_FFFF, 0, true),
+ ];
+ let mut out = Vec::new();
+ render_with(
+ &m,
+ 0.0,
+ glam::DVec3::ZERO,
+ &atlas,
+ 7,
+ &data,
+ &extra,
+ &mut out,
+ );
+ assert_eq!(out.len(), 12, "body, armour, armour's glow");
+ assert!(out[..8].iter().all(|v| v.light == 7));
+ assert!(out[8..].iter().all(|v| v.light == FULL_BRIGHT));
+ }
}
#[cfg(test)]
diff --git a/crates/horizon-optifine/src/emissive.rs b/crates/horizon-optifine/src/emissive.rs
index 233cc99aa..ea7e659bc 100644
--- a/crates/horizon-optifine/src/emissive.rs
+++ b/crates/horizon-optifine/src/emissive.rs
@@ -8,8 +8,8 @@
//! `zombie3`, never over `zombie`.
//!
//! This pairs entity textures, those under `textures/entity/` (mobs' and block entities'), by
-//! the entity atlas's names ([`crate::random_textures`]); blocks and items have their own
-//! atlas.
+//! the entity atlas's names ([`crate::random_textures`]); the game draws mobs' overlays.
+//! Blocks and items have their own atlas.
//!
//! Written from OptiFine's `emissive.properties` and ETF's `EMISSIVE_GUIDE.md` and
//! `emissive.properties`; no mod's source was read.
@@ -240,19 +240,11 @@ mod tests {
);
// Nothing that could leave the texture's folder.
for bad in [
- &b"suffix.emissive=\\\\..\\\\x"[..],
+ &b"suffix.emissive=_a\\\\b"[..],
b"suffix.emissive=/x",
b"suffix.emissive=..",
] {
- assert_eq!(
- suffix(&[
- (PROPERTIES[0], bad),
- (PROPERTIES[1], b""),
- (PROPERTIES[2], b""),
- (PROPERTIES[2], b"")
- ]),
- "_e"
- );
+ assert_eq!(suffix(&[(PROPERTIES[0], bad)]), "_e");
}
}