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 CTM orient=texture: review fixes, merged with the chained-tile branch

some-du6e8057c41c069c
diff --cc crates/horizon-client-render/src/connected.rs
index 11ecf0414,aefcc592e..431812504
--- a/crates/horizon-client-render/src/connected.rs
+++ b/crates/horizon-client-render/src/connected.rs
@@@ -478,8 -517,7 +539,12 @@@ impl ConnectedTextures
};
let axes = |face| match (rule.orient, info.axis) {
(Orient::StateAxis, Some(axis)) => Axes::column(face, axis),
- // `orient=texture` follows the quad's own UVs; vanilla cubes are what it is used on.
+ // The quad's own texture directions, whatever face `symmetry` stands it for.
- (Orient::Texture, _) => texture().unwrap_or(Axes::cube(face)),
++ // Not for `overlay`, which Continuity's `orient` leaves out: its 17 tiles always face
++ // the standard way.
++ (Orient::Texture, _) if rule.method != Method::Overlay => {
++ texture().unwrap_or(Axes::cube(face))
++ }
_ => Axes::cube(face),
};
let mask = || geometry::neighbours(axes(face), face.normal(), rule.inner_seams, joins);
@@@ -1099,38 -1107,49 +1164,108 @@@ mod tests
assert_eq!(pick_in(&ctm, 1, 3, Face::Up, &[]), tile(2000));
}
+ #[test]
+ fn orient_texture_follows_the_quads_uvs() {
+ let rule = |orient: &str| {
+ world(&[(
+ "glass.properties",
+ &*format!("matchBlocks=glass\nmethod=horizontal\ntiles=0-3\norient={orient}"),
+ )])
+ };
+ // A mirrored north face (a vanilla pane's): its texture's right is east.
+ let mirrored = || {
+ Some(Axes {
+ right: [1, 0, 0],
+ up: [0, 1, 0],
+ })
+ };
+ let east = |o: [i32; 3]| if o == [1, 0, 0] { 1 } else { 0 };
+ let at = |ctm: &ConnectedTextures| {
+ ctm.pick(
+ 1,
+ 3,
+ Face::North,
+ [0, 64, 0],
+ east,
+ || None,
+ mirrored,
+ |_| {},
+ )
+ };
+ // Glass to the east is to the texture's right: the row's left end.
+ assert_eq!(at(&rule("texture")), tile(1000));
+ // By the cube's directions it is to the left: the row's right end.
+ assert_eq!(at(&rule("none")), tile(1002));
++ // A plain overlay keeps the standard directions: glass north of a top face is above it
++ // (tile 15) whatever the quad's texture says.
++ let overlay = world(&[(
++ "a.properties",
++ "matchBlocks=stone\nmethod=overlay\nconnectBlocks=glass\ntiles=0-16\norient=texture",
++ )]);
++ let turned = || {
++ Some(Axes {
++ right: [0, 0, 1],
++ up: [1, 0, 0],
++ })
++ };
++ let north = |o: [i32; 3]| if o == [0, 0, -1] { 1 } else { 0 };
++ let mut got = Vec::new();
++ overlay.pick(
++ 2,
++ 7,
++ Face::Up,
++ [0, 64, 0],
++ north,
++ || None,
++ turned,
++ |o| got.push(o.layer),
++ );
++ assert_eq!(got, [1015]);
++ }
++
+ #[test]
+ fn stacked_panes_hide_the_strips_they_share() {
+ let props = |pairs: &[(&str, &str)]| -> BlockProperties {
+ pairs
+ .iter()
+ .map(|(k, v)| (k.to_string(), v.to_string()))
+ .collect()
+ };
+ // 0 a pane with north and east arms, 1 the same pane with only a north arm, 2 another
+ // pane block, 3 a pane no rule names.
+ let states = [
+ (
+ "minecraft:glass_pane",
+ props(&[("north", "true"), ("east", "true")]),
+ ),
+ ("minecraft:glass_pane", props(&[("north", "true")])),
+ (
+ "minecraft:white_stained_glass_pane",
+ props(&[("north", "true")]),
+ ),
+ ("minecraft:iron_bars", props(&[("north", "true")])),
+ ];
+ let ctm = ConnectedTextures::build(
+ rules(&[(
+ "pane.properties",
+ "matchBlocks=glass_pane white_stained_glass_pane\nmethod=ctm\ntiles=0-46",
+ )]),
+ states.iter().map(|(n, p)| Some((*n, p))),
+ |_| None,
+ );
+ let (post, north, east) = ([0.5, 0.5], [0.5, 0.2], [0.8, 0.5]);
+ assert!(ctm.stacked_pane_hides(0, 1, post));
+ assert!(ctm.stacked_pane_hides(0, 1, north));
+ // The pane above has no east arm: the strip shows; one with it hides it.
+ assert!(!ctm.stacked_pane_hides(0, 1, east));
+ assert!(ctm.stacked_pane_hides(1, 0, east));
+ let (south, west) = ([0.5, 0.8], [0.2, 0.5]);
+ assert!(!ctm.stacked_pane_hides(1, 0, south));
+ assert!(!ctm.stacked_pane_hides(1, 0, west));
+ assert!(ctm.stacked_pane_hides(1, 0, north));
+ // Another block, or a pane without rules, hides nothing.
+ assert!(!ctm.stacked_pane_hides(1, 2, post));
+ assert!(!ctm.stacked_pane_hides(3, 3, post));
}
#[test]
diff --cc crates/horizon-client-render/src/mesher.rs
index 6cfb58f76,f235d255d..1c8894009
--- a/crates/horizon-client-render/src/mesher.rs
+++ b/crates/horizon-client-render/src/mesher.rs
@@@ -1349,7 -1377,6 +1377,14 @@@ impl Mesher<'_>
[world.x, world.y, world.z],
|[dx, dy, dz]| pad.blocks[pi(pos[0] + dx, pos[1] + dy, pos[2] + dz)],
|| Some(tints.biome(pos[0], pos[1], pos[2])),
- || CtmAxes::texture(&q.positions, &q.uv),
++ // A pane's tiles are drawn with the cube's UVs (below), so that is its texture.
++ || {
++ if state.pane {
++ Some(CtmAxes::cube(CtmFace::ALL[q.facing as usize]))
++ } else {
++ CtmAxes::texture(&q.positions, &q.uv)
++ }
++ },
|overlay| {
if let Some(slot) = overlays.get_mut(count) {
*slot = Some(overlay);
diff --cc crates/horizon-optifine/src/ctm/connect.rs
index 9c9cfb4a7,a4011c788..3568c1c0f
--- a/crates/horizon-optifine/src/ctm/connect.rs
+++ b/crates/horizon-optifine/src/ctm/connect.rs
@@@ -88,33 -88,6 +88,32 @@@ pub struct Axes
}
impl Axes {
+ /// Where a quad's own texture points, from its corners' positions and UVs, snapped to the
+ /// block's axes (Continuity's `orient=texture`): a turned or mirrored model's face turns or
+ /// mirrors its neighbours too. `None` for a quad whose UVs don't span it.
+ pub fn texture(positions: &[[f32; 3]; 4], uv: &[[f32; 2]; 4]) -> Option<Self> {
+ let edge = |k: usize| [0, 1, 2].map(|c| positions[k][c] - positions[0][c]);
+ let step = |k: usize| [uv[k][0] - uv[0][0], uv[k][1] - uv[0][1]];
+ let (e1, e2, d1, d2) = (edge(1), edge(3), step(1), step(3));
+ // The edges in UV terms: e = du * (d/du) + dv * (d/dv), solved for the two gradients.
+ let det = d1[0] * d2[1] - d2[0] * d1[1];
- if det.abs() < 1e-6 {
++ if !det.is_finite() || det.abs() < 1e-6 {
+ return None;
+ }
+ let along_u = [0, 1, 2].map(|c| (e1[c] * d2[1] - e2[c] * d1[1]) / det);
+ let along_v = [0, 1, 2].map(|c| (e2[c] * d1[0] - e1[c] * d2[0]) / det);
+ let snap = |v: [f32; 3]| {
+ let k = (0..3).max_by(|&a, &b| v[a].abs().total_cmp(&v[b].abs()))?;
+ let mut out = [0; 3];
+ out[k] = if v[k] > 0.0 { 1 } else { -1 };
+ (v[k] != 0.0).then_some(out)
+ };
- // v grows downward: the texture's up is against it.
- Some(Self {
- right: snap(along_u)?,
- up: neg(snap(along_v)?),
- })
++ // v grows downward: the texture's up is against it. A quad turned off the block's axes
++ // (an element rotated 45°) can snap both to one axis: no directions then.
++ let (right, up) = (snap(along_u)?, neg(snap(along_v)?));
++ (dot(right, up) == 0).then_some(Self { right, up })
+ }
+
/// On a vanilla cube: `BlockElement`'s default UVs (OptiFine's `ctm`, Continuity's
/// `orient=none`).
pub const fn cube(face: Face) -> Self {
@@@ -595,46 -568,4 +594,49 @@@ mod tests
.count();
assert!(differs > 20, "{differs}");
}
+
+ #[test]
+ fn a_quads_own_texture_directions() {
+ // A north face with the cube's UVs: its texture points as the cube's does.
+ let north = [
+ [1.0, 1.0, 0.0],
+ [0.0, 1.0, 0.0],
+ [0.0, 0.0, 0.0],
+ [1.0, 0.0, 0.0],
+ ];
+ let standard = [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0]];
+ assert_eq!(
+ Axes::texture(&north, &standard),
+ Some(Axes::cube(Face::North))
+ );
+ // Mirrored (a vanilla pane face): right turns to east.
+ let mirrored = [[1.0, 0.0], [0.0, 0.0], [0.0, 1.0], [1.0, 1.0]];
+ assert_eq!(
+ Axes::texture(&north, &mirrored),
+ Some(Axes {
+ right: EAST,
+ up: UP
+ })
+ );
+ // A top face turned a quarter (y=90): the texture's up points east, its right south.
+ let top = [
+ [0.0, 1.0, 0.0],
+ [1.0, 1.0, 0.0],
+ [1.0, 1.0, 1.0],
+ [0.0, 1.0, 1.0],
+ ];
+ let turned = [[0.0, 1.0], [0.0, 0.0], [1.0, 0.0], [1.0, 1.0]];
+ assert_eq!(
+ Axes::texture(&top, &turned),
+ Some(Axes {
+ right: SOUTH,
+ up: EAST
+ })
+ );
- // UVs that don't span the quad.
++ // UVs that don't span the quad, or that run diagonally across it.
+ assert_eq!(Axes::texture(&north, &[[0.5, 0.5]; 4]), None);
++ let diagonal = [[0.5, 0.0], [1.0, 0.5], [0.5, 1.0], [0.0, 0.5]];
++ assert_eq!(Axes::texture(&north, &diagonal), None);
++ assert_eq!(Axes::texture(&north, &[[f32::NAN; 2]; 4]), None);
+ }
}