diff --git a/vendor/clouds3d.js b/vendor/clouds3d.js index 3ff7a54..bde0245 100644 --- a/vendor/clouds3d.js +++ b/vendor/clouds3d.js @@ -314,12 +314,15 @@ function drawTileAt(lng, perp, dx, dz, centerTileX, centerTileY) { var tileY = centerTileY + dz; var halfLong = Math.floor(GROUND_CORRIDOR_LONG / 2); var halfPerp = Math.floor(GROUND_CORRIDOR_PERP / 2); - // Canvas position is the rotated-frame coordinate (lng, perp), - // NOT the rotated tile offset (dx, dz). This way the texture - // is rectangular in canvas space and the shader maps world - // (hitPoint - centre) -> rotated axes -> canvas UV. - var canvasX = (lng + halfLong) * GROUND_TILE_SIZE; - var canvasY = (perp + halfPerp) * GROUND_TILE_SIZE; + // Canvas position: place each tile so its CENTRE sits at the + // rotated-frame coordinate (lng, perp). The shader maps + // gUv = rotated / uGroundSize + 0.5, so rotated = 0 is at the + // canvas centre (canvas_width/2, canvas_height/2). Iterating + // (lng, perp) over [-halfLong..halfLong] means tile centres at + // halfLong + 0.5 etc. Without the +0.5 the canvas would be + // half a tile off from the shader's expectation. + var canvasX = (lng + halfLong + 0.5) * GROUND_TILE_SIZE; + var canvasY = (perp + halfPerp + 0.5) * GROUND_TILE_SIZE; if (canvasX < 0 || canvasX >= groundCanvas.width || canvasY < 0 || canvasY >= groundCanvas.height) { return Promise.resolve(false); }