Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
OptiFine CIT: vanilla's glint stays off the GUI only; layers discard and fade like vanilla's; broken rules don't match; a capped array; one run per layer
some-du6e2a396df1088d
diff --git a/crates/horizon-client-render/src/cit.rs b/crates/horizon-client-render/src/cit.rsindex 6f556e23e..229f786f8 100644--- a/crates/horizon-client-render/src/cit.rs+++ b/crates/horizon-client-render/src/cit.rs@@ -118,6 +118,19 @@ impl CitRules {self.rules.is_empty()}+ /// Leave out the Enchantment rules `keep` refuses (those without a drawable texture): they+ /// match no stack, so vanilla's glint and the other rules of their layer stay.+ pub fn keep_glints(&mut self, keep: impl Fn(usize) -> bool) {+ self.any_item.retain(|&i| keep(i as usize));+ let named = &mut self.by_item[Kind::Enchantment as usize];+ for list in named.values_mut() {+ list.retain(|&i| keep(i as usize));+ }+ named.retain(|_, list| !list.is_empty());+ lock(&self.enchanted).clear();+ lock(&self.glints).clear();+ }+/// The winning rule of `kind` (Item, Armor or Elytra) for this stack, as an index into `rules`.pub fn select(&self,@@ -786,6 +799,34 @@ mod tests {);}+ #[test]+ fn a_rule_left_out_of_the_glints_matches_nothing() {+ let mut cit = rules(&[+ ("broken", "type=enchantment\nitems=diamond_sword\nweight=1"),+ ("shown", "type=enchantment"),+ ]);+ let sword = enchanted("diamond_sword", &[("sharpness", 1)]);+ let layers = |cit: &CitRules| -> Vec<String> {+ let glint = glint(cit, &sword, false).unwrap();+ let stems = glint+ .layers+ .iter()+ .map(|l| stem(cit, Some(l.rule)).unwrap());+ stems.map(str::to_owned).collect()+ };+ // The heavier rule wins the layer, until its texture is missing.+ assert_eq!(layers(&cit), ["broken"]);+ let broken = (0..cit.rules.len())+ .find(|&i| stem(&cit, Some(i)) == Some("broken"))+ .unwrap();+ cit.keep_glints(|i| i != broken);+ assert_eq!(layers(&cit), ["shown"]);+ assert_eq!(cit.enchantments(&sword, Hand::Main, 0).len(), 1);+ // None left: vanilla's glint stays.+ cit.keep_glints(|_| false);+ assert!(glint(&cit, &sword, false).is_none());+ }+#[test]fn an_off_hand_layer_draws_only_in_the_off_hand() {let cit = rules(&[diff --git a/crates/horizon-client-render/src/gfx.rs b/crates/horizon-client-render/src/gfx.rsindex 9df5e19c4..d8fbb39da 100644--- a/crates/horizon-client-render/src/gfx.rs+++ b/crates/horizon-client-render/src/gfx.rs@@ -1005,7 +1005,7 @@ const SPRITE_ARRAYS: u32 = 8;/// array. wgpu's OpenGL backend picks a texture's target from its layer/// count when it is created: one layer makes a 2D texture and a multiple of/// six a cube map, neither of which can be viewed as an array.-fn array_layers(count: u32, gl: bool) -> u32 {+pub(crate) fn array_layers(count: u32, gl: bool) -> u32 {match count {_ if !gl => count,0 | 1 => 2,diff --git a/crates/horizon-client-render/src/hud.wgsl b/crates/horizon-client-render/src/hud.wgslindex 73b6b270f..97d3af00a 100644--- a/crates/horizon-client-render/src/hud.wgsl+++ b/crates/horizon-client-render/src/hud.wgsl@@ -63,8 +63,12 @@ struct CitSlots {let blurred = textureSampleLevel(cit_tex, cit_blur, in.glint_uv, index, 0.0);let sharp = textureSampleLevel(cit_tex, cit_nearest, in.glint_uv, index, 0.0);if mask < 0.1 { discard; }- let c = select(sharp, blurred, slot.blur.x > 0.5) * slot.rgba;- return vec4(c.rgb * hud.size.w, c.a * in.color.a);+ // The layer's colour times its intensity (the glint strength option included) in alpha,+ // cut where vanilla's glint shader cuts, which CIT Resewn draws through.+ var t = select(sharp, blurred, slot.blur.x > 0.5) * slot.rgba;+ t.a *= in.color.a;+ if t.a < 0.1 { discard; }+ return t;}@fragment fn fs_crosshair(in: Out) -> @location(0) vec4<f32> {let c = textureSample(atlas, atlas_sampler, in.uv) * in.color;diff --git a/crates/horizon-client-render/src/hud/cit_glint.rs b/crates/horizon-client-render/src/hud/cit_glint.rsindex b985f942a..1afec496c 100644--- a/crates/horizon-client-render/src/hud/cit_glint.rs+++ b/crates/horizon-client-render/src/hud/cit_glint.rs@@ -8,10 +8,12 @@ use super::HudVertex;use horizon_optifine::cit::{Blend, Factor, Kind, Rule};use std::path::Path;-/// Slots the shader's table holds; rules past it draw no layer.+/// Slots the shader's table holds; rules past it draw no layer (and match no stack).pub const MAX_SLOTS: usize = 256;/// The largest side the shared texture size takes: bigger glints are scaled down to it.const MAX_SIDE: u32 = 1024;+/// The most the texture array takes, in bytes: past it the shared size is halved.+const MAX_BYTES: u64 = 64 << 20;/// One slot's constants.#[derive(Clone, Copy, Debug, PartialEq)]@@ -29,10 +31,11 @@ pub struct Slot {pub struct GlintTextures {pub width: u32,pub height: u32,- /// One `width` x `height` RGBA image per slot, slot after slot.+ /// One `width` x `height` RGBA image per slot, slot after slot. Kept after the upload: every+ /// split-screen player's renderer builds its own array from it.pub pixels: Vec<u8>,- /// Per rule (an index into `CitRules::rules`): its slot; `None` for other kinds of rules and- /// textures that did not load.+ /// Per rule (an index into `CitRules::rules`): its slot; `None` for other kinds of rules,+ /// textures that did not load and rules past `MAX_SLOTS`.pub slot_of: Vec<Option<u8>>,pub slots: Vec<Slot>,/// The blends the slots use, once each: the HUD makes a pipeline per entry.@@ -42,31 +45,36 @@ pub struct GlintTextures {impl GlintTextures {/// The textures of `rules` under the overlay resource root.pub fn load(root: &Path, rules: &[Rule]) -> Self {- let images = rules- .iter()- .enumerate()- .filter(|(_, r)| r.kind == Kind::Enchantment)- .filter_map(|(i, r)| {- let path = r.texture.as_deref()?;- match super::decode(&root.join(path)) {- Ok(image) => Some((i, image)),- Err(e) => {- log::warn!("custom item textures: glint {path} left out: {e}");- None- }- }- })- .take(MAX_SLOTS)- .collect();- Self::new(rules, images)+ let mut images = Vec::new();+ let mut past = 0;+ for (i, rule) in rules.iter().enumerate() {+ let Some(path) = rule.texture.as_deref() else {+ continue;+ };+ if rule.kind != Kind::Enchantment {+ continue;+ }+ if images.len() == MAX_SLOTS {+ past += 1;+ continue;+ }+ match super::decode(&root.join(path)) {+ Ok(image) => images.push((i, image)),+ Err(e) => log::warn!("custom item textures: glint {path} left out: {e}"),+ }+ }+ if past > 0 {+ log::warn!(+ "custom item textures: {past} glint rules past the first {MAX_SLOTS} left out"+ );+ }+ Self::new(rules, images, MAX_BYTES)}- /// `images`: (rule, (width, height, RGBA)).- fn new(rules: &[Rule], images: Vec<(usize, (u32, u32, Vec<u8>))>) -> Self {- let side = |pick: fn(&(u32, u32, Vec<u8>)) -> u32| {- images.iter().map(|(_, im)| pick(im).min(MAX_SIDE)).max()- };- let (Some(width), Some(height)) = (side(|im| im.0), side(|im| im.1)) else {+ /// `images`: (rule, (width, height, RGBA)), in at most `budget` bytes.+ fn new(rules: &[Rule], images: Vec<(usize, (u32, u32, Vec<u8>))>, budget: u64) -> Self {+ let sizes = images.iter().map(|(_, (w, h, _))| (*w, *h));+ let Some((width, height)) = shared_size(sizes, images.len(), budget) else {return Self::default();};let mut out = Self {@@ -76,8 +84,9 @@ impl GlintTextures {..Self::default()};for (rule, (w, h, rgba)) in images {- out.pixels.extend(resize(&rgba, w, h, width, height));let glint = &rules[rule].glint;+ out.pixels+ .extend(resize(&rgba, (w, h), (width, height), glint.blur));let blend = match out.blends.iter().position(|b| *b == glint.blend) {Some(i) => i,None => {@@ -100,18 +109,66 @@ impl GlintTextures {}}-/// Nearest-neighbour scaling: the glint repeats over the item, so its scale does not show.-fn resize(rgba: &[u8], w: u32, h: u32, to_w: u32, to_h: u32) -> Vec<u8> {- if (w, h) == (to_w, to_h) {+/// The size every slot takes: the largest width and height of `sizes`, each at most+/// `MAX_SIDE`, then halved until `layers` RGBA images of it fit in `budget` bytes.+fn shared_size(+ sizes: impl Iterator<Item = (u32, u32)>,+ layers: usize,+ budget: u64,+) -> Option<(u32, u32)> {+ let (mut w, mut h) = sizes.fold(None, |max: Option<(u32, u32)>, (w, h)| {+ let (w, h) = (w.clamp(1, MAX_SIDE), h.clamp(1, MAX_SIDE));+ Some(max.map_or((w, h), |(mw, mh)| (mw.max(w), mh.max(h))))+ })?;+ let bytes = |w: u32, h: u32| u64::from(w) * u64::from(h) * 4 * layers as u64;+ while bytes(w, h) > budget && (w > 1 || h > 1) {+ (w, h) = ((w / 2).max(1), (h / 2).max(1));+ }+ Some((w, h))+}++/// `rgba` (`from` texels) scaled to `to`: bilinearly for a `blur` glint, as the GPU would have+/// filtered the texture at its own size, else to the nearest texel. Both wrap at the edges, as+/// the glint repeats over the item.+fn resize(rgba: &[u8], from: (u32, u32), to: (u32, u32), smooth: bool) -> Vec<u8> {+ if from == to {return rgba.to_vec();}- let mut out = Vec::with_capacity((to_w * to_h * 4) as usize);+ let ((w, h), (to_w, to_h)) = (from, to);+ let texel = |x: i64, y: i64| {+ let (x, y) = (x.rem_euclid(i64::from(w)), y.rem_euclid(i64::from(h)));+ let at = (y as usize * w as usize + x as usize) * 4;+ &rgba[at..at + 4]+ };+ // Where texel `i` of `n` samples the source's `size` texels, in source texels.+ let centre = |i: u32, n: u32, size: u32| (f64::from(i) + 0.5) * f64::from(size) / f64::from(n);+ let mut out = Vec::with_capacity(to_w as usize * to_h as usize * 4);for y in 0..to_h {- let sy = (u64::from(y) * u64::from(h) / u64::from(to_h)) as usize;+ let sy = centre(y, to_h, h);for x in 0..to_w {- let sx = (u64::from(x) * u64::from(w) / u64::from(to_w)) as usize;- let at = (sy * w as usize + sx) * 4;- out.extend_from_slice(&rgba[at..at + 4]);+ let sx = centre(x, to_w, w);+ if !smooth {+ let pick = |i: u32, n: u32, size: u32| {+ (u64::from(i) * u64::from(size) / u64::from(n)) as i64+ };+ out.extend_from_slice(texel(pick(x, to_w, w), pick(y, to_h, h)));+ continue;+ }+ let (fx, fy) = (sx - 0.5, sy - 0.5);+ let (x0, y0) = (fx.floor() as i64, fy.floor() as i64);+ let (tx, ty) = (fx - fx.floor(), fy - fy.floor());+ let [a, b, c, d] = [+ texel(x0, y0),+ texel(x0 + 1, y0),+ texel(x0, y0 + 1),+ texel(x0 + 1, y0 + 1),+ ];+ let lerp =+ |p: &[u8], q: &[u8], k: usize| f64::from(p[k]) * (1.0 - tx) + f64::from(q[k]) * tx;+ out.extend((0..4).map(|k| {+ let (top, bottom) = (lerp(a, b, k), lerp(c, d, k));+ (top * (1.0 - ty) + bottom * ty).round() as u8+ }));}}out@@ -189,6 +246,27 @@ impl CitGlintPass {if textures.is_empty() {return None;}+ // wgpu's OpenGL backend makes 1 layer a 2D texture and 6n a cube map+ // (`gfx::array_layers`): pad with empty layers, within the GPU's limit. Slots past the+ // layers kept sample the last one.+ let gl = device.adapter_info().backend == wgpu::Backend::Gl;+ let max = device.limits().max_texture_array_layers.max(1);+ let slots = textures.slots.len() as u32;+ let mut kept = slots.min(max);+ while kept > 1 && crate::gfx::array_layers(kept, gl) > max {+ kept -= 1;+ }+ if kept < slots {+ log::warn!("custom item textures: the GPU holds {kept} of {slots} glint textures");+ }+ let layers = crate::gfx::array_layers(kept, gl).min(max);+ let layer_bytes = textures.width as usize * textures.height as usize * 4;+ let mut data = std::borrow::Cow::Borrowed(&textures.pixels[..]);+ if layers != slots {+ let mut padded = textures.pixels[..layer_bytes * kept as usize].to_vec();+ padded.resize(layer_bytes * layers as usize, 0);+ data = std::borrow::Cow::Owned(padded);+ }let texture = device.create_texture_with_data(queue,&wgpu::TextureDescriptor {@@ -196,7 +274,7 @@ impl CitGlintPass {size: wgpu::Extent3d {width: textures.width,height: textures.height,- depth_or_array_layers: textures.slots.len() as u32,+ depth_or_array_layers: layers,},mip_level_count: 1,sample_count: 1,@@ -206,7 +284,7 @@ impl CitGlintPass {view_formats: &[],},wgpu::util::TextureDataOrder::LayerMajor,- &textures.pixels,+ &data,);let view = texture.create_view(&wgpu::TextureViewDescriptor {dimension: Some(wgpu::TextureViewDimension::D2Array),@@ -382,6 +460,7 @@ mod tests {(2, (2, 2, quad.clone())),(3, (2, 2, quad.clone())),],+ MAX_BYTES,);assert_eq!((t.width, t.height), (2, 2));assert_eq!(t.slot_of, [Some(0), None, Some(1), Some(2)]);@@ -398,7 +477,53 @@ mod tests {assert_eq!(blends, [0, 1, 0]);assert_eq!(t.slots[0].rgba, [0.5, 1.0, 1.0, 1.0]);assert!(!t.slots[1].blur && t.slots[2].blur);- assert!(GlintTextures::new(&rules, Vec::new()).is_empty());+ assert!(GlintTextures::new(&rules, Vec::new(), MAX_BYTES).is_empty());+ }++ #[test]+ fn big_glints_are_scaled_down_to_the_largest_side() {+ let rules = [rule("wide", "type=enchantment\nblur=false")];+ // 2048 x 1, texel x holding x in red and green: every other texel is kept.+ let wide: Vec<u8> = (0..2048u32)+ .flat_map(|x| [(x % 256) as u8, (x / 256) as u8, 0, 255])+ .collect();+ let t = GlintTextures::new(&rules, vec![(0, (2048, 1, wide))], MAX_BYTES);+ assert_eq!((t.width, t.height), (1024, 1));+ for x in [0u32, 1, 300, 1023] {+ let at = x as usize * 4;+ let source = 2 * x;+ let want = [(source % 256) as u8, (source / 256) as u8, 0, 255];+ assert_eq!(t.pixels[at..at + 4], want, "texel {x}");+ }+ }++ #[test]+ fn the_array_is_halved_until_it_fits() {+ let sizes = |n: usize| std::iter::repeat_n((1024, 1024), n);+ // 16 layers of 1024 x 1024 RGBA are 64 MiB; a 17th halves both sides.+ assert_eq!(shared_size(sizes(16), 16, 64 << 20), Some((1024, 1024)));+ assert_eq!(shared_size(sizes(17), 17, 64 << 20), Some((512, 512)));+ // The largest of each side, never past MAX_SIDE.+ let mixed = [(16, 4096), (64, 32)].into_iter();+ assert_eq!(shared_size(mixed, 2, 64 << 20), Some((64, 1024)));+ assert_eq!(shared_size(std::iter::empty(), 0, 64 << 20), None);+ }++ #[test]+ fn blurred_glints_grow_smoothly_and_sharp_ones_by_texel() {+ // Black then white, doubled: the wrapping blend of the two, or each texel twice.+ let row = [0, 0, 0, 255, 255, 255, 255, 255];+ let red = |rgba: Vec<u8>| rgba.chunks(4).map(|t| t[0]).collect::<Vec<_>>();+ assert_eq!(red(resize(&row, (2, 1), (4, 1), true)), [64, 64, 191, 191]);+ assert_eq!(red(resize(&row, (2, 1), (4, 1), false)), [0, 0, 255, 255]);+ }++ #[test]+ fn a_layer_vertex_carries_its_slot_and_intensity() {+ // Unorm8x4 reads the colour's bytes in memory order: r, g, b, a.+ assert_eq!(vertex_color(3, 0.5).to_le_bytes(), [3, 0, 0, 128]);+ assert_eq!(vertex_color(200, 2.0).to_le_bytes(), [200, 0, 0, 255]);+ assert_eq!(vertex_color(0, -1.0).to_le_bytes(), [0, 0, 0, 0]);}#[test]@@ -434,6 +559,5 @@ mod tests {blend_state(parse_blend("replace").unwrap()),wgpu::BlendState::REPLACE);- assert_eq!(vertex_color(3, 0.5), super::super::rgba(3, 0, 0, 128));}}diff --git a/crates/horizon-client/src/game/item_draw.rs b/crates/horizon-client/src/game/item_draw.rsindex 3029a4d4d..7f4578a32 100644--- a/crates/horizon-client/src/game/item_draw.rs+++ b/crates/horizon-client/src/game/item_draw.rs@@ -296,8 +296,6 @@ impl Game<'_> {) -> ItemRenderState {self.resolve_item_in_hand(stack, display, owner, seed, CitHand::Main)}- /// [`Self::resolve_item`] of a stack held in `hand`, which OptiFine CIT rules can test- /// (GUI items count as the main hand)./// `ItemStack.hasFoil`, with the item's default glint.fn has_foil(&self, stack: &ItemStack) -> bool {let item_glint = self@@ -309,6 +307,8 @@ impl Game<'_> {.is_some_and(|p| p.glint);stack.has_foil(item_glint)}+ /// [`Self::resolve_item`] of a stack held in `hand`, which OptiFine CIT rules can test+ /// (GUI items count as the main hand).pub(super) fn resolve_item_in_hand(&self,stack: &ItemStack,@@ -342,14 +342,20 @@ impl Game<'_> {rule,);if let Some(glint) = glint {- // The pack's enchantment rules replace vanilla's glint unless one keeps it.- if !glint.vanilla {+ // The pack's enchantment rules replace vanilla's glint unless one keeps it, so far+ // only in the GUI, where their own layers draw: held, dropped and framed items keep+ // vanilla's until theirs do. The pack's `useGlint=false` removes it everywhere.+ let gui = display == DisplayContext::Gui;+ let pack_keeps = renderer+ .cit+ .as_ref()+ .is_none_or(|c| c.rules.global.use_glint);+ if !glint.vanilla && (gui || !pack_keeps) {for layer in &mut state.layers {layer.foil = horizon_assets::item_model::FoilType::None;}}- // Their own layers draw in the GUI only so far.- if display == DisplayContext::Gui && !glint.is_empty() {+ if gui && !glint.is_empty() {state.cit_glint = Some(glint);}}diff --git a/crates/horizon-client/src/item_render/cit.rs b/crates/horizon-client/src/item_render/cit.rsindex 1e4703aad..7d1bcfec0 100644--- a/crates/horizon-client/src/item_render/cit.rs+++ b/crates/horizon-client/src/item_render/cit.rs@@ -120,6 +120,12 @@ pub(super) fn load(};let mut models = CitModels::new(rules);models.glint_textures = GlintTextures::load(root, &models.rules.rules);+ // An enchantment rule whose texture has no slot draws nothing, so it must not take its+ // layer (or vanilla's glint) from the stack either.+ let slots = &models.glint_textures.slot_of;+ models+ .rules+ .keep_glints(|i| slots.get(i).copied().flatten().is_some());(library, Some(models))}diff --git a/crates/horizon-client/src/item_render/gui.rs b/crates/horizon-client/src/item_render/gui.rsindex 82a475ab5..a25ae62bf 100644--- a/crates/horizon-client/src/item_render/gui.rs+++ b/crates/horizon-client/src/item_render/gui.rs@@ -137,31 +137,38 @@ struct CitDraw<'a> {millis: f32,}-/// The CIT glint layers over one clipped face, bottom first, each blended as its rule says.-fn emit_cit(batch: &mut HudBatch, fan: &[Point], cit: CitDraw) {+/// The CIT glint layers over the item's clipped faces (`fans`, in draw order), bottom first:+/// each layer is one run over all of them, blended as its rule says, at its intensity times+/// the glint strength option (`HudBatch::glint_alpha`).+fn emit_cit(batch: &mut HudBatch, fans: &[Vec<Point>], cit: CitDraw) {+ let seconds = f64::from(cit.millis) / 1000.0;for (i, layer) in cit.glint.layers.iter().enumerate() {let Some(slot) = cit.textures.slot_of.get(layer.rule).copied().flatten() else {continue;};- let intensity = cit.glint.intensity(i, f64::from(cit.millis) / 1000.0);+ let Some(constants) = cit.textures.slots.get(usize::from(slot)) else {+ continue;+ };+ let intensity = cit.glint.intensity(i, seconds) * batch.glint_alpha;if intensity <= 0.0 {continue;}let glint = &cit.rules[layer.rule].glint;let color = vertex_color(slot, intensity);- let blend = crate::hud::Blend::CitGlint(cit.textures.slots[usize::from(slot)].blend);let uv = |v: Point| layer_uv(v.glint_uv, cit.millis, glint.speed, glint.rotation, 8.0);- for k in 1..fan.len().saturating_sub(1) {- let corners = [fan[0], fan[k], fan[k + 1], fan[k + 1]];- let start = batch.vertices.len();- batch.quad_glint(- corners.map(|v| v.p.to_array()),- corners.map(|v| v.uv),- corners.map(uv),- color,- );- batch.blend_since(start, blend);+ let start = batch.vertices.len();+ for fan in fans {+ for k in 1..fan.len().saturating_sub(1) {+ let corners = [fan[0], fan[k], fan[k + 1], fan[k + 1]];+ batch.quad_glint(+ corners.map(|v| v.p.to_array()),+ corners.map(|v| v.uv),+ corners.map(uv),+ color,+ );+ }}+ batch.blend_since(start, crate::hud::Blend::CitGlint(constants.blend));}}@@ -378,7 +385,7 @@ fn draw_quads(draw_quads_with(quads, lights, batch, rect, glint, None);}-/// [`draw_quads`] with a stack's CIT glint layers over every face.+/// [`draw_quads`], then a stack's CIT glint layers over every face.fn draw_quads_with(quads: &[ItemQuad],lights: (Vec3, Vec3),@@ -387,6 +394,8 @@ fn draw_quads_with(glint: Option<&Glint>,cit: Option<CitDraw>,) {+ // The faces the CIT layers go over once the item is drawn.+ let mut fans = Vec::new();for face in depth::sort(quads) {let q = &quads[face.quad];let points: Vec<_> = face@@ -409,11 +418,14 @@ fn draw_quads_with(if q.foil != Foil::None {emit(batch, &fan, |_| color, glint);}- if let Some(cit) = cit {- emit_cit(batch, &fan, cit);+ if cit.is_some() {+ fans.push(fan);}}}+ if let Some(cit) = cit {+ emit_cit(batch, &fans, cit);+ }}/// `PictureInPictureRenderer.prepare` for the loom's 20x40 result rectangle@@ -674,6 +686,65 @@ mod tests {}}+ #[test]+ fn cit_layers_draw_once_over_the_whole_item() {+ use crate::cit_glint::Global;+ use crate::hud::Blend;+ use crate::hud::cit_glint::Slot;+ use horizon_optifine::Properties;+ let rule = |name: &str, text: &str| {+ let path = format!("assets/minecraft/optifine/cit/{name}.properties");+ let text = format!("type=enchantment\ntexture=glint\n{text}");+ Rule::parse(&path, &Properties::parse_equals_first(&text), |_| true).unwrap()+ };+ let rules = [+ rule("shown", ""),+ rule("fire", "layer=1\nenchantments=fire_aspect"),+ ];+ // Shared by level, and the stack has no Fire Aspect: that layer is at intensity 0.+ let global = Global::parse(&Properties::parse_equals_first("method=average"));+ let glint = StackGlint::new(&rules, &[0, 1], &[("minecraft:sharpness", 3)], &global);+ assert_eq!(glint.layers.len(), 2);+ let slot = |blend| Slot {+ rgba: [1.0; 4],+ blur: false,+ blend,+ };+ let textures = GlintTextures {+ width: 1,+ height: 1,+ slot_of: vec![Some(1), Some(0)],+ slots: vec![slot(0), slot(1)],+ ..GlintTextures::default()+ };+ let cit = CitDraw {+ glint: &glint,+ textures: &textures,+ rules: &rules,+ millis: 0.0,+ };+ let mut batch = HudBatch::new([320, 240]);+ batch.glint_alpha = 0.5;+ draw_quads_with(+ &[face(0.0, 8.0, |_| 0.0, 0xFFFF_FFFF)],+ (Vec3::Z, Vec3::Z),+ &mut batch,+ [0.0, 0.0, 16.0, 16.0],+ None,+ Some(cit),+ );+ // The square's two triangles, then the one layer over both: six vertices a triangle.+ assert_eq!(batch.vertices.len(), 24);+ assert_eq!(+ batch.runs(),+ [(0..12, Blend::Alpha), (12..24, Blend::CitGlint(1))]+ );+ for v in &batch.vertices[12..] {+ // Slot 1 in red; full intensity at half the glint strength in alpha.+ assert_eq!(v.color.to_le_bytes(), [1, 0, 0, 128]);+ }+ }+#[test]fn flat_lights_match_joml() {// new Matrix4f().rotationY(-PI/8).rotateX(3PI/4).transformDirection(L0).diff --git a/docs/resource-packs.md b/docs/resource-packs.mdindex 76dd1702f..41ae91dba 100644--- a/docs/resource-packs.md+++ b/docs/resource-packs.md@@ -67,13 +67,13 @@ harness named checks that loader against vanilla).| Sky: sun, moon phases, stars, end sky, clouds, rain and snow | `atlases/celestials.json`, `textures/environment/` | works | `test_environment_render_parity`, `test_cloud_render_parity`, `test_weather_render_parity` || Title panorama | `textures/gui/title/background/` | works | `gfx/panorama.rs` loads it from the overlay || Screen overlays: vignette, pumpkin, powder snow, nausea, underwater, world border | `textures/misc/` | works | `test_world_border_render_parity`, `test_hud_parity`; loaded from the overlay |-| Enchantment glint | `textures/misc/enchanted_glint_*` | works | `item_render/gui.rs`, `entity.wgsl` |+| Enchantment glint | `textures/misc/enchanted_glint_*` | works | `item_render/gui.rs`, `hud/cit_glint.rs`, `entity.wgsl` || Maps: background, decorations | `textures/map/`, `atlases/map_decorations.json` | works | loaded from the overlay || Paintings, mob effect icons | `atlases/paintings.json`, `textures/mob_effect/` | works | loaded from the overlay || Locator bar styles | `waypoint_style/` | **no** | the locator bar isn't drawn yet || Post effects (spectating a creeper, spider or enderman; glowing outlines) | `post_effect/`, `shaders/post/` | **no** | Horizon's effects are WGSL; a pack's GLSL post chain isn't run || Core shaders | `shaders/core/`, `shaders/include/` | partly | `core/text` draws the GUI's text (HUDs moved by its vertex shader, text effects), translated by naga (`horizon-shaders` `core_shader.rs`, `hud/pack_text.rs`); the other core shaders aren't run |-| OptiFine / CIT Resewn custom item textures (`type=item`: `texture`, `model`, `texture.<name>`, `model.<name>`; `type=armor`: `texture`, `texture.<layer>` with the pre-1.21.2 layer names such as `diamond_layer_1`, `leather_layer_2_overlay`; `type=elytra`: `texture`) | `optifine/cit/`, `mcpatcher/cit/`, `citresewn/cit/` | partly | `item_render/cit.rs` and `cit_armor.rs` tests; enchantment glints come in a later PR; special renderers (heads, shields, banners) keep their vanilla look; only players and armour stands wear CIT armour and elytra, other mobs keep vanilla's; worn trims are unchanged; armour textures above 1024x512 (16 times vanilla's 64x32) draw vanilla |+| OptiFine / CIT Resewn custom item textures (`type=item`: `texture`, `model`, `texture.<name>`, `model.<name>`; `type=armor`: `texture`, `texture.<layer>` with the pre-1.21.2 layer names such as `diamond_layer_1`, `leather_layer_2_overlay`; `type=elytra`: `texture`; `type=enchantment` layers on GUI items; `useGlint=false` in `cit.properties`, which removes vanilla's glint from items) | `optifine/cit/`, `mcpatcher/cit/`, `citresewn/cit/` | partly | `item_render/cit.rs`, `cit_armor.rs`, `cit_glint.rs` and `hud/cit_glint.rs` tests; enchantment layers on held, dropped, framed and worn items, and `anim/` glints, come later; special renderers (heads, shields, banners) keep their vanilla look; only players and armour stands wear CIT armour and elytra, other mobs keep vanilla's; worn trims are unchanged; armour textures above 1024x512 (16 times vanilla's 64x32) draw vanilla || GPU warn list, regional compliance | `gpu_warnlist.json`, `regional_compliancies.json` | n/a | OpenGL driver warnings and play-time notices for some regions; not used |Summary: 46 rows; 32 work, 5 partly, 7 don't (interpolated animation, TrueType fonts, credits and end poem,