Shadow on every level when neighboring voxel is taller
This commit is contained in:
1 parent
0b2da2a947
commit
cd66460baa
1 file changed
+18
-15
+18
-15
@@ -187,17 +187,20 @@
|
|||||||
drawTile(wx, wy, level, true, hRight, hBack, false);
|
drawTile(wx, wy, level, true, hRight, hBack, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h > 0) {
|
for (var level = 1; level <= h; level++) {
|
||||||
var shadowFront = (heightMap[(wx + TILE) + ',' + wy] || 0) - h;
|
var hRightNeighbor = heightMap[(wx + TILE) + ',' + wy] || 0;
|
||||||
var shadowLeft = (heightMap[wx + ',' + (wy - TILE)] || 0) - h;
|
var hLeftNeighbor = heightMap[wx + ',' + (wy - TILE)] || 0;
|
||||||
|
|
||||||
|
var shadowFront = hRightNeighbor - level;
|
||||||
|
var shadowLeft = hLeftNeighbor - level;
|
||||||
|
|
||||||
if (shadowFront > 0) {
|
if (shadowFront > 0) {
|
||||||
var shadowWidth = Math.min(shadowFront * 2, TILE);
|
var shadowW = Math.min(shadowFront * 2, TILE - GAP);
|
||||||
var t = shadowWidth / TILE;
|
var tt = shadowW / TILE;
|
||||||
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
|
var top1 = project(wx + GAP/2, wy + TILE - GAP/2, level * 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, level * HEIGHT_UNIT);
|
||||||
var topA = project(wx + GAP/2 + (TILE - GAP) * t, wy + TILE - GAP/2, h * 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) * t, wy + TILE - GAP/2, h * 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.fillStyle = 'rgba(0, 0, 0, 0.4)';
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
@@ -210,12 +213,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shadowLeft > 0) {
|
if (shadowLeft > 0) {
|
||||||
var shadowWidth = Math.min(shadowLeft * 2, TILE);
|
var shadowW = Math.min(shadowLeft * 2, TILE - GAP);
|
||||||
var t = shadowWidth / TILE;
|
var tt = shadowW / TILE;
|
||||||
var top4 = project(wx + GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
|
var top4 = project(wx + GAP/2, wy + GAP/2, level * 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, level * HEIGHT_UNIT);
|
||||||
var topA = project(wx + GAP/2, wy + GAP/2 + (TILE - GAP) * t, h * 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) * t, h * 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.fillStyle = 'rgba(0, 0, 0, 0.4)';
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
|
|||||||
Reference in new issue
Block a user