Shadow on every level when neighboring voxel is taller

This commit is contained in:
Richard Zink committed 2026-10-06 17:34:59 +02:00
1 parent 0b2da2a947
commit cd66460baa
1 file changed
+18 -15
+18 -15
View File
@@ -187,17 +187,20 @@
drawTile(wx, wy, level, true, hRight, hBack, false);
}
if (h > 0) {
var shadowFront = (heightMap[(wx + TILE) + ',' + wy] || 0) - h;
var shadowLeft = (heightMap[wx + ',' + (wy - TILE)] || 0) - h;
for (var level = 1; level <= h; level++) {
var hRightNeighbor = heightMap[(wx + TILE) + ',' + wy] || 0;
var hLeftNeighbor = heightMap[wx + ',' + (wy - TILE)] || 0;
var shadowFront = hRightNeighbor - level;
var shadowLeft = hLeftNeighbor - level;
if (shadowFront > 0) {
var shadowWidth = Math.min(shadowFront * 2, TILE);
var t = shadowWidth / 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 topA = project(wx + GAP/2 + (TILE - GAP) * t, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var topB = project(wx + TILE - GAP/2 - (TILE - GAP) * t, wy + TILE - GAP/2, h * HEIGHT_UNIT);
var shadowW = Math.min(shadowFront * 2, TILE - GAP);
var tt = shadowW / TILE;
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, level * HEIGHT_UNIT);
var top2 = project(wx + TILE - GAP/2, wy + TILE - GAP/2, level * HEIGHT_UNIT);
var topA = project(wx + 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, level * HEIGHT_UNIT);
ctx.fillStyle = 'rgba(0, 0, 0, 0.4)';
ctx.beginPath();
@@ -210,12 +213,12 @@
}
if (shadowLeft > 0) {
var shadowWidth = Math.min(shadowLeft * 2, TILE);
var t = shadowWidth / 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 topA = project(wx + GAP/2, wy + GAP/2 + (TILE - GAP) * t, h * HEIGHT_UNIT);
var topB = project(wx + GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * t, h * HEIGHT_UNIT);
var shadowW = Math.min(shadowLeft * 2, TILE - GAP);
var tt = shadowW / TILE;
var top4 = project(wx + GAP/2, wy + GAP/2, level * HEIGHT_UNIT);
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, level * HEIGHT_UNIT);
var topA = project(wx + GAP/2, wy + GAP/2 + (TILE - GAP) * tt, level * HEIGHT_UNIT);
var topB = project(wx + GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * tt, level * HEIGHT_UNIT);
ctx.fillStyle = 'rgba(0, 0, 0, 0.4)';
ctx.beginPath();