Fix fluid atlas N/S flip and reduce tile-grid seams.
Remove incorrect FBO Y-flip (coasts were mirrored), draw atlas tiles opaque to avoid blend fringes, and pixel-snap the chunk atlas sprite.
@@ -2,9 +2,8 @@
2
2
* Per-chunk fluid (water / lava) atlas: render procedural shaders at true
3
3
* SPRITE_SIZE_PX, then nearest-upscale the atlas to chunk world size.
4
4
*
5
* FBO textures use WebGL's bottom-left origin; Framework HTML uploads use
6
* UNPACK_FLIP_Y=false (image top → v=0). Tile centers are Y-flipped so the
7
* displayed atlas matches world orientation without mirrorY.
5
* Tile placement uses the same Y-down screen space as Framework drawSprite
6
* (no extra FBO Y-flip — that put N/S coasts on the wrong sides).
8
7
*/
9
8
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
10
9
import { frameworkImageFromCanvas } from "./canvasSprite.js";
@@ -96,8 +95,8 @@ export function withFluidAtlasPass (glCtx, target, drawFn)
96
95
glCtx._lastHeight = target.size;
97
96
gl.bindFramebuffer(gl.FRAMEBUFFER, target.fb);
98
97
gl.viewport(0, 0, target.size, target.size);
99
gl.enable(gl.BLEND);
100
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
98
// Opaque replace — blending onto clear left 1px fringes / grid seams.
99
gl.disable(gl.BLEND);
101
100
gl.clearColor(0, 0, 0, 0);
102
101
gl.clear(gl.COLOR_BUFFER_BIT);
103
102
drawFn();
@@ -114,12 +113,12 @@ export function withFluidAtlasPass (glCtx, target, drawFn)
114
113
}
115
114
}
116
115
117
/** Pixel-space center of a chunk-local tile inside the FBO (Y-flipped). */
116
/** Pixel-space center of a chunk-local tile inside the FBO (Y-down, same as world). */
118
117
export function fluidAtlasTileCenter (localX, localY)
119
118
{
120
119
return {
121
120
x: localX * SPRITE_SIZE_PX + SPRITE_SIZE_PX / 2,
122
y: (CHUNK_SIZE - 1 - localY) * SPRITE_SIZE_PX + SPRITE_SIZE_PX / 2
121
y: localY * SPRITE_SIZE_PX + SPRITE_SIZE_PX / 2
123
122
};
124
123
}
125
124
@@ -2,9 +2,8 @@2
* Per-chunk fluid (water / lava) atlas: render procedural shaders at true2
* Per-chunk fluid (water / lava) atlas: render procedural shaders at true3
* SPRITE_SIZE_PX, then nearest-upscale the atlas to chunk world size.3
* SPRITE_SIZE_PX, then nearest-upscale the atlas to chunk world size.4
*4
*5
* FBO textures use WebGL's bottom-left origin; Framework HTML uploads use5
* Tile placement uses the same Y-down screen space as Framework drawSprite6
* UNPACK_FLIP_Y=false (image top → v=0). Tile centers are Y-flipped so the6
* (no extra FBO Y-flip — that put N/S coasts on the wrong sides).7
* displayed atlas matches world orientation without mirrorY.8
*/7
*/9
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";8
import { CHUNK_SIZE, SPRITE_SIZE_PX } from "/shared/protocol/constants.js";10
import { frameworkImageFromCanvas } from "./canvasSprite.js";9
import { frameworkImageFromCanvas } from "./canvasSprite.js";@@ -96,8 +95,8 @@ export function withFluidAtlasPass (glCtx, target, drawFn)96
glCtx._lastHeight = target.size;95
glCtx._lastHeight = target.size;97
gl.bindFramebuffer(gl.FRAMEBUFFER, target.fb);96
gl.bindFramebuffer(gl.FRAMEBUFFER, target.fb);98
gl.viewport(0, 0, target.size, target.size);97
gl.viewport(0, 0, target.size, target.size);99
gl.enable(gl.BLEND);98
// Opaque replace — blending onto clear left 1px fringes / grid seams.100
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);99
gl.disable(gl.BLEND);101
gl.clearColor(0, 0, 0, 0);100
gl.clearColor(0, 0, 0, 0);102
gl.clear(gl.COLOR_BUFFER_BIT);101
gl.clear(gl.COLOR_BUFFER_BIT);103
drawFn();102
drawFn();@@ -114,12 +113,12 @@ export function withFluidAtlasPass (glCtx, target, drawFn)114
}113
}115
}114
}116
115
117
/** Pixel-space center of a chunk-local tile inside the FBO (Y-flipped). */116
/** Pixel-space center of a chunk-local tile inside the FBO (Y-down, same as world). */118
export function fluidAtlasTileCenter (localX, localY)117
export function fluidAtlasTileCenter (localX, localY)119
{118
{120
return {119
return {121
x: localX * SPRITE_SIZE_PX + SPRITE_SIZE_PX / 2,120
x: localX * SPRITE_SIZE_PX + SPRITE_SIZE_PX / 2,122
y: (CHUNK_SIZE - 1 - localY) * SPRITE_SIZE_PX + SPRITE_SIZE_PX / 2121
y: localY * SPRITE_SIZE_PX + SPRITE_SIZE_PX / 2123
};122
};124
}123
}125
124
@@ -4442,8 +4442,9 @@ export class WorldView
4442
4442
const left = baked.chunkX * CHUNK_SIZE * size;
4443
4443
const top = baked.chunkY * CHUNK_SIZE * size;
4444
4444
const chunkPx = CHUNK_SIZE * size;
4445
object.transform.position.x = left + chunkPx / 2;
4446
object.transform.position.y = top + chunkPx / 2;
4445
// Pixel-snap: subpixel atlas placement + NEAREST causes grid cracks.
4446
object.transform.position.x = Math.round(left + chunkPx / 2);
4447
object.transform.position.y = Math.round(top + chunkPx / 2);
4447
4448
object.transform.size = new vector(chunkPx, chunkPx);
4448
4449
if (kind === "bloom")
4449
4450
{
@@ -4442,8 +4442,9 @@ export class WorldView4442
const left = baked.chunkX * CHUNK_SIZE * size;4442
const left = baked.chunkX * CHUNK_SIZE * size;4443
const top = baked.chunkY * CHUNK_SIZE * size;4443
const top = baked.chunkY * CHUNK_SIZE * size;4444
const chunkPx = CHUNK_SIZE * size;4444
const chunkPx = CHUNK_SIZE * size;4445
object.transform.position.x = left + chunkPx / 2;4445
// Pixel-snap: subpixel atlas placement + NEAREST causes grid cracks.4446
object.transform.position.y = top + chunkPx / 2;4446
object.transform.position.x = Math.round(left + chunkPx / 2);4447
object.transform.position.y = Math.round(top + chunkPx / 2);4447
object.transform.size = new vector(chunkPx, chunkPx);4448
object.transform.size = new vector(chunkPx, chunkPx);4448
if (kind === "bloom")4449
if (kind === "bloom")4449
{4450
{