[PR #201] [MERGED] Sprite mips from vanilla's MipmapGenerator: no cactus corner gaps #2401

Closed
opened 2026-11-02 15:55:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/201
Author: @ludovic111
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @ludovic111

Base: main ← Head: fix/cactus-mips-110


📝 Commits (1)

  • 95db0fc Sprite mips from MipmapGenerator: cutout edges keep their coverage

📊 Changes

9 files changed (+582 additions, -35 deletions)

View changed files

➕ crates/horizon-client/examples/mipmap_probe.rs (+54 -0)
📝 crates/horizon-client/src/assets.rs (+3 -0)
📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/gfx.rs (+46 -35)
📝 crates/horizon-client/src/lib.rs (+1 -0)
➕ crates/horizon-client/src/mipmap.rs (+334 -0)
📝 crates/horizon-client/src/sprites.rs (+24 -0)
➕ mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMipmapOracle.java (+65 -0)
➕ tools/test_mipmap_parity.py (+54 -0)

📄 Description

Fixes #110

What differs from vanilla. Vanilla 26.3 builds every sprite's mip levels with MipmapGenerator.generateMipLevels: for cutout textures (strategy auto with a fully transparent pixel, or cutout/strict_cutout/dark_cutout from the texture's .mcmeta), it solidifys the base, averages in linear light (ARGB.meanLinear) and then scaleAlphaToCoverages every level so its alpha-test coverage (0.5, or 0.3 for strict) stays the base level's, plus the .mcmeta alpha_cutoff_bias (cactus_side has 0.1) and 0.025. Horizon averaged alpha plainly (gfx::mip_chain), so each level lost coverage: the cactus side's transparent border columns widened past the cutout and opened slits along the corners from about 40 blocks.

Fix. horizon_client::mipmap is a port of MipmapGenerator (alphaTestCoverage, scaleAlphaToCoverage, TextureUtil.solidify with its breadth-first order, fillEmptyAreasWithDarkColor, meanLinear, darkenedAlphaBlend, the SRGB_TO_LINEAR/LINEAR_TO_SRGB tables with Java's Math.round). Sprites reads each texture's .mcmeta texture section and its transparency (NativeImage.computeTransparency over the whole image) and the renderer builds the sprite array's mips (and the world border's MipmappedTexture) with it. Animated sprites get their mips per frame (vanilla mips the whole strip at once; the per-frame result only differs for cutout animations).

Harness (new): tools/test_mipmap_parity.py. VanillaMipmapOracle runs the pinned client's MipmapGenerator on each texture with its .mcmeta settings; examples/mipmap_probe loads the same sprites through sprites::Sprites and runs mipmap::generate. Mac mini: 1,319 sprites (every static 16x16 block texture and every 7th item texture), all 5 levels byte-identical (7,914 output lines).

In game (vscreen): a 4-high cactus column against the sky, seen from 45°, main against this branch; sky pixels showing through inside the cactus silhouette:

distance main this PR
12, 20, 28 blocks 0 0
40 blocks 68 0
56 blocks 49 0

agent-state/wave5b-shots/110-cactus-45deg-28-40-56.png on the desktop (pairs main / PR at 28, 40, 56 blocks; the slit on main's corner is closed here).

cargo fmt --check, workspace clippy --all-targets -D warnings and cargo test -p horizon-client --lib sprites on the Mac mini: clean.

Left over (not in this PR, it changes how all terrain looks): vanilla 26.3 samples terrain with a LINEAR, trilinear-mipmapped sampler through texture_sampling.glsl's sampleNearest (texel edges smoothed by screen size, sampleRGSS with the RGSS texture filtering option); Horizon samples nearest with nearest mips. That accounts for the remaining far-distance differences.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/201 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/cactus-mips-110` --- ### 📝 Commits (1) - [`95db0fc`](https://github.com/horizon-rust/horizon/commit/95db0fce9d00f4bb586b39763032f9c0af5177e9) Sprite mips from MipmapGenerator: cutout edges keep their coverage ### 📊 Changes **9 files changed** (+582 additions, -35 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/mipmap_probe.rs` (+54 -0) 📝 `crates/horizon-client/src/assets.rs` (+3 -0) 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/gfx.rs` (+46 -35) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) ➕ `crates/horizon-client/src/mipmap.rs` (+334 -0) 📝 `crates/horizon-client/src/sprites.rs` (+24 -0) ➕ `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaMipmapOracle.java` (+65 -0) ➕ `tools/test_mipmap_parity.py` (+54 -0) </details> ### 📄 Description Fixes #110 **What differs from vanilla.** Vanilla 26.3 builds every sprite's mip levels with `MipmapGenerator.generateMipLevels`: for cutout textures (strategy `auto` with a fully transparent pixel, or `cutout`/`strict_cutout`/`dark_cutout` from the texture's `.mcmeta`), it `solidify`s the base, averages in linear light (`ARGB.meanLinear`) and then `scaleAlphaToCoverage`s every level so its alpha-test coverage (0.5, or 0.3 for strict) stays the base level's, plus the `.mcmeta` `alpha_cutoff_bias` (cactus_side has 0.1) and 0.025. Horizon averaged alpha plainly (`gfx::mip_chain`), so each level lost coverage: the cactus side's transparent border columns widened past the cutout and opened slits along the corners from about 40 blocks. **Fix.** `horizon_client::mipmap` is a port of `MipmapGenerator` (`alphaTestCoverage`, `scaleAlphaToCoverage`, `TextureUtil.solidify` with its breadth-first order, `fillEmptyAreasWithDarkColor`, `meanLinear`, `darkenedAlphaBlend`, the `SRGB_TO_LINEAR`/`LINEAR_TO_SRGB` tables with Java's `Math.round`). `Sprites` reads each texture's `.mcmeta` `texture` section and its transparency (`NativeImage.computeTransparency` over the whole image) and the renderer builds the sprite array's mips (and the world border's `MipmappedTexture`) with it. Animated sprites get their mips per frame (vanilla mips the whole strip at once; the per-frame result only differs for cutout animations). **Harness (new): `tools/test_mipmap_parity.py`.** `VanillaMipmapOracle` runs the pinned client's `MipmapGenerator` on each texture with its `.mcmeta` settings; `examples/mipmap_probe` loads the same sprites through `sprites::Sprites` and runs `mipmap::generate`. Mac mini: **1,319 sprites (every static 16x16 block texture and every 7th item texture), all 5 levels byte-identical** (7,914 output lines). **In game (vscreen)**: a 4-high cactus column against the sky, seen from 45°, main against this branch; sky pixels showing through inside the cactus silhouette: | distance | main | this PR | |---|---|---| | 12, 20, 28 blocks | 0 | 0 | | 40 blocks | 68 | 0 | | 56 blocks | 49 | 0 | `agent-state/wave5b-shots/110-cactus-45deg-28-40-56.png` on the desktop (pairs main / PR at 28, 40, 56 blocks; the slit on main's corner is closed here). `cargo fmt --check`, workspace `clippy --all-targets -D warnings` and `cargo test -p horizon-client --lib sprites` on the Mac mini: clean. Left over (not in this PR, it changes how all terrain looks): vanilla 26.3 samples terrain with a LINEAR, trilinear-mipmapped sampler through `texture_sampling.glsl`'s `sampleNearest` (texel edges smoothed by screen size, `sampleRGSS` with the RGSS texture filtering option); Horizon samples nearest with nearest mips. That accounts for the remaining far-distance differences. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:55:45 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2401
No description provided.