Fix TilemapGPULayer ignoring tile rotation#7338
Open
moufmouf wants to merge 1 commit into
Open
Conversation
TilemapGPULayer rendered rotated tiles unrotated. Tiled encodes 90-degree tile rotations using the anti-diagonal flip flag, which the parser resolves into `tile.rotation` (0, 90, 180 or 270 degrees) plus `tile.flipX`. But `generateLayerDataTexture` only packed `flipX`/`flipY` into the layer-data texture and dropped `rotation` entirely, so the shader had no way to know a tile was rotated. The visible result: any tile placed with a rotation (a very common way to build directional art such as arrows from a single base tile) rendered in its un-rotated orientation, and multi-tile rotated sprites appeared torn apart. The CPU `TilemapLayer` renders these correctly (its `TransformerTile` applies `element.rotation`), so it only affected the GPU layer. Encode the rotation as a 0-3 quadrant in bits 24-25 of the layer-data texel, and in the fragment shader rotate the sampling UV about the tile centre before applying the flip flags - matching the CPU path's `Rotate . Flip` composition. The empty/animated/flip flags are unaffected: the new bits are below them and `mod(flags, 4.0)` isolates the quadrant cleanly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR (delete as applicable)
TilemapGPULayerrendered rotated tiles unrotated. Tiled encodes 90-degree tile rotations using the anti-diagonal flip flag, which the parser resolves intotile.rotation(0, 90, 180 or 270 degrees) plustile.flipX. ButgenerateLayerDataTextureonly packedflipX/flipYinto the layer-data texture and droppedrotationentirely, so the shader had no way to know a tile was rotated.The visible result: any tile placed with a rotation (a very common way to build directional art such as arrows from a single base tile) rendered in its un-rotated orientation, and multi-tile rotated sprites appeared torn apart.
Before (the arrow, split on 2 tiles, is not rotated):

After:

Note that the CPU
TilemapLayerrenders these correctly (itsTransformerTileapplieselement.rotation), so it only affected the GPU layer.The fix: Encode the rotation as a 0-3 quadrant in bits 24-25 of the layer-data texel, and in the fragment shader rotate the sampling UV about the tile centre before applying the flip flags - matching the CPU path's
Rotate . Flipcomposition. The empty/animated/flip flags are unaffected: the new bits are below them andmod(flags, 4.0)isolates the quadrant cleanly.I also opened a repro here: phaserjs/examples#409