Items: animate the armour glint from enchanted_glint_armor
Enchanted worn armour lost its animation: mobs/render.rs gave every armour vertex [0, 0] for glint_uv, while the entity shader samples the glint at that coordinate for overlay 7, so the armour showed a single texel instead of the scrolling pattern. Armour layers now carry overlay 13 (ARMOR_GLINT) and the layer's model UV. entity.wgsl applies ARMOR_ENTITY_GLINT_TEXTURING (scale 0.16) and samples misc/enchanted_glint_armor through the same repeating, linear GlintSampler as items, matching ARMOR_CUTOUT_NO_CULL_GLINT. The scroll clock (millis * glintSpeed * 8 modulo the offsets' common period) rides in globals.time.w, so armour and items move together. Addresses the review comment on #2296. Co-Authored-By: ZCode <agent@zcode.dev>
This commit is contained in:
@@ -14,7 +14,8 @@ struct Globals {
|
||||
// Atlas rects (u0, v0, width, height) of end_sky.png and end_portal.png.
|
||||
end_portal_sprites: array<vec4<f32>, 2>,
|
||||
// x: vanilla's GameTime ((game time % 24000 + partial tick) / 24000)
|
||||
// y: Nether cardinal lighting, z: how many dynamic_lights are set.
|
||||
// y: Nether cardinal lighting, z: how many dynamic_lights are set,
|
||||
// w: the glint scroll clock (`Glint::scroll_ticks`).
|
||||
time: vec4<f32>,
|
||||
crumbling_sprite: vec4<f32>,
|
||||
// Selection outline parameters (read by terrain.wgsl).
|
||||
@@ -30,6 +31,9 @@ struct Globals {
|
||||
// enchanted_glint_item on its own repeating texture (vanilla's GlintSampler).
|
||||
@group(0) @binding(5) var glint_tex: texture_2d<f32>;
|
||||
@group(0) @binding(6) var glint_sampler: sampler;
|
||||
// The armour layers' GlintSampler: vanilla samples enchanted_glint_armor with
|
||||
// the same repeating, linearly filtered sampler as the item glint.
|
||||
@group(0) @binding(7) var glint_armor_tex: texture_2d<f32>;
|
||||
struct Out {
|
||||
@builtin(position) clip: vec4<f32>,
|
||||
@location(0) uv: vec2<f32>,
|
||||
@@ -47,7 +51,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).
|
||||
// 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>,
|
||||
}
|
||||
// Shipped light.glsl; normals are already transformed and RGBA8_SNORM packed.
|
||||
@@ -176,6 +181,27 @@ fn linear_fog(d: f32, start: f32, end: f32) -> f32 {
|
||||
if d >= end { return 1.0; }
|
||||
return (d - start) / (end - start);
|
||||
}
|
||||
// TextureTransform.setupGlintTexturing(0.16), ARMOR_ENTITY_GLINT_TEXTURING.
|
||||
// globals.time.w is (Util.getMillis() * glintSpeed * 8) modulo 330000, the
|
||||
// common period of both offsets.
|
||||
fn armor_glint_uv(model: vec2<f32>) -> vec2<f32> {
|
||||
let ticks = globals.time.w;
|
||||
let offset0 = (ticks % 110000.0) / 110000.0;
|
||||
let offset1 = (ticks % 30000.0) / 30000.0;
|
||||
let angle = 0.17453292;
|
||||
let c = cos(angle);
|
||||
let s = sin(angle);
|
||||
let scaled = model * 0.16;
|
||||
return vec2(scaled.x * c - scaled.y * s - offset0,
|
||||
scaled.x * s + scaled.y * c + offset1);
|
||||
}
|
||||
// RenderPipelines.GLINT: the source colour is scaled by itself, so `GlintAlpha`
|
||||
// is squared along with the sample.
|
||||
fn glint_over(color: vec4<f32>, glint: vec4<f32>) -> vec4<f32> {
|
||||
let alpha = globals.fog_ends.w;
|
||||
let g = alpha * glint;
|
||||
return vec4(color.rgb + g.rgb * g.rgb, max(color.a, alpha));
|
||||
}
|
||||
// CRUMBLING_UV_BEGIN
|
||||
fn crumbling_uv(uv: vec2<f32>, packed_origin: vec2<f32>, sprite_size: vec2<f32>, dimensions: vec2<u32>) -> vec2<f32> {
|
||||
let size = vec2<f32>(dimensions);
|
||||
@@ -216,9 +242,13 @@ fn crumbling_uv(uv: vec2<f32>, packed_origin: vec2<f32>, sprite_size: vec2<f32>,
|
||||
if in.overlay == 7u || in.overlay == 8u {
|
||||
// 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(glint_tex, glint_sampler, in.glint_uv);
|
||||
color = vec4(color.rgb + glint.rgb * glint.rgb, max(color.a, alpha));
|
||||
color = glint_over(color, textureSample(glint_tex, glint_sampler, in.glint_uv));
|
||||
} else if in.overlay == 13u {
|
||||
// Enchanted armour: enchanted_glint_armor at the scrolling model UV.
|
||||
color = glint_over(
|
||||
color,
|
||||
textureSample(glint_armor_tex, glint_sampler, armor_glint_uv(in.glint_uv)),
|
||||
);
|
||||
}
|
||||
let f = max(linear_fog(in.spherical, globals.fog.x, globals.fog.y),
|
||||
linear_fog(in.cylindrical, globals.fog.z, globals.fog.w));
|
||||
|
||||
@@ -10806,6 +10806,7 @@ impl Game<'_> {
|
||||
debug_crosshair: &debug_crosshair,
|
||||
hud: &hud,
|
||||
glint_alpha: self.settings.file.double("glintStrength") as f32,
|
||||
glint_ticks: self.glint_ticks(),
|
||||
clouds: (!title
|
||||
&& self.dim == Dim::Overworld
|
||||
&& horizon_client::clouds::visible(&self.settings.clouds, sky.cloud_color[3]))
|
||||
@@ -13386,6 +13387,11 @@ fn build_renderer(
|
||||
&assets.animations,
|
||||
(&atlas.pixels, atlas.width, atlas.height),
|
||||
(&atlas.glint.0, atlas.glint.1, atlas.glint.2),
|
||||
(
|
||||
&atlas.glint_armor.0,
|
||||
atlas.glint_armor.1,
|
||||
atlas.glint_armor.2,
|
||||
),
|
||||
(&pack.forcefield.2, pack.forcefield.0),
|
||||
&gui.panorama,
|
||||
prepared,
|
||||
@@ -13444,6 +13450,7 @@ fn loading_renderer(
|
||||
&[],
|
||||
(pixels, width, height),
|
||||
(glint_pixels, glint_width, glint_height),
|
||||
(glint_pixels, glint_width, glint_height),
|
||||
(&FORCEFIELD[..], 1),
|
||||
panorama,
|
||||
None,
|
||||
@@ -13491,6 +13498,7 @@ fn loading_frame(hud: &HudBatch) -> Frame<'_> {
|
||||
debug_crosshair: &[],
|
||||
hud,
|
||||
glint_alpha: 0.75,
|
||||
glint_ticks: 0.0,
|
||||
nether_lighting: false,
|
||||
entities: &[],
|
||||
entity_spans: &[],
|
||||
|
||||
@@ -314,6 +314,14 @@ impl Game<'_> {
|
||||
scale: 0.5,
|
||||
})
|
||||
}
|
||||
/// The glint scroll phase shared by world items and armour
|
||||
/// (`item_render::Glint::scroll_ticks`).
|
||||
pub(super) fn glint_ticks(&self) -> f32 {
|
||||
item_render::Glint::scroll_ticks(
|
||||
self.started.elapsed().as_secs_f32() * 1000.0,
|
||||
self.settings.file.double("glintSpeed") as f32,
|
||||
)
|
||||
}
|
||||
/// Submit a resolved item under `pose` (camera-relative) at `light`
|
||||
/// (packed lightmap coordinates).
|
||||
pub(super) fn submit_item_world(
|
||||
|
||||
@@ -178,7 +178,7 @@ struct Globals {
|
||||
/// Atlas rects (u0, v0, width, height) of end_sky.png and end_portal.png.
|
||||
end_portal_sprites: [[f32; 4]; 2],
|
||||
/// x: vanilla's `GameTime` uniform; y: nether cardinal lighting; z: how many
|
||||
/// `dynamic_lights` are set; w unused.
|
||||
/// `dynamic_lights` are set; w: the glint scroll clock (`Glint::scroll_ticks`).
|
||||
time: [f32; 4],
|
||||
/// Atlas rect of a destroy stage (entity.wgsl takes only its size: every stage's is the same,
|
||||
/// and each crack carries its own stage's origin).
|
||||
@@ -260,6 +260,9 @@ pub struct Frame<'a> {
|
||||
/// `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,
|
||||
/// The glint scroll clock (`Glint::scroll_ticks`): entity.wgsl's
|
||||
/// `ARMOR_ENTITY_GLINT_TEXTURING` phase.
|
||||
pub glint_ticks: f32,
|
||||
/// CardinalLighting.Type.NETHER, otherwise DEFAULT.
|
||||
pub nether_lighting: bool,
|
||||
/// Camera-relative entity geometry textured from the shared atlas.
|
||||
@@ -1024,6 +1027,7 @@ impl Renderer {
|
||||
animations: &[SpriteAnimation],
|
||||
hud_atlas: (&[u8], u32, u32),
|
||||
glint: (&[u8], u32, u32),
|
||||
glint_armor: (&[u8], u32, u32),
|
||||
forcefield: (&[u8], u32),
|
||||
panorama_faces: &panorama::Faces,
|
||||
prepared: Option<PreparedTextures>,
|
||||
@@ -1609,6 +1613,29 @@ impl Renderer {
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
..Default::default()
|
||||
});
|
||||
// ARMOR_ENTITY_GLINT_TEXTURING's sampler is vanilla's GlintSampler: the
|
||||
// same repeat and linear filtering as the item glint.
|
||||
let (glint_armor_pixels, glint_armor_width, glint_armor_height) = glint_armor;
|
||||
let glint_armor_texture = device.create_texture_with_data(
|
||||
&queue,
|
||||
&wgpu::TextureDescriptor {
|
||||
label: Some("Enchanted armor glint"),
|
||||
size: wgpu::Extent3d {
|
||||
width: glint_armor_width,
|
||||
height: glint_armor_height,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8Unorm,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING,
|
||||
view_formats: &[],
|
||||
},
|
||||
wgpu::util::TextureDataOrder::LayerMajor,
|
||||
glint_armor_pixels,
|
||||
);
|
||||
let glint_armor_view = glint_armor_texture.create_view(&Default::default());
|
||||
let mut hud = HudRenderer::new(
|
||||
&device,
|
||||
config.format.remove_srgb_suffix(),
|
||||
@@ -1675,6 +1702,15 @@ impl Renderer {
|
||||
vf,
|
||||
wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||
),
|
||||
entry(
|
||||
7,
|
||||
vf,
|
||||
wgpu::BindingType::Texture {
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
multisampled: false,
|
||||
},
|
||||
),
|
||||
],
|
||||
});
|
||||
let weather = weather::Weather::new(
|
||||
@@ -1719,6 +1755,10 @@ impl Renderer {
|
||||
binding: 6,
|
||||
resource: wgpu::BindingResource::Sampler(&glint_sampler),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 7,
|
||||
resource: wgpu::BindingResource::TextureView(&glint_armor_view),
|
||||
},
|
||||
],
|
||||
});
|
||||
let hand_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
@@ -1753,6 +1793,10 @@ impl Renderer {
|
||||
binding: 6,
|
||||
resource: wgpu::BindingResource::Sampler(&glint_sampler),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 7,
|
||||
resource: wgpu::BindingResource::TextureView(&glint_armor_view),
|
||||
},
|
||||
],
|
||||
});
|
||||
let entity_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
@@ -3557,7 +3601,7 @@ impl Renderer {
|
||||
frame.shader_game_time,
|
||||
f32::from(frame.nether_lighting),
|
||||
frame.dynamic_lights.len().min(crate::dynamic_light::MAX) as f32,
|
||||
0.0,
|
||||
frame.glint_ticks,
|
||||
],
|
||||
outline_params: outline_params(self.config.width, self.config.height),
|
||||
dynamic_lights: {
|
||||
|
||||
@@ -70,6 +70,8 @@ pub struct HudAtlas {
|
||||
/// `misc/enchanted_glint_item` as its own image: vanilla's `GlintSampler`
|
||||
/// repeats it per pixel, which one sprite inside this atlas cannot.
|
||||
pub glint: (Vec<u8>, u32, u32),
|
||||
/// `misc/enchanted_glint_armor`, the armour layers' `GlintSampler`.
|
||||
pub glint_armor: (Vec<u8>, u32, u32),
|
||||
white: Rect,
|
||||
}
|
||||
/// Atlas rows reserved for glyphs rasterized at run time.
|
||||
@@ -529,7 +531,8 @@ impl HudAtlas {
|
||||
}
|
||||
}
|
||||
let white = sprites["horizon/white"];
|
||||
let glint = Self::glint_texture(root, defaults);
|
||||
let glint = Self::glint_texture(root, defaults, "enchanted_glint_item");
|
||||
let glint_armor = Self::glint_texture(root, defaults, "enchanted_glint_armor");
|
||||
let font = crate::font::Font::load(
|
||||
root,
|
||||
&sprites,
|
||||
@@ -547,16 +550,18 @@ impl HudAtlas {
|
||||
flags,
|
||||
fire_animations,
|
||||
glint,
|
||||
glint_armor,
|
||||
font,
|
||||
white,
|
||||
})
|
||||
}
|
||||
/// `misc/enchanted_glint_item.png` on its own, or a transparent texel if
|
||||
/// the resource pack lacks it.
|
||||
fn glint_texture(root: &Path, defaults: &Path) -> (Vec<u8>, u32, u32) {
|
||||
let mut path = root.join("assets/minecraft/textures/misc/enchanted_glint_item.png");
|
||||
/// `misc/<name>.png` on its own, or a transparent texel if the resource
|
||||
/// pack lacks it.
|
||||
fn glint_texture(root: &Path, defaults: &Path, name: &str) -> (Vec<u8>, u32, u32) {
|
||||
let relative = format!("assets/minecraft/textures/misc/{name}.png");
|
||||
let mut path = root.join(&relative);
|
||||
if !path.exists() && defaults != root {
|
||||
path = defaults.join("assets/minecraft/textures/misc/enchanted_glint_item.png");
|
||||
path = defaults.join(&relative);
|
||||
}
|
||||
decode(&path).map_or((vec![0; 4], 1, 1), |(w, h, pixels)| (pixels, w, h))
|
||||
}
|
||||
|
||||
@@ -60,18 +60,29 @@ pub struct Glint {
|
||||
/// `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.
|
||||
/// `ENTITY_GLINT_TEXTURING`'s 0.5 for items in the world and
|
||||
/// `ARMOR_ENTITY_GLINT_TEXTURING`'s 0.16 for armour (entity.wgsl).
|
||||
pub scale: f32,
|
||||
}
|
||||
impl Glint {
|
||||
/// `Util.getMillis() * glintSpeed * 8.0` as vanilla's long.
|
||||
fn ticks(millis: f32, speed: f32) -> i64 {
|
||||
(f64::from(millis) * f64::from(speed) * 8.0) as i64
|
||||
}
|
||||
/// The scroll clock modulo the common period of both offsets (110000 and
|
||||
/// 30000 divide 330000), for `globals.time.w`: the entity shader derives
|
||||
/// `ARMOR_ENTITY_GLINT_TEXTURING` from it.
|
||||
pub fn scroll_ticks(millis: f32, speed: f32) -> f32 {
|
||||
(Self::ticks(millis, speed) % 330_000) as f32
|
||||
}
|
||||
/// `TextureTransform.setupGlintTexturing(scale)` applied to the model UV:
|
||||
/// translation(-o0, o1) * rotateZ(PI/18) * scale. The result repeats:
|
||||
/// the shader samples the dedicated glint texture with vanilla's
|
||||
/// repeating `GlintSampler`, so the UVs stay unwrapped.
|
||||
pub fn 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 ticks = Self::ticks(self.millis, self.speed);
|
||||
let offset0 = (ticks % 110_000) as f32 / 110_000.0;
|
||||
let offset1 = (ticks % 30_000) as f32 / 30_000.0;
|
||||
let angle = std::f32::consts::PI / 18.0;
|
||||
let (sin, cos) = angle.sin_cos();
|
||||
[
|
||||
|
||||
@@ -14,6 +14,12 @@ use std::f32::consts::PI;
|
||||
/// A texture lookup into the shared atlas (name without namespace -> uv rect).
|
||||
pub type Atlas<'a> = &'a dyn Fn(&str) -> Option<[f32; 4]>;
|
||||
|
||||
/// The overlay code of an enchanted armour layer's glint. 7 and 8 are the
|
||||
/// item glint and 9 to 12 Horizon's End-portal and breaking overlays, so 13
|
||||
/// marks the `ARMOR_ENTITY_GLINT_TEXTURING` sample: entity.wgsl transforms
|
||||
/// the model UV and reads `enchanted_glint_armor`.
|
||||
pub const ARMOR_GLINT: u32 = 13;
|
||||
|
||||
/// One draw of a model with a texture.
|
||||
pub struct Layer {
|
||||
pub model: String,
|
||||
@@ -958,6 +964,13 @@ fn draw_normals(
|
||||
let normal = poly.vertex_normal(normals);
|
||||
for v in poly.vertices {
|
||||
let pos = m.transform_point3(glam::Vec3::new(v[0], v[1], v[2]) / 16.0);
|
||||
// The armour glint scrolls the layer's model UV in the shader;
|
||||
// the item path already passed its transformed UV.
|
||||
let glint_uv = if overlay == ARMOR_GLINT {
|
||||
[v[3], v[4]]
|
||||
} else {
|
||||
[0.0, 0.0]
|
||||
};
|
||||
out.push(Vertex {
|
||||
normal,
|
||||
pos: pos.to_array(),
|
||||
@@ -968,7 +981,7 @@ fn draw_normals(
|
||||
layer: overlay,
|
||||
color,
|
||||
light,
|
||||
glint_uv: [0.0, 0.0],
|
||||
glint_uv,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1129,9 +1142,9 @@ fn render_visible(
|
||||
light
|
||||
};
|
||||
// EquipmentLayerRenderer draws armour with OverlayTexture.NO_OVERLAY: never
|
||||
// the hurt tint, the glint (7) when enchanted.
|
||||
// the hurt tint, the armour glint (13) when enchanted.
|
||||
let overlay = match armor_slot(&layer.model) {
|
||||
Some(slot) if super::gear::enchanted(m, slot) => 7,
|
||||
Some(slot) if super::gear::enchanted(m, slot) => ARMOR_GLINT,
|
||||
Some(_) => 0,
|
||||
None => overlay,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user