Shadow only on top of highest voxel

This commit is contained in:
Richard Zink committed 2026-10-06 17:31:03 +02:00
1 parent 36cfd8c67d
commit 14ef21d657
1 file changed
+18 -19
+18 -19
View File
@@ -170,6 +170,11 @@
var water = isWater(h);
var sunX = wx + TILE;
var sunY = wy - TILE;
var sunH = heightMap[sunX + ',' + sunY] || 0;
var isInShadow = (sunH >= h);
for (var level = 1; level <= h; level++) {
var hRight;
if (level > (heightMap[(wx + TILE) + ',' + wy] || 0)) {
@@ -187,26 +192,20 @@
drawTile(wx, wy, level, true, hRight, hBack, false);
}
for (var level = 1; level <= h; level++) {
var sunX = wx + TILE;
var sunY = wy - TILE;
var sunH = heightMap[sunX + ',' + sunY] || 0;
if (isInShadow && h > 0) {
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 top3 = project(wx + TILE - GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
var top4 = project(wx + GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
if (sunH > level) {
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 top3 = project(wx + TILE - GAP/2, wy + GAP/2, level * HEIGHT_UNIT);
var top4 = project(wx + GAP/2, wy + GAP/2, level * HEIGHT_UNIT);
ctx.fillStyle = 'rgba(0, 0, 0, 0.4)';
ctx.beginPath();
ctx.moveTo(top1[0], top1[1]);
ctx.lineTo(top2[0], top2[1]);
ctx.lineTo(top3[0], top3[1]);
ctx.lineTo(top4[0], top4[1]);
ctx.closePath();
ctx.fill();
}
ctx.fillStyle = 'rgba(0, 0, 0, 0.35)';
ctx.beginPath();
ctx.moveTo(top1[0], top1[1]);
ctx.lineTo(top2[0], top2[1]);
ctx.lineTo(top3[0], top3[1]);
ctx.lineTo(top4[0], top4[1]);
ctx.closePath();
ctx.fill();
}
}
}