Add cliff walls with dirt sides and ground-sampled magenta tops.
Thick/thin cliff sprites reuse wall shapes: sides bake dirt browns with face lighting; tops stay magenta and the block atlas shader replaces them with a center crop of the ground tile beneath, then applies lightmap darkness.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -122,6 +122,7 @@ function decodePngRgba (path)
let off = 8;
let w = 0;
let h = 0;
let colorType = 6;
const idat = [];
while (off < buf.length)
{
@@ -132,6 +133,7 @@ function decodePngRgba (path)
{
w = data.readUInt32BE(0);
h = data.readUInt32BE(4);
colorType = data[9];
}
else if (type === "IDAT")
{ idat.push(data); }
@@ -139,43 +141,52 @@ function decodePngRgba (path)
{ break; }
off += 12 + len;
}
const channels = colorType === 2 ? 3 : colorType === 6 ? 4 : 0;
if (!channels)
{ throw new Error(`${path}: unsupported PNG color type ${colorType}`); }
const inflated = inflateSync(Buffer.concat(idat));
const rgba = new Uint8Array(w * h * 4);
const bpp = 4;
let src = 0;
const prevRow = new Uint8Array(w * channels);
const curRow = new Uint8Array(w * channels);
for (let y = 0; y < h; y++)
{
const filter = inflated[src++];
const row = inflated.subarray(src, src + w * bpp);
src += w * bpp;
const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null;
const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp);
for (let i = 0; i < row.length; i++)
for (let i = 0; i < w * channels; i++)
{
let v = row[i];
let v = inflated[src++];
if (filter === 1)
{ v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; }
{ v = (v + (i >= channels ? curRow[i - channels] : 0)) & 255; }
else if (filter === 2)
{ v = (v + (prev ? prev[i] : 0)) & 255; }
{ v = (v + prevRow[i]) & 255; }
else if (filter === 3)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
v = (v + Math.floor((a + b) / 2)) & 255;
const a = i >= channels ? curRow[i - channels] : 0;
v = (v + Math.floor((a + prevRow[i]) / 2)) & 255;
}
else if (filter === 4)
{
const a = i >= bpp ? out[i - bpp] : 0;
const b = prev ? prev[i] : 0;
const c = prev && i >= bpp ? prev[i - bpp] : 0;
const a = i >= channels ? curRow[i - channels] : 0;
const b = prevRow[i];
const c = i >= channels ? prevRow[i - channels] : 0;
const p = a + b - c;
const pa = Math.abs(p - a);
const pb = Math.abs(p - b);
const pc = Math.abs(p - c);
v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255;
}
out[i] = v;
curRow[i] = v;
}
for (let x = 0; x < w; x++)
{
const si = x * channels;
const di = (y * w + x) * 4;
rgba[di] = curRow[si];
rgba[di + 1] = curRow[si + 1];
rgba[di + 2] = curRow[si + 2];
rgba[di + 3] = channels === 4 ? curRow[si + 3] : 255;
}
prevRow.set(curRow);
}
if (w !== SIZE || h !== SIZE)
{ throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }
@@ -122,6 +122,7 @@ function decodePngRgba (path) let off = 8; let off = 8; let w = 0; let w = 0; let h = 0; let h = 0; let colorType = 6; const idat = []; const idat = []; while (off < buf.length) while (off < buf.length) { {@@ -132,6 +133,7 @@ function decodePngRgba (path) { { w = data.readUInt32BE(0); w = data.readUInt32BE(0); h = data.readUInt32BE(4); h = data.readUInt32BE(4); colorType = data[9]; } } else if (type === "IDAT") else if (type === "IDAT") { idat.push(data); } { idat.push(data); }@@ -139,43 +141,52 @@ function decodePngRgba (path) { break; } { break; } off += 12 + len; off += 12 + len; } } const channels = colorType === 2 ? 3 : colorType === 6 ? 4 : 0; if (!channels) { throw new Error(`${path}: unsupported PNG color type ${colorType}`); } const inflated = inflateSync(Buffer.concat(idat)); const inflated = inflateSync(Buffer.concat(idat)); const rgba = new Uint8Array(w * h * 4); const rgba = new Uint8Array(w * h * 4); const bpp = 4; let src = 0; let src = 0; const prevRow = new Uint8Array(w * channels); const curRow = new Uint8Array(w * channels); for (let y = 0; y < h; y++) for (let y = 0; y < h; y++) { { const filter = inflated[src++]; const filter = inflated[src++]; const row = inflated.subarray(src, src + w * bpp); for (let i = 0; i < w * channels; i++) src += w * bpp; const prev = y > 0 ? rgba.subarray((y - 1) * w * bpp, y * w * bpp) : null; const out = rgba.subarray(y * w * bpp, (y + 1) * w * bpp); for (let i = 0; i < row.length; i++) { { let v = row[i]; let v = inflated[src++]; if (filter === 1) if (filter === 1) { v = (v + (i >= bpp ? out[i - bpp] : 0)) & 255; } { v = (v + (i >= channels ? curRow[i - channels] : 0)) & 255; } else if (filter === 2) else if (filter === 2) { v = (v + (prev ? prev[i] : 0)) & 255; } { v = (v + prevRow[i]) & 255; } else if (filter === 3) else if (filter === 3) { { const a = i >= bpp ? out[i - bpp] : 0; const a = i >= channels ? curRow[i - channels] : 0; const b = prev ? prev[i] : 0; v = (v + Math.floor((a + prevRow[i]) / 2)) & 255; v = (v + Math.floor((a + b) / 2)) & 255; } } else if (filter === 4) else if (filter === 4) { { const a = i >= bpp ? out[i - bpp] : 0; const a = i >= channels ? curRow[i - channels] : 0; const b = prev ? prev[i] : 0; const b = prevRow[i]; const c = prev && i >= bpp ? prev[i - bpp] : 0; const c = i >= channels ? prevRow[i - channels] : 0; const p = a + b - c; const p = a + b - c; const pa = Math.abs(p - a); const pa = Math.abs(p - a); const pb = Math.abs(p - b); const pb = Math.abs(p - b); const pc = Math.abs(p - c); const pc = Math.abs(p - c); v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255; v = (v + (pa <= pb && pa <= pc ? a : pb <= pc ? b : c)) & 255; } } out[i] = v; curRow[i] = v; } } for (let x = 0; x < w; x++) { const si = x * channels; const di = (y * w + x) * 4; rgba[di] = curRow[si]; rgba[di + 1] = curRow[si + 1]; rgba[di + 2] = curRow[si + 2]; rgba[di + 3] = channels === 4 ? curRow[si + 3] : 255; } prevRow.set(curRow); } } if (w !== SIZE || h !== SIZE) if (w !== SIZE || h !== SIZE) { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); } { throw new Error(`${path}: expected ${SIZE}×${SIZE}, got ${w}×${h}`); }@@ -352,8 +352,51 @@ const ATLAS_LIGHTING_FRAG = [
"}"
].join("\n");
/**
* Block-row atlas: optional magenta → sample center crop of the ground atlas
* (bound as u_bump). Used so cliff tops show the ground the wall sits on.
* Darkness matches ATLAS_LIGHTING_FRAG (lightmap in u_secondary).
*/
const ATLAS_BLOCK_GROUND_TOP_FRAG = [
"precision mediump float;",
"varying vec2 v_texCoord;",
"uniform sampler2D u_texture;",
"uniform sampler2D u_secondary;",
"uniform sampler2D u_bump;",
"uniform float u_alpha;",
"uniform float u_ambientDark;",
"uniform float u_lightRow;",
"void main() {",
" vec4 color = texture2D(u_texture, v_texCoord);",
" if (color.a <= 0.0) { discard; }",
" vec3 rgb = color.rgb;",
" // Magenta family (R≈B, G<R): replace with ground tile center crop.",
" float rbDiff = abs(rgb.r - rgb.b);",
" if (rbDiff < 0.02 && rgb.g < rgb.r - 0.02) {",
" float tileX = floor(v_texCoord.x * 16.0);",
" float tileY = max(u_lightRow, 0.0);",
" float localX = fract(v_texCoord.x * 16.0);",
" float localY = v_texCoord.y;",
" vec2 groundUV = vec2(",
" (tileX + 0.25 + localX * 0.5) / 16.0,",
" (tileY + 0.25 + localY * 0.5) / 16.0",
" );",
" rgb = texture2D(u_bump, groundUV).rgb;",
" }",
" vec2 lightUV = v_texCoord;",
" if (u_lightRow >= 0.0) {",
" lightUV.y = (u_lightRow + v_texCoord.y) / 16.0;",
" }",
" float lit = texture2D(u_secondary, lightUV).r;",
" float darkness = u_ambientDark * (1.0 - lit);",
" rgb = mix(rgb, vec3(0.0), darkness);",
" gl_FragColor = vec4(rgb, color.a * u_alpha);",
"}"
].join("\n");
let spriteLightingShader = null;
let atlasLightingShader = null;
let atlasBlockGroundTopShader = null;
let waterGroundShader = null;
let tintLitSpriteShader = null;
let dualTintLitSpriteShader = null;
@@ -374,6 +417,13 @@ function getAtlasLightingShader ()
return atlasLightingShader;
}
function getAtlasBlockGroundTopShader ()
{
if (!atlasBlockGroundTopShader)
{ atlasBlockGroundTopShader = Shader.fragment(ATLAS_BLOCK_GROUND_TOP_FRAG); }
return atlasBlockGroundTopShader;
}
function getWaterGroundShader ()
{
if (!waterGroundShader)
@@ -3297,7 +3347,7 @@ export class WorldView
for (let row = 0; row < CHUNK_SIZE; row++)
{
const object = new GameObject(0, 0, baked.blockImages[row], SORT_BLOCK);
this.#applyAtlasLighting(object, baked.lightmapImage, row);
this.#applyAtlasLighting(object, baked.lightmapImage, row, baked.groundImage);
this.scene.addObject(object);
baked.blockObjects.push(object);
}
@@ -3314,6 +3364,7 @@ export class WorldView
baked.groundCanvas = atlases.ground;
baked.groundImage = groundImage;
baked.groundObject.renderer.sprite = groundImage;
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1);
}
for (let row = 0; row < CHUNK_SIZE; row++)
{
@@ -3323,6 +3374,12 @@ export class WorldView
baked.blockImages[row] = blockImages[row];
baked.blockObjects[row].renderer.sprite = blockImages[row];
}
this.#applyAtlasLighting(
baked.blockObjects[row],
baked.lightmapImage,
row,
baked.groundImage
);
}
if (baked.bloomCanvas !== atlases.bloom)
{
@@ -3419,12 +3476,21 @@ export class WorldView
{ this.#scheduleTextureWarm(); }
}
#applyAtlasLighting (object, lightmapImage, lightRow)
#applyAtlasLighting (object, lightmapImage, lightRow, groundImage = null)
{
if (!object?.renderer)
{ return; }
object._lit = true;
object.renderer.shader = getAtlasLightingShader();
if (groundImage)
{
object.renderer.shader = getAtlasBlockGroundTopShader();
object.renderer.bumpMap = groundImage;
}
else
{
object.renderer.shader = getAtlasLightingShader();
object.renderer.bumpMap = null;
}
object.renderer.secondaryMap = lightmapImage;
object.renderer.shaderUniforms = {
u_ambientDark: 0,
@@ -352,8 +352,51 @@ const ATLAS_LIGHTING_FRAG = [ "}" "}"].join("\n");].join("\n");/** * Block-row atlas: optional magenta → sample center crop of the ground atlas * (bound as u_bump). Used so cliff tops show the ground the wall sits on. * Darkness matches ATLAS_LIGHTING_FRAG (lightmap in u_secondary). */const ATLAS_BLOCK_GROUND_TOP_FRAG = [ "precision mediump float;", "varying vec2 v_texCoord;", "uniform sampler2D u_texture;", "uniform sampler2D u_secondary;", "uniform sampler2D u_bump;", "uniform float u_alpha;", "uniform float u_ambientDark;", "uniform float u_lightRow;", "void main() {", " vec4 color = texture2D(u_texture, v_texCoord);", " if (color.a <= 0.0) { discard; }", " vec3 rgb = color.rgb;", " // Magenta family (R≈B, G<R): replace with ground tile center crop.", " float rbDiff = abs(rgb.r - rgb.b);", " if (rbDiff < 0.02 && rgb.g < rgb.r - 0.02) {", " float tileX = floor(v_texCoord.x * 16.0);", " float tileY = max(u_lightRow, 0.0);", " float localX = fract(v_texCoord.x * 16.0);", " float localY = v_texCoord.y;", " vec2 groundUV = vec2(", " (tileX + 0.25 + localX * 0.5) / 16.0,", " (tileY + 0.25 + localY * 0.5) / 16.0", " );", " rgb = texture2D(u_bump, groundUV).rgb;", " }", " vec2 lightUV = v_texCoord;", " if (u_lightRow >= 0.0) {", " lightUV.y = (u_lightRow + v_texCoord.y) / 16.0;", " }", " float lit = texture2D(u_secondary, lightUV).r;", " float darkness = u_ambientDark * (1.0 - lit);", " rgb = mix(rgb, vec3(0.0), darkness);", " gl_FragColor = vec4(rgb, color.a * u_alpha);", "}"].join("\n");let spriteLightingShader = null;let spriteLightingShader = null;let atlasLightingShader = null;let atlasLightingShader = null;let atlasBlockGroundTopShader = null;let waterGroundShader = null;let waterGroundShader = null;let tintLitSpriteShader = null;let tintLitSpriteShader = null;let dualTintLitSpriteShader = null;let dualTintLitSpriteShader = null;@@ -374,6 +417,13 @@ function getAtlasLightingShader () return atlasLightingShader; return atlasLightingShader;}}function getAtlasBlockGroundTopShader (){ if (!atlasBlockGroundTopShader) { atlasBlockGroundTopShader = Shader.fragment(ATLAS_BLOCK_GROUND_TOP_FRAG); } return atlasBlockGroundTopShader;}function getWaterGroundShader ()function getWaterGroundShader (){{ if (!waterGroundShader) if (!waterGroundShader)@@ -3297,7 +3347,7 @@ export class WorldView for (let row = 0; row < CHUNK_SIZE; row++) for (let row = 0; row < CHUNK_SIZE; row++) { { const object = new GameObject(0, 0, baked.blockImages[row], SORT_BLOCK); const object = new GameObject(0, 0, baked.blockImages[row], SORT_BLOCK); this.#applyAtlasLighting(object, baked.lightmapImage, row); this.#applyAtlasLighting(object, baked.lightmapImage, row, baked.groundImage); this.scene.addObject(object); this.scene.addObject(object); baked.blockObjects.push(object); baked.blockObjects.push(object); } }@@ -3314,6 +3364,7 @@ export class WorldView baked.groundCanvas = atlases.ground; baked.groundCanvas = atlases.ground; baked.groundImage = groundImage; baked.groundImage = groundImage; baked.groundObject.renderer.sprite = groundImage; baked.groundObject.renderer.sprite = groundImage; this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1); } } for (let row = 0; row < CHUNK_SIZE; row++) for (let row = 0; row < CHUNK_SIZE; row++) { {@@ -3323,6 +3374,12 @@ export class WorldView baked.blockImages[row] = blockImages[row]; baked.blockImages[row] = blockImages[row]; baked.blockObjects[row].renderer.sprite = blockImages[row]; baked.blockObjects[row].renderer.sprite = blockImages[row]; } } this.#applyAtlasLighting( baked.blockObjects[row], baked.lightmapImage, row, baked.groundImage ); } } if (baked.bloomCanvas !== atlases.bloom) if (baked.bloomCanvas !== atlases.bloom) { {@@ -3419,12 +3476,21 @@ export class WorldView { this.#scheduleTextureWarm(); } { this.#scheduleTextureWarm(); } } } #applyAtlasLighting (object, lightmapImage, lightRow) #applyAtlasLighting (object, lightmapImage, lightRow, groundImage = null) { { if (!object?.renderer) if (!object?.renderer) { return; } { return; } object._lit = true; object._lit = true; object.renderer.shader = getAtlasLightingShader(); if (groundImage) { object.renderer.shader = getAtlasBlockGroundTopShader(); object.renderer.bumpMap = groundImage; } else { object.renderer.shader = getAtlasLightingShader(); object.renderer.bumpMap = null; } object.renderer.secondaryMap = lightmapImage; object.renderer.secondaryMap = lightmapImage; object.renderer.shaderUniforms = { object.renderer.shaderUniforms = { u_ambientDark: 0, u_ambientDark: 0,@@ -32,6 +32,9 @@ test("sprite folders expose alphabetical states; first is default", () =>
assert.ok(catalog.images.some((image) => image.name === "block:thick-wood-wall:pine-0"));
assert.ok(catalog.images.some((image) => image.name === "block:thin-wood-wall:oak-15"));
assert.equal(catalog.blocks["thick-wood-wall"].states.length, WOOD_TIER_ORDER.length * 16);
assert.equal(catalog.blocks["thick-cliff"].states.length, 16);
assert.equal(catalog.blocks["thin-cliff"].states.length, 16);
assert.ok(catalog.images.some((image) => image.name === "block:thick-cliff:thick-cliff-nesw"));
assert.equal(catalog.images[0].subImgTotal, 1);
assert.equal(catalog.images[0].perRow, 1);
});
@@ -32,6 +32,9 @@ test("sprite folders expose alphabetical states; first is default", () => assert.ok(catalog.images.some((image) => image.name === "block:thick-wood-wall:pine-0")); assert.ok(catalog.images.some((image) => image.name === "block:thick-wood-wall:pine-0")); assert.ok(catalog.images.some((image) => image.name === "block:thin-wood-wall:oak-15")); assert.ok(catalog.images.some((image) => image.name === "block:thin-wood-wall:oak-15")); assert.equal(catalog.blocks["thick-wood-wall"].states.length, WOOD_TIER_ORDER.length * 16); assert.equal(catalog.blocks["thick-wood-wall"].states.length, WOOD_TIER_ORDER.length * 16); assert.equal(catalog.blocks["thick-cliff"].states.length, 16); assert.equal(catalog.blocks["thin-cliff"].states.length, 16); assert.ok(catalog.images.some((image) => image.name === "block:thick-cliff:thick-cliff-nesw")); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].subImgTotal, 1); assert.equal(catalog.images[0].perRow, 1); assert.equal(catalog.images[0].perRow, 1);});});