Items: draw the enchantment glint from enchanted_glint_item

Horizon invented the glint: the GUI drew sine bands in screen space and
the entity shader layered the same over held and dropped items. Vanilla
26.3 samples `misc/enchanted_glint_item` through `GLINT_TEXTURING`
(`item.vsh`/`item.fsh`, `TextureTransform.setupGlintTexturing`), so
items now carry the real texture:

- `ItemQuad.foil_uv` keeps the model UV the glint samples; `Glint` turns
  it into the atlas UV with the 26.3 transform (translation(-o0, o1) *
  rotateZ(PI/18) * scale) and `WorldSink` gives foil quads overlay 7 and
  the per-corner glint UV.
- The GUI glint is a separate additive HUD pass masked by the item's
  texture alpha (`item.fsh`'s ALPHA_CUTOUT 0.1 and GLINT path).
- `entity.wgsl` samples the glint at overlay 7/8 like vanilla's
  `color.rgb += glintColor.rgb * glintColor.rgb`.
- The Accessibility options Glint Speed and Glint Strength work: both
  sliders persist to `options.txt` (they were hidden placeholders), the
  GUI pass takes them per draw, and `Frame.glint_alpha` feeds the entity
  shader every frame instead of whatever the last HUD item set.
- GUI items use `GLINT_TEXTURING`'s scale 8, world items
  `ENTITY_GLINT_TEXTURING`'s scale 0.5.

Co-Authored-By: ZCode <agent@zcode.dev>
This commit is contained in:
masa-masa-0314
2026-10-27 00:29:02 +08:00
parent f9b2f949ee
commit cf6b91a710
43 changed files with 280 additions and 75 deletions
@@ -149,6 +149,8 @@ pub fn draw_part(
layer: 0,
color,
light,
glint_uv: [0.0, 0.0],
});
}
}
@@ -648,6 +650,8 @@ fn draw_text(scene: &Scene, call: &TextCall, out: &mut Vec<Vertex>) {
layer: 0,
color: c,
light: call.light,
glint_uv: [0.0, 0.0],
});
}
}
@@ -1714,6 +1718,8 @@ impl BeamPart {
layer: 6,
color,
light: self.wrap,
glint_uv: [0.0, 0.0],
});
}
}
@@ -1784,6 +1790,7 @@ fn portal_cube(m: Mat4, faces: &[Direction], layer: u32, out: &mut Vec<Vertex>)
layer,
color: 0,
light: 0,
glint_uv: [0.0, 0.0],
});
}
}
+2
View File
@@ -49,6 +49,8 @@ pub fn geometry(
color: 0xffff_ffff,
light: stage_light(stage),
normal: [0; 4],
glint_uv: [0.0, 0.0],
});
}
}
+2
View File
@@ -179,6 +179,8 @@ impl Mesh {
layer: 4,
color: u32::MAX,
light: shade,
glint_uv: [0.0, 0.0],
});
}
};
+13 -11
View File
@@ -44,6 +44,8 @@ struct Out {
// entity.vsh's lightMapColor, multiplied in after the overlay.
@location(9) light_color: vec4<f32>,
@location(10) @interpolate(flat) weather_rect: vec4<f32>,
// The `GLINT_TEXTURING` sample for overlay 7 (item foil).
@location(11) glint_uv: vec2<f32>,
}
// Shipped light.glsl; normals are already transformed and RGBA8_SNORM packed.
fn entity_light(normal: vec3<f32>, nether: bool) -> f32 {
@@ -103,12 +105,16 @@ fn entity_vertex(position: vec3<f32>, uv: vec2<f32>,
out.spherical = select(length(position), 0.0, overlay >= 2u && overlay <= 4u);
out.cylindrical = select(max(length(position.xz), abs(position.y)), 0.0, overlay >= 2u && overlay <= 4u);
out.overlay = overlay;
out.glint_uv = vec2(0.0);
if overlay == 4u { out.spherical = length(position); }
return out;
}
@vertex fn vs_entity(@location(0) position: vec3<f32>, @location(1) uv: vec2<f32>,
@location(2) overlay: u32, @location(3) color: vec4<f32>, @location(4) light: vec4<u32>, @location(5) normal: vec4<f32>) -> Out {
return entity_vertex(position, uv, overlay, color, light, normal);
@location(2) overlay: u32, @location(3) color: vec4<f32>, @location(4) light: vec4<u32>,
@location(5) normal: vec4<f32>, @location(6) glint_uv: vec2<f32>) -> Out {
var out = entity_vertex(position, uv, overlay, color, light, normal);
out.glint_uv = glint_uv;
return out;
}
// Retained bolt-local geometry, translated using the same f64 camera
// subtraction as the former CPU path before adding each local f32 position.
@@ -204,15 +210,11 @@ fn crumbling_uv(uv: vec2<f32>, packed_origin: vec2<f32>, sprite_size: vec2<f32>,
color = vec4(mix(in.overlay_color.rgb, color.rgb, in.overlay_color.a), color.a);
color *= in.light_color;
if in.overlay == 7u || in.overlay == 8u {
// Enchantment glint (overlay 7, 8 with the hurt tint): the purple
// enchanted_glint sheen drifting diagonally over the item's shape.
let px = in.uv * vec2<f32>(textureDimensions(atlas));
let t = globals.misc.y * 0.05;
let band = sin((px.x + px.y) * 0.9 - t * 6.0) * 0.5 + 0.5;
let band2 = sin((px.x - px.y) * 0.6 + t * 4.0) * 0.5 + 0.5;
let shimmer = pow(band * 0.6 + band2 * 0.4, 2.0);
let glint = vec3(0.50, 0.25, 0.80) * (0.25 + 0.75 * shimmer);
color = vec4(min(color.rgb + glint * 0.6, vec3(1.0)), color.a);
// Enchantment glint: item.fsh's GLINT path, sampled from
// enchanted_glint_item at the `GLINT_TEXTURING` UV.
let alpha = globals.fog_ends.w;
let glint = alpha * textureSample(atlas, atlas_sampler, in.glint_uv);
color = vec4(color.rgb + glint.rgb * glint.rgb, max(color.a, alpha));
}
let f = max(linear_fog(in.spherical, globals.fog.x, globals.fog.y),
linear_fog(in.cylindrical, globals.fog.z, globals.fog.w));
@@ -186,6 +186,8 @@ mod tests {
color: u32::MAX,
light: 0,
normal: [0; 4],
glint_uv: [0.0, 0.0],
};
let prior = vertex([0.0; 3]);
let body = [vertex([8.0, -1.0, -1.0]), vertex([10.0, 1.0, 1.0])];
+2
View File
@@ -48,6 +48,8 @@ pub fn flames(
color: 0xffff_ffff,
light: 0xf000 | (u32::from(scene_light >> 4) * 16),
normal: [0; 4],
glint_uv: [0.0, 0.0],
});
}
remaining -= 0.45;
+6
View File
@@ -7380,6 +7380,8 @@ impl Game<'_> {
layer: 0,
color,
light: packed,
glint_uv: [0.0, 0.0],
});
}
}
@@ -7999,6 +8001,8 @@ impl Game<'_> {
layer: 2,
color,
light: 0,
glint_uv: [0.0, 0.0],
});
}
};
@@ -10801,6 +10805,7 @@ impl Game<'_> {
debug_lines_on_top: &debug_lines_on_top,
debug_crosshair: &debug_crosshair,
hud: &hud,
glint_alpha: self.settings.file.double("glintStrength") as f32,
clouds: (!title
&& self.dim == Dim::Overworld
&& horizon_client::clouds::visible(&self.settings.clouds, sky.cloud_color[3]))
@@ -13478,6 +13483,7 @@ fn loading_frame(hud: &HudBatch) -> Frame<'_> {
debug_lines_on_top: &[],
debug_crosshair: &[],
hud,
glint_alpha: 0.75,
nether_lighting: false,
entities: &[],
entity_spans: &[],
@@ -872,6 +872,7 @@ impl Game<'_> {
lights: Some(horizon_client::block_entity_render::diffuse_lights(
self.dim == super::Dim::Nether,
)),
glint: self.glint(),
};
let profile = stack
.extra
@@ -145,6 +145,8 @@ fn flame_geometry(
layer: 0,
color: 0xFFFF_FFFF,
light: packed,
glint_uv: [0.0, 0.0],
});
}
h -= 0.45;
@@ -3316,6 +3318,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light: packed,
glint_uv: [0.0, 0.0],
});
}
}
+6
View File
@@ -2482,6 +2482,8 @@ impl Game<'_> {
layer: 2,
color: c,
light: 0,
glint_uv: [0.0, 0.0],
});
}
}
@@ -2547,6 +2549,8 @@ impl Game<'_> {
layer: 6,
color: c,
light: wrap_light,
glint_uv: [0.0, 0.0],
});
}
(last_sin, last_cos, last_u) = (sin, cos, uu);
@@ -2592,6 +2596,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light: 240 | 240 << 8,
glint_uv: [0.0, 0.0],
});
}
}
+4
View File
@@ -247,6 +247,8 @@ impl Game<'_> {
layer: 2,
color,
light: 0,
glint_uv: [0.0, 0.0],
});
}
}
@@ -1240,6 +1242,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light: full,
glint_uv: [0.0, 0.0],
});
}
}
@@ -643,6 +643,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light: packed,
glint_uv: [0.0, 0.0],
});
}
}
+2
View File
@@ -377,6 +377,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light,
glint_uv: [0.0, 0.0],
});
}
};
@@ -296,8 +296,25 @@ impl Game<'_> {
x,
y,
self.started.elapsed().as_secs_f32(),
self.settings.file.double("glintSpeed") as f32,
self.settings.file.double("glintStrength") as f32,
);
}
/// The `GLINT_TEXTURING` inputs the atlas and options provide.
pub(super) fn glint(&self) -> Option<item_render::Glint> {
self.gui
.atlas
.sprites
.get("misc/enchanted_glint_item")
.copied()
.map(|rect| item_render::Glint {
rect,
speed: self.settings.file.double("glintSpeed") as f32,
alpha: self.settings.file.double("glintStrength") as f32,
millis: self.started.elapsed().as_secs_f32() * 1000.0,
scale: 0.5,
})
}
/// Submit a resolved item under `pose` (camera-relative) at `light`
/// (packed lightmap coordinates).
pub(super) fn submit_item_world(
@@ -311,6 +328,7 @@ impl Game<'_> {
out,
light,
lights: Some(diffuse_lights(self.dim == Dim::Nether)),
glint: self.glint(),
};
state.submit(
&self.pack.item_renderer,
@@ -332,6 +350,7 @@ impl Game<'_> {
out,
light,
lights: None,
glint: self.glint(),
};
state.submit(
&self.pack.item_renderer,
+2
View File
@@ -381,6 +381,8 @@ impl Game<'_> {
layer: 0,
color,
light: packed,
glint_uv: [0.0, 0.0],
});
}
}
+6
View File
@@ -1133,6 +1133,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light,
glint_uv: [0.0, 0.0],
});
}
};
@@ -1180,6 +1182,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light,
glint_uv: [0.0, 0.0],
});
}
};
@@ -1251,6 +1255,8 @@ impl Game<'_> {
layer: 0,
color: 0xFFFF_FFFF,
light,
glint_uv: [0.0, 0.0],
});
}
}
@@ -1297,6 +1297,7 @@ impl Game<'_> {
layer: 0,
color,
light,
glint_uv: [0.0, 0.0],
});
}
}
@@ -203,6 +203,8 @@ impl Game<'_> {
layer: overlay,
color,
light,
glint_uv: [0.0, 0.0],
});
}
}
+1
View File
@@ -377,6 +377,7 @@ impl Game<'_> {
layer,
color,
light,
glint_uv: [0.0, 0.0],
});
}
};
@@ -308,6 +308,8 @@ impl Game<'_> {
layer: 0,
color,
light: packed,
glint_uv: [0.0, 0.0],
});
}
};
@@ -710,6 +710,8 @@ mod preview_tests {
color: u32::MAX,
light: 0,
normal: [0; 4],
glint_uv: [0.0, 0.0],
})
};
// A shield and arm can intersect: neither average depth orders both ends.
@@ -268,6 +268,8 @@ impl Game<'_> {
light,
layer: if through { 2 } else { 0 },
normal: [0; 4],
glint_uv: [0.0, 0.0],
});
}
}
+2
View File
@@ -332,6 +332,8 @@ impl Game<'_> {
layer: if lit { 5 } else { 0 },
color,
light: packed,
glint_uv: [0.0, 0.0],
});
}
}
+8 -3
View File
@@ -172,7 +172,8 @@ struct Globals {
inverse_view: [[f32; 4]; 4],
sunrise: [f32; 4],
sun: [f32; 4],
/// x: sky fog end, y: cloud fog end, z: dark disc (camera below the horizon), w: unused.
/// x: sky fog end, y: cloud fog end, z: dark disc (camera below the horizon),
/// w: the glint strength (`GlintAlpha`).
fog_ends: [f32; 4],
/// Atlas rects (u0, v0, width, height) of end_sky.png and end_portal.png.
end_portal_sprites: [[f32; 4]; 2],
@@ -256,6 +257,9 @@ pub struct Frame<'a> {
/// drawn after the hand at its projection, without the bob or fog.
pub debug_crosshair: &'a [[f32; 8]],
pub hud: &'a HudBatch,
/// `GlintAlpha` (accessibility Glint Strength); the entity shader uses it
/// for held/world items, independent of what the HUD batch last drew.
pub glint_alpha: f32,
/// CardinalLighting.Type.NETHER, otherwise DEFAULT.
pub nether_lighting: bool,
/// Camera-relative entity geometry textured from the shared atlas.
@@ -1724,7 +1728,7 @@ impl Renderer {
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
let entity_attributes = wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x2,2=>Uint32,3=>Unorm8x4,4=>Uint8x4,5=>Snorm8x4];
let entity_attributes = wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x2,2=>Uint32,3=>Unorm8x4,4=>Uint8x4,5=>Snorm8x4,6=>Float32x2];
let entity_vertex = [Some(wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as u64,
step_mode: wgpu::VertexStepMode::Vertex,
@@ -3475,7 +3479,7 @@ impl Renderer {
frame.fog.map_or(frame.distance.min(512.0), |f| f.sky_end),
frame.fog.map_or(2048.0, |f| f.cloud_end),
if frame.dark_disc { 1.0 } else { 0.0 },
0.0,
frame.glint_alpha,
],
end_portal_sprites: frame.end_portal_sprites,
crumbling_sprite: frame.crumbling_sprite,
@@ -5222,6 +5226,7 @@ mod tests {
color: 0xffff_ffff,
light: id,
normal: [0; 4],
glint_uv: [0.0, 0.0],
}; 4]
};
let entities: Vec<_> = [
+2
View File
@@ -72,6 +72,8 @@ fn vertices(uv: [f32; 4]) -> Vec<Vertex> {
layer: 2,
color: 0xFF28_2828,
light: 0,
glint_uv: [0.0, 0.0],
});
}
}
@@ -12,15 +12,15 @@ fn geometry_matches_pre_residency_vertex_snapshots() {
for (uv, expected) in [
(
[0.0, 0.0, 1.0, 1.0],
"f7ee23457fc557b33ecf09c9afaf858f3d8907e108abf06055f627523f733536",
"82a9be3f3ed1f733017df2c81dc6dff163f67bf739c768e3fd0f90f00c7802f6",
),
(
[0.125, 0.25, 0.375, 0.5],
"f74c4b8d23ec2b7c11b5752821d0733851bf11358f1b26f9448226ff62a6a318",
"05a058bd8e70cff900c8e1c81061892ed27866d86498ebe1e8ae5af4c3b770ef",
),
(
[0.13, 0.27, 0.41, 0.59],
"f0aaa39c5b22168bdc7c6c329acb4d3598a2feb61ff7b6f2850b644682749b39",
"93064b9fd2e745da46b927b2625edc8a381bb8c6e20b0f0880e816c4c1745ec1",
),
] {
let mut mesh = vertices(uv);
@@ -31,10 +31,8 @@ fn geometry_matches_pre_residency_vertex_snapshots() {
if n == 0.0 { 0.0 } else { n }
});
}
assert_eq!(
format!("{:x}", Sha256::digest(bytemuck::cast_slice(&mesh))),
expected
);
let hash = format!("{:x}", Sha256::digest(bytemuck::cast_slice(&mesh)));
assert_eq!(hash, expected);
}
}
@@ -95,7 +93,7 @@ fn separate_draws_match_combined_celestial_pixels() {
label: Some("End sky differential shader"),
source: wgpu::ShaderSource::Wgsl(crate::gfx::entity_shader().into()),
});
let attributes = wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x2,2=>Uint32,3=>Unorm8x4,4=>Uint8x4,5=>Snorm8x4];
let attributes = wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x2,2=>Uint32,3=>Unorm8x4,4=>Uint8x4,5=>Snorm8x4,6=>Float32x2];
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("End sky differential pipeline"),
layout: None,
@@ -305,6 +303,8 @@ fn separate_draws_match_combined_celestial_pixels() {
color: level * 0x01010101,
light: 0,
normal: [0; 4],
glint_uv: [0.0, 0.0],
})
.to_vec()
};
@@ -130,6 +130,8 @@ mod tests {
color: index as u32,
light: (index * 3) as u32,
normal: [1, 2, 3, 4],
glint_uv: [0.0, 0.0],
})
.collect()
}
@@ -77,6 +77,8 @@ fn geometry(seed: i64, uv: [f32; 2]) -> Vec<Vertex> {
layer: 2,
color,
light: 240 | 240 << 8,
glint_uv: [0.0, 0.0],
});
}
}
@@ -60,6 +60,8 @@ fn reference(seed: i64, at: [f64; 3], camera: DVec3, uv: [f32; 2]) -> Vec<Vertex
layer: 2,
color,
light: 240 | 240 << 8,
glint_uv: [0.0, 0.0],
});
}
}
@@ -135,6 +135,8 @@ impl PackWeather {
color: v.color,
light: v.light,
normal: [0; 4],
glint_uv: [0.0, 0.0],
}
}));
if self.scratch.len() > self.capacity {
+36 -2
View File
@@ -554,6 +554,8 @@ pub struct HudVertex {
pub uv: [f32; 2],
pub color: u32,
pub depth: f32,
/// The glint sprite UV (`GLINT_TEXTURING`), unused unless `uv.x >= 2`.
pub glint_uv: [f32; 2],
}
/// The GUI Scale option (0 = auto).
pub static GUI_SCALE: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
@@ -569,6 +571,8 @@ pub struct HudBatch {
pub blends: Vec<(std::ops::Range<u32>, Blend)>,
/// The textures and time of the `Blend::EndPortal` runs.
pub end_portal: EndPortalFill,
/// `options.glintStrength` for the glint pass (`GlintAlpha`).
pub glint_alpha: f32,
/// Screen's first vertex: the preceding HUD is part of its blurred background.
pub blur_at: u32,
}
@@ -620,6 +624,7 @@ impl HudBatch {
patches: Vec::new(),
blends: Vec::new(),
end_portal: EndPortalFill::default(),
glint_alpha: 0.75,
blur_at: 0,
}
}
@@ -695,6 +700,26 @@ impl HudBatch {
uv: uv[i],
color,
depth: 0.0,
glint_uv: [0.0, 0.0],
});
}
}
/// A quad whose texture is the `GLINT_TEXTURING` sample at `glint_uv`;
/// `uv` is the item's atlas UV, which the shader masks by.
pub fn quad_glint(
&mut self,
p: [[f32; 2]; 4],
uv: [[f32; 2]; 4],
glint_uv: [[f32; 2]; 4],
color: u32,
) {
for i in [0, 1, 2, 0, 2, 3] {
self.vertices.push(HudVertex {
pos: p[i],
uv: uv[i],
color,
depth: 0.0,
glint_uv: glint_uv[i],
});
}
}
@@ -705,6 +730,7 @@ impl HudBatch {
uv: uv[i],
color,
depth: p[i][2],
glint_uv: [0.0, 0.0],
});
}
}
@@ -875,6 +901,7 @@ impl HudBatch {
uv,
color: c[i],
depth: 0.0,
glint_uv: [0.0, 0.0],
});
}
}
@@ -1122,7 +1149,8 @@ impl HudRenderer {
bind_group_layouts: &[Some(&layout)],
..Default::default()
});
let attributes = wgpu::vertex_attr_array![0=>Float32x2,1=>Float32x2,2=>Unorm8x4,3=>Float32];
let attributes =
wgpu::vertex_attr_array![0=>Float32x2,1=>Float32x2,2=>Unorm8x4,3=>Float32,4=>Float32x2];
let create = |label, blend, fragment_entry, depth: bool| {
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some(label),
@@ -1337,7 +1365,12 @@ impl HudRenderer {
&self.uniform,
0,
bytemuck::bytes_of(&HudUniform::new(
[size[0] as f32, size[1] as f32, batch.scale, 0.0],
[
size[0] as f32,
size[1] as f32,
batch.scale,
batch.glint_alpha,
],
batch.end_portal,
)),
);
@@ -1787,6 +1820,7 @@ mod tests {
patches: Vec::new(),
blends: Vec::new(),
end_portal: EndPortalFill::default(),
glint_alpha: 0.75,
blur_at: 0,
};
for (image_width, image_height) in [(195, 136), (176, 166), (176, 222)] {
+9 -5
View File
@@ -13,22 +13,26 @@ struct Out {
@location(1) color: vec4<f32>,
// projection_from_position(gl_Position): the End portal's texProj0.
@location(2) proj: vec4<f32>,
@location(3) glint_uv: vec2<f32>,
}
@vertex fn vs_main(@location(0) pos: vec2<f32>, @location(1) uv: vec2<f32>, @location(2) color: vec4<f32>, @location(3) depth: f32) -> Out {
@vertex fn vs_main(@location(0) pos: vec2<f32>, @location(1) uv: vec2<f32>, @location(2) color: vec4<f32>, @location(3) depth: f32, @location(4) glint_uv: vec2<f32>) -> Out {
let pixels = pos * hud.size.z;
var out: Out;
out.clip = vec4(pixels.x / hud.size.x * 2.0 - 1.0, 1.0 - pixels.y / hud.size.y * 2.0, depth, 1.0);
out.uv = uv;
out.color = color;
out.proj = vec4(out.clip.xy * 0.5 + 0.5, out.clip.zw);
out.glint_uv = glint_uv;
return out;
}
@fragment fn fs_main(in: Out) -> @location(0) vec4<f32> {
// u >= 2: flat vertex colour masked by the texture's alpha (enchantment glint).
// u >= 2: the GLINT_TEXTURING sample over the item, masked by the item's
// texture alpha (item.fsh's ALPHA_CUTOUT and GLINT path).
if in.uv.x >= 2.0 {
let m = textureSample(atlas, atlas_sampler, in.uv - vec2(2.0, 0.0)).a * in.color.a;
if m < 0.004 { discard; }
return vec4(in.color.rgb, m);
let mask = textureSample(atlas, atlas_sampler, in.uv - vec2(2.0, 0.0)).a;
if mask < 0.1 { discard; }
let glint = hud.size.w * textureSample(atlas, atlas_sampler, in.glint_uv);
return vec4(glint.rgb * glint.rgb, mask);
}
let c = textureSample(atlas, atlas_sampler, in.uv) * in.color;
if c.a < 0.004 { discard; }
+48 -2
View File
@@ -41,12 +41,48 @@ use std::{
pub struct ItemQuad {
pub pos: [Vec3; 4],
pub uv: [[f32; 2]; 4],
/// The model UVs `GLINT_TEXTURING` scrolls for the glint (vanilla's UV0,
/// or UV3 for a special model).
pub foil_uv: [[f32; 2]; 4],
pub normal: Vec3,
pub color: u32,
pub foil: Foil,
/// `MaterialInfo.lightEmission` (block light floor).
pub light_emission: u8,
}
/// `TextureTransform.setupGlintTexturing`'s inputs and the glint sprite.
#[derive(Clone, Copy, Debug)]
pub struct Glint {
pub rect: crate::hud::Rect,
/// `options.glintSpeed` (vanilla default 0.5).
pub speed: f32,
/// `options.glintStrength` / shader `GlintAlpha` (vanilla default 0.75).
pub alpha: f32,
/// `Util.getMillis()`.
pub millis: f32,
/// The transform's scale: `GLINT_TEXTURING`'s 8.0 for GUI items,
/// `ENTITY_GLINT_TEXTURING`'s 0.5 for items in the world.
pub scale: f32,
}
impl Glint {
/// `TextureTransform.setupGlintTexturing(scale)`: translation(-o0, o1) *
/// rotateZ(PI/18) * scale, wrapped and mapped into the glint sprite.
pub fn atlas_uv(&self, model: [f32; 2]) -> [f32; 2] {
let millis = (f64::from(self.millis) * f64::from(self.speed) * 8.0) as i64;
let offset0 = (millis % 110000) as f32 / 110000.0;
let offset1 = (millis % 30000) as f32 / 30000.0;
let angle = std::f32::consts::PI / 18.0;
let (sin, cos) = angle.sin_cos();
let x = model[0] * self.scale * cos - model[1] * self.scale * sin - offset0;
let y = model[0] * self.scale * sin + model[1] * self.scale * cos + offset1;
let u = (x - x.floor()).clamp(0.5 / self.rect.w as f32, 1.0 - 0.5 / self.rect.w as f32);
let v = (y - y.floor()).clamp(0.5 / self.rect.h as f32, 1.0 - 0.5 / self.rect.h as f32);
[
self.rect.u0 + u * (self.rect.u1 - self.rect.u0),
self.rect.v0 + v * (self.rect.v1 - self.rect.v0),
]
}
}
/// Which glint render type a quad uses.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Foil {
@@ -242,6 +278,7 @@ fn submit_quads(
sink.quad(ItemQuad {
pos,
uv,
foil_uv: q.uv,
normal: transform_normal(m, direction_vector(q.facing)),
color: argb(color),
foil,
@@ -679,6 +716,8 @@ pub struct WorldSink<'a> {
pub light: u32,
/// The level's diffuse lights; `None` leaves the colour unshaded.
pub lights: Option<(Vec3, Vec3)>,
/// The `GLINT_TEXTURING` sample for foil quads (`None` leaves them unglinted).
pub glint: Option<Glint>,
}
impl ItemSink for WorldSink<'_> {
fn quad(&mut self, q: ItemQuad) {
@@ -693,8 +732,14 @@ impl ItemSink for WorldSink<'_> {
} else {
self.light
};
let overlay = if q.foil == Foil::None { 0 } else { 7 };
for (p, uv) in q.pos.iter().zip(q.uv) {
let glint = if q.foil == Foil::None {
None
} else {
self.glint
};
let overlay = if glint.is_some() { 7 } else { 0 };
for (i, (p, uv)) in q.pos.iter().zip(q.uv).enumerate() {
let glint_uv = glint.map_or([0.0, 0.0], |glint| glint.atlas_uv(q.foil_uv[i]));
self.out.push(Vertex {
normal: [0; 4],
pos: p.to_array(),
@@ -702,6 +747,7 @@ impl ItemSink for WorldSink<'_> {
layer: overlay,
color,
light,
glint_uv,
});
}
}
+46 -37
View File
@@ -5,7 +5,7 @@
//! drawn far to near, and clipped to the item's 16x16 slot unless the model
//! is oversized in the GUI (`GuiItemAtlas` draws each item into a scissored
//! 16x16 slot; oversized items get a picture-in-picture of their bounds).
use super::{Foil, ItemQuad, ItemRenderState, ItemRenderer, SpecialHost};
use super::{Foil, Glint, ItemQuad, ItemRenderState, ItemRenderer, SpecialHost};
use crate::hud::{HudBatch, Rect};
use glam::{EulerRot, Mat4, Vec2, Vec3};
use std::{collections::HashMap, f32::consts::PI, sync::Arc};
@@ -43,6 +43,7 @@ pub fn items_3d_lights() -> (Vec3, Vec3) {
struct Point {
p: Vec2,
uv: [f32; 2],
glint_uv: [f32; 2],
}
fn lerp(a: Point, b: Point, t: f32) -> Point {
Point {
@@ -51,6 +52,10 @@ fn lerp(a: Point, b: Point, t: f32) -> Point {
a.uv[0] + (b.uv[0] - a.uv[0]) * t,
a.uv[1] + (b.uv[1] - a.uv[1]) * t,
],
glint_uv: [
a.glint_uv[0] + (b.glint_uv[0] - a.glint_uv[0]) * t,
a.glint_uv[1] + (b.glint_uv[1] - a.glint_uv[1]) * t,
],
}
}
/// Sutherland-Hodgman against one half plane `dot(p, n) <= limit`.
@@ -97,37 +102,25 @@ pub fn lit_color(q: &ItemQuad, lights: (Vec3, Vec3)) -> u32 {
let c = |v: u8| (f32::from(v) * light) as u8;
crate::hud::rgba(c(r), c(g), c(b), a)
}
/// The glint's moving sheen at a GUI position (a stand-in for the
/// `GLINT_TEXTURING`-scrolled `enchanted_glint_item` texture added on top).
fn glint_color(p: Vec2, time: f32) -> u32 {
let d = ((p.x + p.y) / 32.0 - time * 0.35).rem_euclid(1.0);
let band = (1.0 - (d - 0.5).abs() * 6.0).max(0.0);
crate::hud::rgba(
(170.0 + 70.0 * band) as u8,
(90.0 + 110.0 * band) as u8,
255,
(45.0 + 110.0 * band) as u8,
)
}
fn emit(batch: &mut HudBatch, fan: &[Point], color: impl Fn(Vec2) -> u32, glint: bool) {
let shift = if glint { 2.0 } else { 0.0 };
fn emit(batch: &mut HudBatch, fan: &[Point], color: impl Fn(Vec2) -> u32, glint: Option<&Glint>) {
for i in 1..fan.len().saturating_sub(1) {
let (a, b, c) = (fan[0], fan[i], fan[i + 1]);
let corners = [a, b, c, c];
// `HudBatch.quad` draws (0, 1, 2) and (0, 2, 3): the second is empty.
batch.quad(
corners.map(|v| v.p.to_array()),
corners.map(|v| [v.uv[0] + shift, v.uv[1]]),
color(a.p),
);
if glint {
// Per-vertex colours are flat per quad in the HUD batch: use the
// fan centre for the sheen.
let n = batch.vertices.len();
for v in &mut batch.vertices[n - 6..] {
v.color = color(Vec2::from(v.pos));
}
if let Some(glint) = glint {
let start = batch.vertices.len();
batch.quad_glint(
corners.map(|v| v.p.to_array()),
corners.map(|v| [v.uv[0] + 2.0, v.uv[1]]),
corners.map(|v| glint.atlas_uv(v.glint_uv)),
u32::MAX,
);
batch.blend_since(start, crate::hud::Blend::Additive);
} else {
batch.quad(
corners.map(|v| v.p.to_array()),
corners.map(|v| v.uv),
color(a.p),
);
}
}
}
@@ -144,6 +137,8 @@ pub fn draw(
x: f32,
y: f32,
time: f32,
glint_speed: f32,
glint_alpha: f32,
) {
if state.is_empty() {
return;
@@ -256,7 +251,18 @@ fn draw_now(
} else {
[x, y, x + 16.0, y + 16.0]
};
draw_quads(&quads, lights, batch, rect, time);
let glint = sprites
.get("misc/enchanted_glint_item")
.copied()
.map(|rect| Glint {
rect,
speed: glint_speed,
alpha: glint_alpha,
millis: time * 1000.0,
scale: 8.0,
});
batch.glint_alpha = glint_alpha;
draw_quads(&quads, lights, batch, rect, glint.as_ref());
}
/// Lights, culls, sorts far to near and clips `quads` (GUI positions) to
@@ -266,7 +272,7 @@ fn draw_quads(
lights: (Vec3, Vec3),
batch: &mut HudBatch,
rect: [f32; 4],
time: f32,
glint: Option<&Glint>,
) {
for face in depth::sort(quads) {
let q = &quads[face.quad];
@@ -276,6 +282,7 @@ fn draw_quads(
.map(|v| Point {
p: v.pos.truncate(),
uv: v.uv,
glint_uv: v.glint_uv,
})
.collect();
let color = lit_color(q, lights);
@@ -285,9 +292,9 @@ fn draw_quads(
if fan.len() < 3 {
continue;
}
emit(batch, &fan, |_| color, false);
emit(batch, &fan, |_| color, None);
if q.foil != Foil::None {
emit(batch, &fan, |p| glint_color(p, time), true);
emit(batch, &fan, |_| color, glint);
}
}
}
@@ -342,7 +349,7 @@ pub fn draw_banner_result(
items_flat_lights(),
batch,
[x0, y0, x0 + 20.0, y0 + 40.0],
0.0,
None,
);
}
@@ -354,6 +361,7 @@ mod tests {
ItemQuad {
pos: [(0.0, y0), (0.0, y1), (8.0, y1), (8.0, y0)].map(|(x, y)| Vec3::new(x, y, z(y))),
uv: [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]],
foil_uv: [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]],
normal: Vec3::Z,
color,
foil: Foil::None,
@@ -394,7 +402,7 @@ mod tests {
(Vec3::Z, Vec3::Z),
&mut batch,
[0.0, 0.0, 16.0, 16.0],
0.0,
None,
);
assert_eq!(color_at(&batch, Vec2::new(4.0, 0.5)), Some(u32::MAX));
}
@@ -410,7 +418,7 @@ mod tests {
(Vec3::Z, Vec3::Z),
&mut batch,
[0.0, 0.0, 16.0, 16.0],
0.0,
None,
);
assert_eq!(
color_at(&batch, Vec2::new(4.0, 2.0)),
@@ -442,7 +450,7 @@ mod tests {
(Vec3::Z, Vec3::Z),
&mut batch,
[0.0, 0.0, 16.0, 16.0],
0.0,
None,
);
for y in [0.5, 6.0] {
assert_eq!(
@@ -468,6 +476,7 @@ mod tests {
let p = |x: f32, y: f32| Point {
p: Vec2::new(x, y),
uv: [x, y],
glint_uv: [0.0, 0.0],
};
let fan = clip_triangle(
[p(-4.0, 0.0), p(8.0, 0.0), p(8.0, 8.0)],
@@ -10,6 +10,7 @@ use glam::{Vec3, Vec4};
pub(super) struct Corner {
pub pos: Vec3,
pub uv: [f32; 2],
pub glint_uv: [f32; 2],
}
pub(super) struct Face {
@@ -38,6 +39,9 @@ fn split(face: Face, distances: &[f32]) -> (Face, Face) {
let corner = Corner {
pos: a.pos.lerp(b.pos, t),
uv: std::array::from_fn(|k| a.uv[k] + (b.uv[k] - a.uv[k]) * t),
glint_uv: std::array::from_fn(|k| {
a.glint_uv[k] + (b.glint_uv[k] - a.glint_uv[k]) * t
}),
};
back.push(corner);
front.push(corner);
@@ -73,6 +77,7 @@ pub(super) fn sort(quads: &[ItemQuad]) -> Vec<Face> {
corners: std::array::from_fn::<_, 4, _>(|k| Corner {
pos: q.pos[k],
uv: q.uv[k],
glint_uv: q.foil_uv[k],
})
.to_vec(),
})
@@ -115,6 +115,7 @@ fn draw(
sprite.v0 + (sprite.v1 - sprite.v0) * v[4],
]
}),
foil_uv: poly.map(|v| [v[3], v[4]]),
normal,
color,
foil,
+2
View File
@@ -38,6 +38,8 @@ pub struct Vertex {
pub light: u32,
/// RGBA8_SNORM face normal; w = -127 for two-sided lighting, 0 to keep baked/unlit colour.
pub normal: [i8; 4],
/// The `GLINT_TEXTURING` atlas UV for a foil item quad; zero elsewhere.
pub glint_uv: [f32; 2],
}
/// A section vertex: vanilla's `DefaultVertexFormat.BLOCK` (position, colour,
/// UV0, UV2) with the sprite's array layer beside the light, in 24 bytes
+2 -1
View File
@@ -2013,6 +2013,7 @@ pub fn render_model(
layer: overlay,
color: 0xFFFF_FFFF,
light,
glint_uv: [0.0, 0.0],
});
}
}
@@ -2147,7 +2148,7 @@ mod lighting_tests {
#[test]
fn packed_normal_uses_native_snorm_bytes_without_changing_vertex_offsets() {
assert_eq!(std::mem::offset_of!(Vertex, normal), 32);
assert_eq!(std::mem::size_of::<Vertex>(), 36);
assert_eq!(std::mem::size_of::<Vertex>(), 44);
let part = plane([0.0, 1.0, 0.0]);
assert_eq!(
part.polygons[0].vertex_normal(ModelNormals::new(Mat4::from_scale(Vec3::ZERO))),
@@ -396,6 +396,8 @@ pub fn beam_geometry(
layer: 0,
color,
light: 240 | 240 << 8,
glint_uv: [0.0, 0.0],
});
};
// Sides: one quad per texture repeat.
+1
View File
@@ -968,6 +968,7 @@ fn draw_normals(
layer: overlay,
color,
light,
glint_uv: [0.0, 0.0],
});
}
}
+6 -6
View File
@@ -167,8 +167,6 @@ impl Opt {
| Opt::NarratorHotkey
| Opt::ChatDelay
| Opt::DistortionEffects
| Opt::GlintSpeed
| Opt::GlintStrength
| Opt::MonochromeLogo
| Opt::RotateWithMinecarts
| Opt::HighContrastBlockOutlines
@@ -625,10 +623,12 @@ impl Opt {
self.file_key().unwrap(),
crate::options_file::V::Double(f64::from(v).powi(2)),
),
Opt::DamageTilt | Opt::PanoramaSpeed => s.file.set(
self.file_key().unwrap(),
crate::options_file::V::Double(f64::from(v)),
),
Opt::DamageTilt | Opt::PanoramaSpeed | Opt::GlintSpeed | Opt::GlintStrength => {
s.file.set(
self.file_key().unwrap(),
crate::options_file::V::Double(f64::from(v)),
)
}
Opt::Fov => s.fov = step(30.0, 110.0),
Opt::RenderDistance => s.render_distance = step(2.0, 64.0) as i32,
Opt::SimulationDistance => s.simulation_distance = step(5.0, 32.0) as i32,
+2
View File
@@ -3946,6 +3946,8 @@ impl ParticleEngine {
},
color,
light,
glint_uv: [0.0, 0.0],
});
}
}
+2
View File
@@ -119,6 +119,8 @@ pub fn shadow(
layer: crate::gfx::SHADOW_OVERLAY,
color,
light: 240 | 240 << 8,
glint_uv: [0.0, 0.0],
});
}
}