Shadow falls on lower neighbor in light direction
This commit is contained in:
1 parent
59077670ba
commit
ac5db93beb
1 file changed
+26
-26
+26
-26
@@ -195,49 +195,49 @@
|
||||
}
|
||||
|
||||
if (h > 0) {
|
||||
var hRightNeighbor = heightMap[(wx + TILE) + ',' + wy] || 0;
|
||||
var hBackNeighbor = heightMap[wx + ',' + (wy - TILE)] || 0;
|
||||
var hLeftNeighbor = heightMap[(wx - TILE) + ',' + wy] || 0;
|
||||
var hFrontNeighbor = heightMap[wx + ',' + (wy + TILE)] || 0;
|
||||
|
||||
var shadowFromRight = hRightNeighbor - h;
|
||||
var shadowFromBack = hBackNeighbor - h;
|
||||
var shadowOnRight = h - hLeftNeighbor;
|
||||
var shadowOnFront = h - hFrontNeighbor;
|
||||
|
||||
if (shadowFromRight > 0) {
|
||||
var shadowW = Math.min(shadowFromRight * 2, TILE);
|
||||
if (shadowOnRight > 0) {
|
||||
var shadowW = Math.min(shadowOnRight * 4, TILE);
|
||||
var tt = shadowW / TILE;
|
||||
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 topA = project(wx + TILE - GAP/2 - (TILE - GAP) * tt, wy + TILE - GAP/2, h * HEIGHT_UNIT);
|
||||
var topB = project(wx + TILE - GAP/2 - (TILE - GAP) * tt, wy + GAP/2, h * HEIGHT_UNIT);
|
||||
var target2 = project((wx - TILE) + GAP/2 + (TILE - GAP) * tt, wy + TILE - GAP/2, hLeftNeighbor * HEIGHT_UNIT);
|
||||
var target3 = project((wx - TILE) + GAP/2 + (TILE - GAP) * tt, wy + GAP/2, hLeftNeighbor * HEIGHT_UNIT);
|
||||
var origin1 = project(wx + GAP/2, wy + TILE - GAP/2, h * HEIGHT_UNIT);
|
||||
var origin4 = project(wx + GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
|
||||
|
||||
renderList.push({
|
||||
type: 'shadow',
|
||||
points: [
|
||||
{ x: top2[0], y: top2[1] },
|
||||
{ x: topA[0], y: topA[1] },
|
||||
{ x: topB[0], y: topB[1] },
|
||||
{ x: top3[0], y: top3[1] }
|
||||
{ x: origin4[0], y: origin4[1] },
|
||||
{ x: target2[0], y: target2[1] },
|
||||
{ x: target3[0], y: target3[1] },
|
||||
{ x: origin1[0], y: origin1[1] }
|
||||
],
|
||||
depth: wx + wy + 0.999
|
||||
depth: (wx - TILE) + wy + hLeftNeighbor + 0.999
|
||||
});
|
||||
}
|
||||
|
||||
if (shadowFromBack > 0) {
|
||||
var shadowW = Math.min(shadowFromBack * 2, TILE);
|
||||
if (shadowOnFront > 0) {
|
||||
var shadowW = Math.min(shadowOnFront * 4, 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 topA = project(wx + GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * tt, h * HEIGHT_UNIT);
|
||||
var topB = project(wx + TILE - GAP/2, wy + TILE - GAP/2 - (TILE - GAP) * tt, h * HEIGHT_UNIT);
|
||||
var target1 = project(wx + GAP/2, (wy + TILE) - GAP/2 - (TILE - GAP) * tt, hFrontNeighbor * HEIGHT_UNIT);
|
||||
var target2 = project(wx + TILE - GAP/2, (wy + TILE) - GAP/2 - (TILE - GAP) * tt, hFrontNeighbor * HEIGHT_UNIT);
|
||||
var origin3 = project(wx + TILE - GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
|
||||
var origin4 = project(wx + GAP/2, wy + GAP/2, h * HEIGHT_UNIT);
|
||||
|
||||
renderList.push({
|
||||
type: 'shadow',
|
||||
points: [
|
||||
{ x: top1[0], y: top1[1] },
|
||||
{ x: topA[0], y: topA[1] },
|
||||
{ x: topB[0], y: topB[1] },
|
||||
{ x: top2[0], y: top2[1] }
|
||||
{ x: origin4[0], y: origin4[1] },
|
||||
{ x: target2[0], y: target2[1] },
|
||||
{ x: target1[0], y: target1[1] },
|
||||
{ x: origin3[0], y: origin3[1] }
|
||||
],
|
||||
depth: wx + wy + 0.999
|
||||
depth: wx + (wy + TILE) + hFrontNeighbor + 0.999
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user