Fix daylight shadow rims around solid tiles and water.
Occluding neighbours no longer pull lightmap corners toward zero (which carved daytime edges after Dark baked visible light into the map); water coast sync uses the same ambient=1 model.
@@ -2,6 +2,7 @@ import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BO
2
2
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
3
3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4
4
import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";
5
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
5
6
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
6
7
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
7
8
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";
@@ -2743,9 +2744,7 @@ export class WorldView
2743
2744
this.#syncLitSprite(objects.ground, objects.shadeAlpha ?? 0);
2744
2745
return;
2745
2746
}
2746
const fallbackLit = ambientDark > 0
2747
? 1 - (objects.shadeAlpha ?? 0) / ambientDark
2748
: 1;
2747
const fallbackLit = 1 - (objects.shadeAlpha ?? 0);
2749
2748
const chunkX = Math.floor(objects.tileX / CHUNK_SIZE);
2750
2749
const chunkY = Math.floor(objects.tileY / CHUNK_SIZE);
2751
2750
const chunkBaked = baked ?? this.bakedChunks.get(`${chunkX},${chunkY}`);
@@ -3447,7 +3446,8 @@ export class WorldView
3447
3446
{ continue; }
3448
3447
if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)
3449
3448
{ continue; }
3450
this.#syncGroundWaterFx(objects, this.#ambientDarkness(), timeSec);
3449
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
3450
this.#syncGroundWaterFx(objects, 1, timeSec);
3451
3451
}
3452
3452
}
3453
3453
@@ -3487,7 +3487,7 @@ export class WorldView
3487
3487
objects.ground.transform.size = new vector(size, size);
3488
3488
objects.ground.layer = LAYER_GROUND;
3489
3489
objects.groundTypeId = animatedGround.typeId;
3490
this.#syncGroundWaterFx(objects, this.#ambientDarkness(), performance.now() / 1000);
3490
this.#syncGroundWaterFx(objects, 1, performance.now() / 1000);
3491
3491
this.#markSortDirty();
3492
3492
}
3493
3493
if (animatedGround.bloom)
@@ -3977,25 +3977,16 @@ export class WorldView
3977
3977
{
3978
3978
const sample = (lx, ly) => grid[(ly + 1) * gridW + (lx + 1)];
3979
3979
const blocks = (lx, ly) => occlude[(ly + 1) * gridW + (lx + 1)] !== 0;
3980
const openSample = (lx, ly) => (blocks(lx, ly) ? 0 : sample(lx, ly));
3981
const smoothCorner = (homeLx, homeLy, aLx, aLy, bLx, bLy, dLx, dLy) =>
3982
{
3983
const home = sample(homeLx, homeLy);
3984
if (blocks(homeLx, homeLy))
3985
{ return home; }
3986
let sum = home;
3987
let count = 1;
3988
sum += openSample(aLx, aLy);
3989
count += 1;
3990
sum += openSample(bLx, bLy);
3991
count += 1;
3992
if (!blocks(aLx, aLy) && !blocks(bLx, bLy))
3993
{
3994
sum += openSample(dLx, dLy);
3995
count += 1;
3996
}
3997
return sum / count;
3998
};
3980
const smoothCorner = (homeLx, homeLy, aLx, aLy, bLx, bLy, dLx, dLy) => smoothLitCorner({
3981
homeLit: sample(homeLx, homeLy),
3982
homeBlocks: blocks(homeLx, homeLy),
3983
aLit: sample(aLx, aLy),
3984
aBlocks: blocks(aLx, aLy),
3985
bLit: sample(bLx, bLy),
3986
bBlocks: blocks(bLx, bLy),
3987
dLit: sample(dLx, dLy),
3988
dBlocks: blocks(dLx, dLy)
3989
});
3999
3990
return { smoothCorner };
4000
3991
}
4001
3992
@@ -2,6 +2,7 @@ import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BO2
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";2
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";4
import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";4
import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";5
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";5
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";6
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";6
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";7
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";7
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";8
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";@@ -2743,9 +2744,7 @@ export class WorldView2743
this.#syncLitSprite(objects.ground, objects.shadeAlpha ?? 0);2744
this.#syncLitSprite(objects.ground, objects.shadeAlpha ?? 0);2744
return;2745
return;2745
}2746
}2746
const fallbackLit = ambientDark > 02747
const fallbackLit = 1 - (objects.shadeAlpha ?? 0);2747
? 1 - (objects.shadeAlpha ?? 0) / ambientDark2748
: 1;2749
const chunkX = Math.floor(objects.tileX / CHUNK_SIZE);2748
const chunkX = Math.floor(objects.tileX / CHUNK_SIZE);2750
const chunkY = Math.floor(objects.tileY / CHUNK_SIZE);2749
const chunkY = Math.floor(objects.tileY / CHUNK_SIZE);2751
const chunkBaked = baked ?? this.bakedChunks.get(`${chunkX},${chunkY}`);2750
const chunkBaked = baked ?? this.bakedChunks.get(`${chunkX},${chunkY}`);@@ -3447,7 +3446,8 @@ export class WorldView3447
{ continue; }3446
{ continue; }3448
if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)3447
if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)3449
{ continue; }3448
{ continue; }3450
this.#syncGroundWaterFx(objects, this.#ambientDarkness(), timeSec);3449
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.3450
this.#syncGroundWaterFx(objects, 1, timeSec);3451
}3451
}3452
}3452
}3453
3453
@@ -3487,7 +3487,7 @@ export class WorldView3487
objects.ground.transform.size = new vector(size, size);3487
objects.ground.transform.size = new vector(size, size);3488
objects.ground.layer = LAYER_GROUND;3488
objects.ground.layer = LAYER_GROUND;3489
objects.groundTypeId = animatedGround.typeId;3489
objects.groundTypeId = animatedGround.typeId;3490
this.#syncGroundWaterFx(objects, this.#ambientDarkness(), performance.now() / 1000);3490
this.#syncGroundWaterFx(objects, 1, performance.now() / 1000);3491
this.#markSortDirty();3491
this.#markSortDirty();3492
}3492
}3493
if (animatedGround.bloom)3493
if (animatedGround.bloom)@@ -3977,25 +3977,16 @@ export class WorldView3977
{3977
{3978
const sample = (lx, ly) => grid[(ly + 1) * gridW + (lx + 1)];3978
const sample = (lx, ly) => grid[(ly + 1) * gridW + (lx + 1)];3979
const blocks = (lx, ly) => occlude[(ly + 1) * gridW + (lx + 1)] !== 0;3979
const blocks = (lx, ly) => occlude[(ly + 1) * gridW + (lx + 1)] !== 0;3980
const openSample = (lx, ly) => (blocks(lx, ly) ? 0 : sample(lx, ly));3980
const smoothCorner = (homeLx, homeLy, aLx, aLy, bLx, bLy, dLx, dLy) => smoothLitCorner({3981
const smoothCorner = (homeLx, homeLy, aLx, aLy, bLx, bLy, dLx, dLy) =>3981
homeLit: sample(homeLx, homeLy),3982
{3982
homeBlocks: blocks(homeLx, homeLy),3983
const home = sample(homeLx, homeLy);3983
aLit: sample(aLx, aLy),3984
if (blocks(homeLx, homeLy))3984
aBlocks: blocks(aLx, aLy),3985
{ return home; }3985
bLit: sample(bLx, bLy),3986
let sum = home;3986
bBlocks: blocks(bLx, bLy),3987
let count = 1;3987
dLit: sample(dLx, dLy),3988
sum += openSample(aLx, aLy);3988
dBlocks: blocks(dLx, dLy)3989
count += 1;3989
});3990
sum += openSample(bLx, bLy);3991
count += 1;3992
if (!blocks(aLx, aLy) && !blocks(bLx, bLy))3993
{3994
sum += openSample(dLx, dLy);3995
count += 1;3996
}3997
return sum / count;3998
};3999
return { smoothCorner };3990
return { smoothCorner };4000
}3991
}4001
3992
@@ -180,3 +180,41 @@ test("encodeChunkBlob stores pre-baked occlusion aligned with chunkTileLightOccl
180
180
assert.equal(decoded.occlusion[0], chunkTileLightOcclusion(decoded, 0, 0));
181
181
assert.equal(decoded.occlusion[1], LightOcclusion.clear);
182
182
});
183
184
test("lit corner blend does not darken daylight beside occluding walls", async () =>
185
{
186
const { smoothLitCorner } = await import("../../shared/lighting/lightCorners.js");
187
const dayOpen = smoothLitCorner({
188
homeLit: 1,
189
homeBlocks: false,
190
aLit: 1,
191
aBlocks: false,
192
bLit: 0.2,
193
bBlocks: true,
194
dLit: 0,
195
dBlocks: true
196
});
197
assert.equal(dayOpen, 1);
198
const nightDarkBesideLitWall = smoothLitCorner({
199
homeLit: 0,
200
homeBlocks: false,
201
aLit: 0,
202
aBlocks: false,
203
bLit: 0.8,
204
bBlocks: true,
205
dLit: 0.5,
206
dBlocks: true
207
});
208
assert.equal(nightDarkBesideLitWall, 0);
209
const openBlend = smoothLitCorner({
210
homeLit: 1,
211
homeBlocks: false,
212
aLit: 0.5,
213
aBlocks: false,
214
bLit: 0.5,
215
bBlocks: false,
216
dLit: 0.25,
217
dBlocks: false
218
});
219
assert.equal(openBlend, (1 + 0.5 + 0.5 + 0.25) / 4);
220
});
@@ -180,3 +180,41 @@ test("encodeChunkBlob stores pre-baked occlusion aligned with chunkTileLightOccl180
assert.equal(decoded.occlusion[0], chunkTileLightOcclusion(decoded, 0, 0));180
assert.equal(decoded.occlusion[0], chunkTileLightOcclusion(decoded, 0, 0));181
assert.equal(decoded.occlusion[1], LightOcclusion.clear);181
assert.equal(decoded.occlusion[1], LightOcclusion.clear);182
});182
});183
184
test("lit corner blend does not darken daylight beside occluding walls", async () =>185
{186
const { smoothLitCorner } = await import("../../shared/lighting/lightCorners.js");187
const dayOpen = smoothLitCorner({188
homeLit: 1,189
homeBlocks: false,190
aLit: 1,191
aBlocks: false,192
bLit: 0.2,193
bBlocks: true,194
dLit: 0,195
dBlocks: true196
});197
assert.equal(dayOpen, 1);198
const nightDarkBesideLitWall = smoothLitCorner({199
homeLit: 0,200
homeBlocks: false,201
aLit: 0,202
aBlocks: false,203
bLit: 0.8,204
bBlocks: true,205
dLit: 0.5,206
dBlocks: true207
});208
assert.equal(nightDarkBesideLitWall, 0);209
const openBlend = smoothLitCorner({210
homeLit: 1,211
homeBlocks: false,212
aLit: 0.5,213
aBlocks: false,214
bLit: 0.5,215
bBlocks: false,216
dLit: 0.25,217
dBlocks: false218
});219
assert.equal(openBlend, (1 + 0.5 + 0.5 + 0.25) / 4);220
});