Merge pull request #2099 from kacpherek/fix/2087-pot-top

🤖 Agent: Read against the vanilla 26.3 sources (Decorated pot: draw one face of its top and bottom planes) and proven in contrib-gate-21's union of 72 kacpherek PRs: 95 parity harnesses on playhorizon and the Mac mini, clippy, 1534 tests, lan_e2e 23 checks in-frame and with --server-thread. Thanks @kacpherek!
This commit is contained in:
Ludovic Marie
2026-10-27 17:17:48 +01:00
committed by GitHub
6 changed files with 43 additions and 6 deletions
@@ -5,7 +5,11 @@
//! (`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 crate::{
hud::Rect,
mesher::{CULL_BACK, Vertex},
world::World,
};
use glam::{DVec3, Mat4, Quat, Vec3};
use horizon_core::geometry::{
Direction,
@@ -1416,6 +1420,7 @@ impl BlockEntityRenderer {
m *= around(Mat4::from_rotation_y(turn * decay), pivot);
}
}
let first = out.len();
if let Some(paint) =
paint("entity/decorated_pot/decorated_pot_base", 0xFFFFFF, packed)
{
@@ -1433,6 +1438,11 @@ impl BlockEntityRenderer {
draw_part(part, side, m, &none, paint, out);
}
}
// `DecoratedPotRenderer` submits every part with `entitySolid`, which culls
// back faces: the flat `top` and `bottom` planes show one side each.
for vertex in &mut out[first..] {
vertex.normal = CULL_BACK;
}
}
Kind::EndPortal => {
// TheEndPortalRenderer.TRANSFORMATION: y from 6/16 to 12/16; only the
+7 -2
View File
@@ -54,6 +54,8 @@ struct Out {
// The `GLINT_TEXTURING` sample for overlay 7 (item foil), or the model UV
// `ARMOR_ENTITY_GLINT_TEXTURING` scrolls for overlay 13 (armour).
@location(11) glint_uv: vec2<f32>,
// 1 drops the quad's back-facing pixels (Vertex::normal w = 1), like a culling render type.
@location(12) @interpolate(flat) cull: u32,
}
// Shipped light.glsl; normals are already transformed and RGBA8_SNORM packed.
fn entity_light(normal: vec3<f32>, nether: bool) -> f32 {
@@ -102,7 +104,10 @@ fn entity_vertex(position: vec3<f32>, uv: vec2<f32>,
// minecraft_mix_light: the vertex colour times the cardinal light only.
var c = color;
var back = c;
if normal.w != 0.0 {
// Normal w: 0 keeps the baked colour, +-127 shades by the normal, and a small positive 1
// keeps the baked colour but culls back faces (entitySolid models such as the decorated pot).
out.cull = select(0u, 1u, normal.w > 0.0 && normal.w < 0.5);
if abs(normal.w) >= 0.5 {
c = vec4(c.rgb * entity_light(normal.xyz, globals.time.y != 0.0), c.a);
back = select(c, vec4(back.rgb * entity_light(-normal.xyz, globals.time.y != 0.0), back.a), normal.w < 0.0);
}
@@ -234,7 +239,7 @@ fn crumbling_uv(uv: vec2<f32>, packed_origin: vec2<f32>, sprite_size: vec2<f32>,
// 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)));
}
if color.a < 0.1 { discard; }
if color.a < 0.1 || (in.cull != 0u && !front) { discard; }
// entity.fsh calculateFinalColor: the overlay (hurt red, TNT white) over the
// lit texture, then the lightmap, then the glint and fog.
color = vec4(mix(in.overlay_color.rgb, color.rgb, in.overlay_color.a), color.a);
+5 -2
View File
@@ -12,7 +12,7 @@ mod special;
use crate::{
block_entity_render::{ModelPart, diffuse},
hud::Rect,
mesher::Vertex,
mesher::{CULL_BACK, Vertex},
};
use glam::{Mat3, Mat4, Vec3};
use horizon_assets::{
@@ -49,6 +49,8 @@ pub struct ItemQuad {
pub foil: Foil,
/// `MaterialInfo.lightEmission` (block light floor).
pub light_emission: u8,
/// The render type culls back faces (`entitySolid`): world drawing discards them.
pub cull_back: bool,
/// The quad's sprite has translucent pixels (`MaterialInfo.itemRenderType`
/// is a translucent sheet): drawn with the translucent entities.
pub translucent: bool,
@@ -307,6 +309,7 @@ fn submit_quads(
color: argb(color),
foil,
light_emission: q.light_emission,
cull_back: false,
translucent: translucent || q.material.force_translucent,
});
}
@@ -787,7 +790,7 @@ impl ItemSink for WorldSink<'_> {
for (i, (p, uv)) in q.pos.iter().zip(q.uv).enumerate() {
let glint_uv = glint.map_or([0.0, 0.0], |glint| glint.uv(q.foil_uv[i]));
self.out.push(Vertex {
normal: [0; 4],
normal: if q.cull_back { CULL_BACK } else { [0; 4] },
pos: p.to_array(),
uv,
layer: overlay,
@@ -377,6 +377,7 @@ mod tests {
color,
foil: Foil::None,
light_emission: 0,
cull_back: false,
translucent: false,
}
}
@@ -65,6 +65,17 @@ pub(super) fn load_parts(root: &Path) -> HashMap<String, ModelPart> {
.collect()
}
/// Marks every quad passed on as drawn with a back-face-culling render type (`entitySolid`).
struct CullBack<'a>(&'a mut dyn ItemSink);
impl ItemSink for CullBack<'_> {
fn quad(&mut self, quad: ItemQuad) {
self.0.quad(ItemQuad {
cull_back: true,
..quad
});
}
}
/// A pose override for a named part (`setupAnim`).
type Adjust<'a> = &'a dyn Fn(&str, &mut [f32; 9]);
fn none(_: &str, _: &mut [f32; 9]) {}
@@ -120,6 +131,7 @@ fn draw(
color,
foil,
light_emission: 0,
cull_back: false,
translucent: false,
});
}
@@ -571,6 +583,8 @@ pub(super) fn submit(
}
SpecialKind::DecoratedPot => {
let sides = pot_sides(argument);
// `DecoratedPotRenderer` draws every part with `entitySolid`.
let sink = &mut CullBack(sink);
if let Some(base) = renderer.part("decorated_pot_base")
&& let Some(r) = sprites
.get("entity/decorated_pot/decorated_pot_base")
+5 -1
View File
@@ -36,11 +36,15 @@ pub struct Vertex {
pub color: u32,
/// Smooth light, 16x fixed point: sky in bits 0..8, block in bits 8..16.
pub light: u32,
/// RGBA8_SNORM face normal; w = -127 for two-sided lighting, 0 to keep baked/unlit colour.
/// RGBA8_SNORM face normal; w = -127 for two-sided lighting, 0 to keep baked/unlit colour,
/// [`CULL_BACK`] to keep it and also drop back-facing pixels.
pub normal: [i8; 4],
/// The `GLINT_TEXTURING` atlas UV for a foil item quad; zero elsewhere.
pub glint_uv: [f32; 2],
}
/// `Vertex::normal` of a baked-colour quad of an `entitySolid` model: the render type culls
/// back faces, which the entity pipelines here do not, so `entity.wgsl` discards them.
pub const CULL_BACK: [i8; 4] = [0, 0, 0, 1];
/// A section vertex: vanilla's `DefaultVertexFormat.BLOCK` (position, colour,
/// UV0, UV2) with the sprite's array layer beside the light, in 24 bytes
/// rather than vanilla's 28: the UV is fixed point, which holds model UVs