Skip to content

fix: round interpolated texture tile sizes#1121

Open
banteg wants to merge 1 commit into
Kenix3:mainfrom
banteg:feat/fix-interpolated-tile-size
Open

fix: round interpolated texture tile sizes#1121
banteg wants to merge 1 commit into
Kenix3:mainfrom
banteg:feat/fix-interpolated-tile-size

Conversation

@banteg

@banteg banteg commented Jun 7, 2026

Copy link
Copy Markdown

Summary

This fixes interpolated texture tile dimensions being truncated after uls/ult/lrs/lrt interpolation.

The bug showed up on macOS/Apple Silicon as animated water/lava textures visibly jittering when interpolation is active. In the Fire Temple lava repro, one replay phase derived a different rendered texture window from the interpolated tile coordinates:

replay=1
tile0=(0.000,6.333,124.000,130.333)
renderSize0=(32, 31)
texSize0=(32, 31)

Adjacent phases for the same surface stayed 32x32, so the visible symptom was an alternating 32x32 / 32x31 texture window.

replay0=(0.000,6.000,124.000,130.000) renderSize0=(32, 32)
replay1=(0.000,6.333,124.000,130.333) renderSize0=(32, 31) # bugged!
replay2=(0.000,6.667,124.000,130.667) renderSize0=(32, 32)

Root Cause

Several paths in src/fast/interpreter.cpp derive rendered/imported tile dimensions with:

(high - low + 4) / 4

Those results were then cast directly to integer types. With interpolated float coordinates, a texel count that is logically 32.0 can land slightly below the integer boundary, so truncation turns it into 31.

That makes the texture clamp/import and draw-time texture size calculations disagree across interpolation phases, producing the observed water/lava animation jitter.

Fix

Add GetTileSizeFromCoordinates() and use it for the tile-size calculations that derive dimensions from interpolated tile coordinates. It keeps non-positive sizes clamped to 0 and rounds the derived texel count with lroundf.

Related Links

Validation

  • cmake -S . -B build -DLUS_BUILD_TESTS=OFF
  • cmake --build build --target libultraship -j 8
  • cmake -S . -B build -DLUS_BUILD_TESTS=ON
  • cmake --build build --target lus_tests -j 8
  • ctest --test-dir build --output-on-failure

@banteg banteg marked this pull request as ready for review June 8, 2026 00:01
roborich added a commit to roborich/libultraship that referenced this pull request Jun 22, 2026
Cherry of banteg's open upstream PR (feat/fix-interpolated-tile-size). Fixes
animated water/lava textures jittering at high FPS (interpolation on) — e.g.
Lake Hylia water — where (high-low+4)/4 tile-size math truncated an
interpolated 31.9999 to 31, so the import-clamp and draw-time texture window
disagreed by a texel across sub-frames (alternating 32x32 / 32x31). Adds
GetTileSizeFromCoordinates() (rounds via lroundf) and routes the 4
ImportTexture* clamps + the GfxSpTri1 draw-time size through it. Backend-
agnostic (interpreter.cpp only), so it fixes D3D11/OpenGL/Metal alike.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
roborich added a commit to roborich/Shipwright that referenced this pull request Jun 22, 2026
…ile sizes)

Points the toon submodule at the LUS commit that cherry-picks
Kenix3/libultraship#1121, fixing high-FPS water/lava texture jitter
(Lake Hylia). See toon-lighting.md for the upstream-merge action item.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
roborich added a commit to roborich/libultraship that referenced this pull request Jun 22, 2026
Cherry of banteg's open upstream PR (feat/fix-interpolated-tile-size). Fixes
animated water/lava textures jittering at high FPS (interpolation on) — e.g.
Lake Hylia water — where (high-low+4)/4 tile-size math truncated an
interpolated 31.9999 to 31, so the import-clamp and draw-time texture window
disagreed by a texel across sub-frames (alternating 32x32 / 32x31). Adds
GetTileSizeFromCoordinates() (rounds via lroundf) and routes the 4
ImportTexture* clamps + the GfxSpTri1 draw-time size through it. Backend-
agnostic (interpreter.cpp only), so it fixes D3D11/OpenGL/Metal alike.
roborich added a commit to roborich/Shipwright that referenced this pull request Jun 22, 2026
…ile sizes)

Points the toon submodule at the LUS commit that cherry-picks
Kenix3/libultraship#1121, fixing high-FPS water/lava texture jitter
(Lake Hylia). See toon-lighting.md for the upstream-merge action item.
roborich added a commit to roborich/Shipwright that referenced this pull request Jun 22, 2026
…ile sizes)

Points the toon submodule at the LUS commit that cherry-picks
Kenix3/libultraship#1121, fixing high-FPS water/lava texture jitter
(Lake Hylia). See toon-lighting.md for the upstream-merge action item.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interpolated texture tile sizes can truncate and cause water/lava jitter

1 participant