BlueGit

timfa questward

Sample lightmap halo tiles with per-tile light sources across the 3×3 boundary.

Outer-chunk corner blends were dark because the ±1 halo reused the outer spill list, so inner neighbour tiles lost torches that do not reach the outer chunk.

timfa Tim Falken · pushed by timfa

Authored 2026-09-02 · 2 months ago

Hash
33e691501c1a6c47d92a2b7eb62c1e7fe35ab7f1
Parent
cdef12b4
1 file changed +18 −6
client/src/render/worldView.js +18 −6
@@ -4108,7 +4108,7 @@ export class WorldView
4108 4108 if (baked._inViewport === false)
4109 4109 { continue; }
4110 4110 const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, mobileLights, blockLights);
4111 this.#writeChunkLightmap(baked, lights, lightOcclusion, ambientDark);
4111 this.#writeChunkLightmap(baked, lights, mobileLights, blockLights, lightOcclusion, ambientDark);
4112 4112 // Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.
4113 4113 if (baked.groundObject?.renderer?.shaderUniforms)
4114 4114 { baked.groundObject.renderer.shaderUniforms.u_ambientDark = 1; }
@@ -4233,7 +4233,7 @@ export class WorldView
4233 4233 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
4234 4234 }
4235 4235
4236 #fillChunkLightGrids (baked, activeLights, lightOcclusion, ambientDark)
4236 #fillChunkLightGrids (baked, mobileLights, blockLights, lightOcclusion, ambientDark)
4237 4237 {
4238 4238 const gridW = CHUNK_SIZE + 2;
4239 4239 const gridSize = gridW * gridW;
@@ -4250,7 +4250,10 @@ export class WorldView
4250 4250 const tileX = baked.chunkX * CHUNK_SIZE + lx;
4251 4251 const tileY = baked.chunkY * CHUNK_SIZE + ly;
4252 4252 const gi = (ly + 1) * gridW + (lx + 1);
4253 grid[gi] = this.#intensityAtTile(tileX, tileY, activeLights, lightOcclusion, ambientDark);
4253 // Halo tiles may sit in the other lighting region (3×3 vs outer). Resolve
4254 // sources per tile so corner blends match the neighbour chunk's shading.
4255 const lights = this.#dynamicLightsForTile(tileX, tileY, mobileLights, blockLights);
4256 grid[gi] = this.#intensityAtTile(tileX, tileY, lights, lightOcclusion, ambientDark);
4254 4257 occlude[gi] = this.#tileOccludesLight(tileX, tileY) ? 1 : 0;
4255 4258 }
4256 4259 }
@@ -4379,13 +4382,22 @@ export class WorldView
4379 4382 * Per-chunk lightmap for atlas ground/blocks. Open tiles blend into open neighbours;
4380 4383 * occluding tiles stay flat and contribute 0 into others so light does not bleed
4381 4384 * through a wall to the far side. Diagonals only when both cardinals are clear.
4385 * @param chunkLights Sources that affect this chunk (cache key + in-chunk samples).
4386 * @param mobileLights / blockLights Full lists so the ±1 halo can sample across the 3×3 boundary.
4382 4387 */
4383 #writeChunkLightmap (baked, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())
4388 #writeChunkLightmap (
4389 baked,
4390 chunkLights,
4391 mobileLights,
4392 blockLights,
4393 lightOcclusion,
4394 ambientDark = this.#ambientDarkness()
4395 )
4384 4396 {
4385 4397 const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);
4386 4398 if (!snapshot)
4387 4399 { return; }
4388 const cacheKey = this.#chunkLightmapCacheKey(baked, activeLights, ambientDark);
4400 const cacheKey = this.#chunkLightmapCacheKey(baked, chunkLights, ambientDark);
4389 4401 if (cacheKey && baked.lightmapCacheKey === cacheKey)
4390 4402 { return; }
4391 4403 const atlasPx = CHUNK_SIZE * SPRITE_SIZE_PX;
@@ -4394,7 +4406,7 @@ export class WorldView
4394 4406 { baked.lightmapPixels = new Uint8ClampedArray(pixelCount); }
4395 4407 const pixels = baked.lightmapPixels;
4396 4408
4397 this.#fillChunkLightGrids(baked, activeLights, lightOcclusion, ambientDark);
4409 this.#fillChunkLightGrids(baked, mobileLights, blockLights, lightOcclusion, ambientDark);
4398 4410 const simple = this.lightingMode === "simple";
4399 4411
4400 4412 for (let localY = 0; localY < CHUNK_SIZE; localY++)
@@ -4108,7 +4108,7 @@ export class WorldView
4108 if (baked._inViewport === false)
4108 if (baked._inViewport === false)
4109 { continue; }
4109 { continue; }
4110 const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, mobileLights, blockLights);
4110 const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, mobileLights, blockLights);
4111 this.#writeChunkLightmap(baked, lights, lightOcclusion, ambientDark);
4111 this.#writeChunkLightmap(baked, lights, mobileLights, blockLights, lightOcclusion, ambientDark);
4112 // Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.
4112 // Lightmap stores visible light (1 − shade); shader applies darkness = 1 − lit.
4113 if (baked.groundObject?.renderer?.shaderUniforms)
4113 if (baked.groundObject?.renderer?.shaderUniforms)
4114 { baked.groundObject.renderer.shaderUniforms.u_ambientDark = 1; }
4114 { baked.groundObject.renderer.shaderUniforms.u_ambientDark = 1; }
@@ -4233,7 +4233,7 @@ export class WorldView
4233 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
4233 return blockLightOcclusionForBlock(snapshot.blocks?.[index]) === LightOcclusion.solid;
4234 }
4234 }
4235
4235
4236 #fillChunkLightGrids (baked, activeLights, lightOcclusion, ambientDark)
4236 #fillChunkLightGrids (baked, mobileLights, blockLights, lightOcclusion, ambientDark)
4237 {
4237 {
4238 const gridW = CHUNK_SIZE + 2;
4238 const gridW = CHUNK_SIZE + 2;
4239 const gridSize = gridW * gridW;
4239 const gridSize = gridW * gridW;
@@ -4250,7 +4250,10 @@ export class WorldView
4250 const tileX = baked.chunkX * CHUNK_SIZE + lx;
4250 const tileX = baked.chunkX * CHUNK_SIZE + lx;
4251 const tileY = baked.chunkY * CHUNK_SIZE + ly;
4251 const tileY = baked.chunkY * CHUNK_SIZE + ly;
4252 const gi = (ly + 1) * gridW + (lx + 1);
4252 const gi = (ly + 1) * gridW + (lx + 1);
4253 grid[gi] = this.#intensityAtTile(tileX, tileY, activeLights, lightOcclusion, ambientDark);
4253 // Halo tiles may sit in the other lighting region (3×3 vs outer). Resolve
4254 // sources per tile so corner blends match the neighbour chunk's shading.
4255 const lights = this.#dynamicLightsForTile(tileX, tileY, mobileLights, blockLights);
4256 grid[gi] = this.#intensityAtTile(tileX, tileY, lights, lightOcclusion, ambientDark);
4254 occlude[gi] = this.#tileOccludesLight(tileX, tileY) ? 1 : 0;
4257 occlude[gi] = this.#tileOccludesLight(tileX, tileY) ? 1 : 0;
4255 }
4258 }
4256 }
4259 }
@@ -4379,13 +4382,22 @@ export class WorldView
4379 * Per-chunk lightmap for atlas ground/blocks. Open tiles blend into open neighbours;
4382 * Per-chunk lightmap for atlas ground/blocks. Open tiles blend into open neighbours;
4380 * occluding tiles stay flat and contribute 0 into others so light does not bleed
4383 * occluding tiles stay flat and contribute 0 into others so light does not bleed
4381 * through a wall to the far side. Diagonals only when both cardinals are clear.
4384 * through a wall to the far side. Diagonals only when both cardinals are clear.
4385 * @param chunkLights Sources that affect this chunk (cache key + in-chunk samples).
4386 * @param mobileLights / blockLights Full lists so the ±1 halo can sample across the 3×3 boundary.
4382 */
4387 */
4383 #writeChunkLightmap (baked, activeLights, lightOcclusion, ambientDark = this.#ambientDarkness())
4388 #writeChunkLightmap (
4389 baked,
4390 chunkLights,
4391 mobileLights,
4392 blockLights,
4393 lightOcclusion,
4394 ambientDark = this.#ambientDarkness()
4395 )
4384 {
4396 {
4385 const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);
4397 const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);
4386 if (!snapshot)
4398 if (!snapshot)
4387 { return; }
4399 { return; }
4388 const cacheKey = this.#chunkLightmapCacheKey(baked, activeLights, ambientDark);
4400 const cacheKey = this.#chunkLightmapCacheKey(baked, chunkLights, ambientDark);
4389 if (cacheKey && baked.lightmapCacheKey === cacheKey)
4401 if (cacheKey && baked.lightmapCacheKey === cacheKey)
4390 { return; }
4402 { return; }
4391 const atlasPx = CHUNK_SIZE * SPRITE_SIZE_PX;
4403 const atlasPx = CHUNK_SIZE * SPRITE_SIZE_PX;
@@ -4394,7 +4406,7 @@ export class WorldView
4394 { baked.lightmapPixels = new Uint8ClampedArray(pixelCount); }
4406 { baked.lightmapPixels = new Uint8ClampedArray(pixelCount); }
4395 const pixels = baked.lightmapPixels;
4407 const pixels = baked.lightmapPixels;
4396
4408
4397 this.#fillChunkLightGrids(baked, activeLights, lightOcclusion, ambientDark);
4409 this.#fillChunkLightGrids(baked, mobileLights, blockLights, lightOcclusion, ambientDark);
4398 const simple = this.lightingMode === "simple";
4410 const simple = this.lightingMode === "simple";
4399
4411
4400 for (let localY = 0; localY < CHUNK_SIZE; localY++)
4412 for (let localY = 0; localY < CHUNK_SIZE; localY++)