Check correct neighbors for shadows

This commit is contained in:
Richard Zink committed 2026-10-06 17:37:08 +02:00
1 parent 98432b1b26
commit ad61b069d8
1 file changed
+16 -16
+16 -16
View File
@@ -170,6 +170,9 @@
var water = isWater(h); var water = isWater(h);
var hLeftNeighbor = heightMap[(wx - TILE) + ',' + wy] || 0;
var hFrontNeighbor = heightMap[wx + ',' + (wy + TILE)] || 0;
for (var level = 1; level <= h; level++) { for (var level = 1; level <= h; level++) {
var hRight; var hRight;
if (level > (heightMap[(wx + TILE) + ',' + wy] || 0)) { if (level > (heightMap[(wx + TILE) + ',' + wy] || 0)) {
@@ -187,20 +190,17 @@
drawTile(wx, wy, level, true, hRight, hBack, false); drawTile(wx, wy, level, true, hRight, hBack, false);
} }
for (var level = 1; level <= h; level++) { if (h > 0) {
var hRightNeighbor = heightMap[(wx + TILE) + ',' + wy] || 0; var shadowFront = hFrontNeighbor - h;
var hLeftNeighbor = heightMap[wx + ',' + (wy - TILE)] || 0; var shadowLeft = hLeftNeighbor - h;
var shadowFront = hRightNeighbor - level;
var shadowLeft = hLeftNeighbor - level;
if (shadowFront > 0) { if (shadowFront > 0) {
var shadowW = Math.min(shadowFront * 2, TILE - GAP); 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, level * HEIGHT_UNIT); var top1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var top2 = project(wx + TILE - GAP/2, wy + TILE - GAP/2, level * 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, level * HEIGHT_UNIT); var topA = project(wx + GAP/2 + (TILE - GAP) * tt, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var topB = project(wx + TILE - GAP/2 - (TILE - GAP) * tt, wy + TILE - GAP/2, level * HEIGHT_UNIT); var topB = project(wx + TILE - GAP/2 - (TILE - GAP) * tt, wy + TILE - GAP/2, h * HEIGHT_UNIT);
ctx.fillStyle = 'rgba(0, 0, 0, 0.4)'; ctx.fillStyle = 'rgba(0, 0, 0, 0.4)';
ctx.beginPath(); ctx.beginPath();
@@ -213,12 +213,12 @@
} }
if (shadowLeft > 0) { if (shadowLeft > 0) {
var shadowW = Math.min(shadowLeft * 2, TILE - GAP); var shadowW = Math.min(shadowLeft * 2, TILE);
var tt = shadowW / TILE; var tt = shadowW / TILE;
var top4 = project(wx + GAP/2, wy + GAP/2, level * HEIGHT_UNIT); var top4 = project(wx + GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, level * 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, level * HEIGHT_UNIT); var topA = project(wx + GAP/2, wy + GAP/2 + (TILE - GAP) * tt, h * HEIGHT_UNIT);
var topB = project(wx + GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * tt, level * HEIGHT_UNIT); var topB = project(wx + GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * tt, h * HEIGHT_UNIT);
ctx.fillStyle = 'rgba(0, 0, 0, 0.4)'; ctx.fillStyle = 'rgba(0, 0, 0, 0.4)';
ctx.beginPath(); ctx.beginPath();