Fix shadow edge orientation

This commit is contained in:
Richard Zink committed 2026-10-06 17:40:13 +02:00
1 parent 2cd78d78e8
commit f5ce558470
1 file changed
+17 -16
+17 -16
View File
@@ -193,46 +193,47 @@
} }
if (h > 0) { if (h > 0) {
var shadowFront = hFrontNeighbor - h; var hFrontNeighbor2 = heightMap[(wx + TILE) + ',' + wy] || 0;
var shadowLeft = hLeftNeighbor - h; var hBackNeighbor2 = heightMap[wx + ',' + (wy - TILE)] || 0;
var shadowFront = hFrontNeighbor2 - h;
var shadowBack = hBackNeighbor2 - h;
if (shadowFront > 0) { if (shadowFront > 0) {
var shadowW = Math.min(shadowFront * 2, TILE); var shadowW = Math.min(shadowFront * 2, TILE);
var tt = shadowW / TILE; var tt = shadowW / TILE;
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var top2 = project(wx + TILE - GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT); var top2 = project(wx + TILE - GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var topA = project(wx + GAP/2 + (TILE - GAP) * tt, wy + TILE - GAP/2, h * HEIGHT_UNIT); var top3 = project(wx + TILE - GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
var topB = project(wx + TILE - GAP/2 - (TILE - GAP) * tt, wy + TILE - GAP/2, h * HEIGHT_UNIT); var topA = project(wx + TILE - GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * tt, h * HEIGHT_UNIT);
var topB = project(wx + TILE - GAP/2, wy + GAP/2 + (TILE - GAP) * tt, h * HEIGHT_UNIT);
shadows.push({ shadows.push({
x: wx, y: wy,
points: [ points: [
{ x: top1[0], y: top1[1] }, { x: top2[0], y: top2[1] },
{ x: topA[0], y: topA[1] }, { x: topA[0], y: topA[1] },
{ x: topB[0], y: topB[1] }, { x: topB[0], y: topB[1] },
{ x: top2[0], y: top2[1] } { x: top3[0], y: top3[1] }
], ],
depth: (wx + wy) - 1 depth: (wx + wy) + 1
}); });
} }
if (shadowLeft > 0) { if (shadowBack > 0) {
var shadowW = Math.min(shadowLeft * 2, TILE); var shadowW = Math.min(shadowBack * 2, TILE);
var tt = shadowW / TILE; var tt = shadowW / TILE;
var top4 = project(wx + GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT); var top1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var topA = project(wx + GAP/2, wy + GAP/2 + (TILE - GAP) * tt, h * HEIGHT_UNIT); var top4 = project(wx + GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
var topB = project(wx + GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * tt, h * HEIGHT_UNIT); var topA = project(wx + GAP/2 + (TILE - GAP) * tt, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var topB = project(wx + GAP/2 + (TILE - GAP) * tt, wy + GAP/2, h * HEIGHT_UNIT);
shadows.push({ shadows.push({
x: wx, y: wy,
points: [ points: [
{ x: top4[0], y: top4[1] }, { x: top4[0], y: top4[1] },
{ x: topA[0], y: topA[1] }, { x: topA[0], y: topA[1] },
{ x: topB[0], y: topB[1] }, { x: topB[0], y: topB[1] },
{ x: top1[0], y: top1[1] } { x: top1[0], y: top1[1] }
], ],
depth: (wx + wy) - 1 depth: (wx + wy) + 1
}); });
} }
} }