Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/renderer/webgl/shaders/TilemapGPULayer-frag.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ module.exports = [
' /* Bit 29 is animation. */',
' bool animated = mod(flags, 64.0) > 31.0;',
' #endif',
' /* Bits 24-25 hold the tile rotation as a 0-3 quadrant (0/90/180/270 deg). */',
' float rotQuad = mod(flags, 4.0);',
' if (rotQuad > 0.5)',
' {',
' vec2 c = uv - 0.5;',
' float ang = -rotQuad * 1.5707963267948966;',
' float cs = cos(ang);',
' float sn = sin(ang);',
' uv = vec2(cs * c.x - sn * c.y, sn * c.x + cs * c.y) + 0.5;',
' }',
' if (flipX)',
' {',
' uv.x = 1.0 - uv.x;',
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/webgl/shaders/src/TilemapGPULayer.frag
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ Tile getLayerData (vec2 coord)
bool animated = mod(flags, 64.0) > 31.0;
#endif

/* Bits 24-25 hold the tile rotation as a 0-3 quadrant (0/90/180/270 deg). */
float rotQuad = mod(flags, 4.0);
if (rotQuad > 0.5)
{
vec2 c = uv - 0.5;
float ang = -rotQuad * 1.5707963267948966;
float cs = cos(ang);
float sn = sin(ang);
uv = vec2(cs * c.x - sn * c.y, sn * c.x + cs * c.y) + 0.5;
}

if (flipX)
{
uv.x = 1.0 - uv.x;
Expand Down
13 changes: 13 additions & 0 deletions src/tilemaps/TilemapGPULayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,19 @@ var TilemapGPULayer = new Class({
{
index |= 0x20000000;
}

// Encode the tile rotation as a 0-3 quadrant (0, 90, 180, 270
// degrees) in bits 24-25. Tiled stores 90-degree rotations via
// the anti-diagonal flip flag, which the parser resolves into
// `tile.rotation`; without this the shader would render rotated
// tiles (e.g. arrows built by rotating a base tile) unrotated.
var rotQuad = Math.round(tile.rotation / (Math.PI / 2)) % 4;
if (rotQuad < 0)
{
rotQuad += 4;
}
index |= rotQuad << 24;

if (tile.index === -1)
{
// Set the fourth bit to 1 to indicate an empty tile.
Expand Down