[PR #1458] [MERGED] High-resolution resource packs draw the GUI at its size #3538

Closed
opened 2026-11-03 04:10:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/high-res-pack-gui


📝 Commits (2)

  • 22ad656 High-resolution resource packs no longer crash the game at launch
  • 79ee670 High-resolution resource packs draw the GUI at its size

📊 Changes

6 files changed (+485 additions, -112 deletions)

View changed files

📝 crates/horizon-client/src/font.rs (+4 -1)
📝 crates/horizon-client/src/game.rs (+23 -5)
📝 crates/horizon-client/src/game/packs.rs (+1 -1)
📝 crates/horizon-client/src/gfx.rs (+7 -0)
📝 crates/horizon-client/src/hud.rs (+193 -33)
📝 crates/horizon-client/src/ui.rs (+257 -72)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #1457 (merge that one first). This fixes the GUI half of #1442: with Faithful 32x the UI renders wrong.

What was wrong

I reproduced the reporter's screenshots on main with Faithful 32x (Modrinth, 26.3-september-2026):

  • The survival and creative inventories showed the top-left quarter of their background, stretched over the whole screen.
  • Tooltips lost their background, leaving loose text and a stray purple line.
  • The recipe toast was drawn twice its size.

All three have one cause. Horizon's GUI code measured atlas sprites in texels (Rect.w/h). Vanilla measures them in GUI units, whatever the resolution of the pack:

  • InventoryScreen.renderBg calls blit(…, 0, 0, imageWidth, imageHeight, 256, 256), so UVs are fractions of a texture it treats as 256 units wide, even when the file is 512 or 1024 texels.
  • GuiGraphicsExtractor.blitNineSlicedSprite works in the sprite's gui.scaling units: sprite.getU(textureX / nineSlice.width()) (decompiled with tools/rea_vanilla.py). Faithful's metadata uses those units. For example, its tooltip/background is 50x50 with a 10-pixel border, on a 100x100 texture in 32x and 200x200 in 64x.

How

  • HudAtlas::build_over(root, defaults): each sprite's w/h is the size of the default resources' texture with the same name (read from its PNG header). That is the size vanilla's GUI code assumes. Textures only a pack has keep their own size. Code that copies pixels reads texels from the UVs (Rect::texels): the font sheets and the fire frames. The texture-size filter now reads the GUI size, so Faithful 64x's 1024x1024 screen backgrounds are no longer dropped.
  • ui::nine_slice follows blitNineSlicedSprite and blitNineSliceInnerSegment: the metadata's width, height and borders, stretch_inner, the one-quad case and the three-part cases, and borders capped at width / 2 with integer division. Before, it ignored width, height and stretch_inner.
  • UiResources::load and the pack reload pass the default resources.

Evidence (Metal, M4 Pro, --offscreen, GUI scale 2)

main this branch
Faithful 32x survival inventory quarter of the background, slots missing full background, every slot in place
Faithful 32x creative inventory tab and background quarters overlapping tabs, grid and scroll bar in place
Faithful 32x tooltip no background, loose text Faithful's dark background and purple frame
Faithful 32x recipe toast 160x64 160x32, as in vanilla
Faithful 64x crash (#1457 fixes it) survival and creative inventories, tooltips and HUD correct

With no pack the root is the default resources themselves, so every sprite keeps its size. Only the nine-slice drawing changed for the default resources, and only to follow vanilla's cases.

Tests

  • hud::tests::a_pack_texture_keeps_the_default_textures_gui_size: covers 64x's 1024x1024 inventory (kept, 256x256 GUI units), 32x's button and stone, an animated strip, and a pack-only sprite.
  • ui::tests::a_high_resolution_button_slices_in_its_gui_units: Faithful 32x's button metadata. The left border's UV ends at 20/200, not 20/400.
  • ui::tests::nine_slice_corners_and_a_stretched_centre: tooltip frame, stretch_inner.
  • ui::tests::a_sprite_drawn_at_its_own_size_is_one_quad and borders_shrink_to_half_the_drawn_size: vanilla's special cases and its integer division.

Self-check

  • cargo fmt --all: clean
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo test -p horizon-client: 1055 + 98 + 18 + 2 + 2 + 2 + 1 passed, 0 failed
  • tools/parity.py --changed origin/main: 103 harnesses depend on the changed files; 103 passed, 0 failed (35.5 min)

Benchmarks (same runs as #1457; frames capped near 115 fps, so compare CPU and GPU times):

Faithful 32x CPU ms/frame GPU ms/frame
main, inventory open 1.33 / 1.36 2.57 / 2.71
this branch, inventory open 1.37 / 1.37 2.48 / 2.88
main, default resources, inventory 1.35 / 1.38 2.08 / 2.37
this branch, default resources, inventory 1.31 / 1.32 2.07 / 2.79

No change beyond run-to-run noise.

Needs Ludovic

  • Faithful 64x's atlas is 16384x11264 (704 MiB) for 452 MiB of textures. The shelf packer wastes about a third of it. A skyline packer, or vanilla-style separate atlases, would recover that, but I kept it out of this PR.
  • Not checked on Linux/Vulkan (the desktop was in use). This change doesn't depend on the backend.

🤖 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/1458 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/23/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/high-res-pack-gui` --- ### 📝 Commits (2) - [`22ad656`](https://github.com/horizon-rust/horizon/commit/22ad65611e85746cc00ad1f5ca25725f40b42d8f) High-resolution resource packs no longer crash the game at launch - [`79ee670`](https://github.com/horizon-rust/horizon/commit/79ee670d7915a1ea4e7cdd4355053aa1a1ff513f) High-resolution resource packs draw the GUI at its size ### 📊 Changes **6 files changed** (+485 additions, -112 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/font.rs` (+4 -1) 📝 `crates/horizon-client/src/game.rs` (+23 -5) 📝 `crates/horizon-client/src/game/packs.rs` (+1 -1) 📝 `crates/horizon-client/src/gfx.rs` (+7 -0) 📝 `crates/horizon-client/src/hud.rs` (+193 -33) 📝 `crates/horizon-client/src/ui.rs` (+257 -72) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #1457 (merge that one first). This fixes the GUI half of #1442: with Faithful 32x the UI renders wrong. ## What was wrong I reproduced the reporter's screenshots on main with Faithful 32x (Modrinth, `26.3-september-2026`): - The survival and creative inventories showed the top-left quarter of their background, stretched over the whole screen. - Tooltips lost their background, leaving loose text and a stray purple line. - The recipe toast was drawn twice its size. All three have one cause. Horizon's GUI code measured atlas sprites in texels (`Rect.w/h`). Vanilla measures them in GUI units, whatever the resolution of the pack: - `InventoryScreen.renderBg` calls `blit(…, 0, 0, imageWidth, imageHeight, 256, 256)`, so UVs are fractions of a texture it treats as 256 units wide, even when the file is 512 or 1024 texels. - `GuiGraphicsExtractor.blitNineSlicedSprite` works in the sprite's `gui.scaling` units: `sprite.getU(textureX / nineSlice.width())` (decompiled with `tools/rea_vanilla.py`). Faithful's metadata uses those units. For example, its `tooltip/background` is 50x50 with a 10-pixel border, on a 100x100 texture in 32x and 200x200 in 64x. ## How - `HudAtlas::build_over(root, defaults)`: each sprite's `w`/`h` is the size of the default resources' texture with the same name (read from its PNG header). That is the size vanilla's GUI code assumes. Textures only a pack has keep their own size. Code that copies pixels reads texels from the UVs (`Rect::texels`): the font sheets and the fire frames. The texture-size filter now reads the GUI size, so Faithful 64x's 1024x1024 screen backgrounds are no longer dropped. - `ui::nine_slice` follows `blitNineSlicedSprite` and `blitNineSliceInnerSegment`: the metadata's `width`, `height` and borders, `stretch_inner`, the one-quad case and the three-part cases, and borders capped at `width / 2` with integer division. Before, it ignored `width`, `height` and `stretch_inner`. - `UiResources::load` and the pack reload pass the default resources. ## Evidence (Metal, M4 Pro, `--offscreen`, GUI scale 2) | | main | this branch | | --- | --- | --- | | Faithful 32x survival inventory | quarter of the background, slots missing | full background, every slot in place | | Faithful 32x creative inventory | tab and background quarters overlapping | tabs, grid and scroll bar in place | | Faithful 32x tooltip | no background, loose text | Faithful's dark background and purple frame | | Faithful 32x recipe toast | 160x64 | 160x32, as in vanilla | | Faithful 64x | crash (#1457 fixes it) | survival and creative inventories, tooltips and HUD correct | With no pack the root is the default resources themselves, so every sprite keeps its size. Only the nine-slice drawing changed for the default resources, and only to follow vanilla's cases. ## Tests - `hud::tests::a_pack_texture_keeps_the_default_textures_gui_size`: covers 64x's 1024x1024 inventory (kept, 256x256 GUI units), 32x's button and stone, an animated strip, and a pack-only sprite. - `ui::tests::a_high_resolution_button_slices_in_its_gui_units`: Faithful 32x's button metadata. The left border's UV ends at 20/200, not 20/400. - `ui::tests::nine_slice_corners_and_a_stretched_centre`: tooltip frame, `stretch_inner`. - `ui::tests::a_sprite_drawn_at_its_own_size_is_one_quad` and `borders_shrink_to_half_the_drawn_size`: vanilla's special cases and its integer division. ## Self-check - `cargo fmt --all`: clean - `cargo clippy --workspace --all-targets -- -D warnings`: clean - `cargo test -p horizon-client`: 1055 + 98 + 18 + 2 + 2 + 2 + 1 passed, 0 failed - `tools/parity.py --changed origin/main`: 103 harnesses depend on the changed files; 103 passed, 0 failed (35.5 min) Benchmarks (same runs as #1457; frames capped near 115 fps, so compare CPU and GPU times): | Faithful 32x | CPU ms/frame | GPU ms/frame | | --- | --- | --- | | main, inventory open | 1.33 / 1.36 | 2.57 / 2.71 | | this branch, inventory open | 1.37 / 1.37 | 2.48 / 2.88 | | main, default resources, inventory | 1.35 / 1.38 | 2.08 / 2.37 | | this branch, default resources, inventory | 1.31 / 1.32 | 2.07 / 2.79 | No change beyond run-to-run noise. ## Needs Ludovic - Faithful 64x's atlas is 16384x11264 (704 MiB) for 452 MiB of textures. The shelf packer wastes about a third of it. A skyline packer, or vanilla-style separate atlases, would recover that, but I kept it out of this PR. - Not checked on Linux/Vulkan (the desktop was in use). This change doesn't depend on the backend. 🤖 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-03 04:10:15 +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#3538
No description provided.