Improve cliff tops: dirt north face, 1:1 blended ground sample.
Thick cliffs keep magenta only on the plateau; north bevel is dirt. The atlas shader samples the ground atlas at matching tile UVs so scale and soft-terrain blend match the floor beneath.
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.
@@ -1,20 +1,22 @@
1
1
/**
2
2
* Bake wall textures onto thick/thin greyscale face-id shape masks.
3
3
*
4
* Shapes (source of truth):
4
* Shape masks (greyscale face-IDs) belong in:
5
5
* client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png
6
6
*
7
* Workflow when editing shapes in the live gameplay folders:
8
* 1. Paint face-id greys in thick-stone-wall / thin-stone-wall
9
* 2. node client/scripts/texture-wall-sprites.mjs --sync-shapes
10
* (copies live → examples only if files are still face-id greyscale)
11
* 3. node client/scripts/texture-wall-sprites.mjs --variant=…
12
*
7
13
* Usage:
8
* node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff
9
* node client/scripts/texture-wall-sprites.mjs --variant=all
14
* node client/scripts/texture-wall-sprites.mjs --sync-shapes
15
* node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff|--all
10
16
*
11
* cobble → thick-stone-wall / thin-stone-wall (named)
12
* smooth → thick-smooth-stone-wall / thin-smooth-stone-wall (named)
13
* brick → thick-brick-wall / thin-brick-wall (named)
14
* wood → thick-wood-wall / thin-wood-wall (magenta masks 0–15)
15
* cliff → thick-cliff / thin-cliff (dirt sides + magenta top, named)
17
* cobble overwrites thick/thin-stone-wall — pass --force (required) so hand tweaks are not clobbered.
16
18
*/
17
import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";
19
import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync, cpSync } from "node:fs";
18
20
import { deflateSync, inflateSync } from "node:zlib";
19
21
import { fileURLToPath } from "node:url";
20
22
import { dirname, join } from "node:path";
@@ -339,9 +341,20 @@ function woodMagenta (role)
339
341
return rgba(L, gHi, L);
340
342
}
341
343
342
function cliffShade (x, y, role)
344
/**
345
* Cliff magenta tops: thick = plateau only (N is a dirt north face).
346
* Thin has no separate T — ridge top is role N.
347
*/
348
function isCliffTopRole (role, shapePrefix)
349
{
350
if (shapePrefix.startsWith("thin"))
351
{ return role === "N"; }
352
return role === "T";
353
}
354
355
function cliffShade (x, y, role, shapePrefix)
343
356
{
344
if (isTopRole(role))
357
if (isCliffTopRole(role, shapePrefix))
345
358
{
346
359
// Full magenta top — replaced in-game by ground sample shader.
347
360
return rgba(255, 0, 255);
@@ -379,7 +392,7 @@ function paintPixel (variant, prefix, g, x, y)
379
392
if (variant === "wood")
380
393
{ return woodMagenta(role); }
381
394
if (variant === "cliff")
382
{ return cliffShade(x, y, role); }
395
{ return cliffShade(x, y, role, prefix); }
383
396
throw new Error(`Unknown variant ${variant}`);
384
397
}
385
398
@@ -440,11 +453,70 @@ function namedOutName (outPrefix, shapeName, shapeKey)
440
453
return `${outPrefix}${suffix}`;
441
454
}
442
455
443
function bakeVariant (variant)
456
const FACE_ID_GREYS = new Set([
457
0x40, 0x54, 0x6c, 0x73, 0x80, 0x95, 0xaf, 0xb6
458
]);
459
460
function isFaceIdMask (rgba)
461
{
462
for (let i = 0; i < rgba.length; i += 4)
463
{
464
if (rgba[i + 3] === 0)
465
{ continue; }
466
if (rgba[i] !== rgba[i + 1] || rgba[i] !== rgba[i + 2])
467
{ return false; }
468
if (!FACE_ID_GREYS.has(rgba[i]))
469
{ return false; }
470
}
471
return true;
472
}
473
474
/** Copy face-id greyscale from live thick/thin-stone-wall → _examples (never textured art). */
475
function syncShapesFromLive ()
476
{
477
mkdirSync(EXAMPLES, { recursive: true });
478
let copied = 0;
479
for (const kind of ["thick", "thin"])
480
{
481
const shapeKey = `${kind}-stone-wall`;
482
const liveDir = join(ROOT, shapeKey);
483
if (!existsSync(liveDir))
484
{ throw new Error(`Missing live folder ${liveDir}`); }
485
const files = readdirSync(liveDir)
486
.filter((name) => name.startsWith(shapeKey) && name.endsWith(".png"))
487
.sort();
488
if (files.length !== 16)
489
{ throw new Error(`Expected 16 live ${shapeKey} sprites, found ${files.length}`); }
490
for (const name of files)
491
{
492
const rgba = decodePngRgba(join(liveDir, name));
493
if (!isFaceIdMask(rgba))
494
{
495
throw new Error(
496
`${shapeKey}/${name} is not a face-id greyscale mask (already textured?). ` +
497
`Paint face-id greys in the live folder, then re-run --sync-shapes.`
498
);
499
}
500
cpSync(join(liveDir, name), join(EXAMPLES, name));
501
copied++;
502
}
503
console.log(` synced ${kind} → ${EXAMPLES}`);
504
}
505
console.log(`Synced ${copied} face-id masks into examples.`);
506
}
507
508
function bakeVariant (variant, { force = false } = {})
444
509
{
445
510
const cfg = VARIANT_OUT[variant];
446
511
if (!cfg)
447
512
{ throw new Error(`Unknown variant: ${variant}`); }
513
if (variant === "cobble" && !force)
514
{
515
throw new Error(
516
"Refusing to overwrite thick/thin-stone-wall without --force " +
517
"(hand-tweaked gameplay sprites). Sync shapes with --sync-shapes first if needed."
518
);
519
}
448
520
let wrote = 0;
449
521
for (const kind of ["thick", "thin"])
450
522
{
@@ -469,7 +541,6 @@ function bakeVariant (variant)
469
541
}
470
542
else
471
543
{
472
// Material-connect: write 0.png … 15.png from matching named shapes.
473
544
for (let mask = 0; mask < 16; mask++)
474
545
{
475
546
const suffix = cardinalConnectionSuffix(mask);
@@ -485,8 +556,20 @@ function bakeVariant (variant)
485
556
return wrote;
486
557
}
487
558
559
if (process.argv.includes("--sync-shapes"))
560
{
561
syncShapesFromLive();
562
process.exit(0);
563
}
564
488
565
const arg = process.argv.find((a) => a.startsWith("--variant="));
489
const variant = arg ? arg.slice("--variant=".length) : "cobble";
566
const variant = arg ? arg.slice("--variant=".length) : null;
567
if (!variant)
568
{
569
console.error("Usage: --sync-shapes | --variant=cobble|smooth|brick|wood|cliff|all [--force]");
570
process.exit(1);
571
}
572
const force = process.argv.includes("--force");
490
573
const list = variant === "all"
491
574
? ["cobble", "smooth", "brick", "wood", "cliff"]
492
575
: [variant];
@@ -498,6 +581,6 @@ let total = 0;
498
581
for (const v of list)
499
582
{
500
583
console.log(`Baking ${v}…`);
501
total += bakeVariant(v);
584
total += bakeVariant(v, { force });
502
585
}
503
586
console.log(`Done (${total} sprites).`);
@@ -1,20 +1,22 @@1
/**1
/**2
* Bake wall textures onto thick/thin greyscale face-id shape masks.2
* Bake wall textures onto thick/thin greyscale face-id shape masks.3
*3
*4
* Shapes (source of truth):4
* Shape masks (greyscale face-IDs) belong in:5
* client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png5
* client/assets/blocks/_examples/stone-wall/{thick,thin}-stone-wall*.png6
*6
*7
* Workflow when editing shapes in the live gameplay folders:8
* 1. Paint face-id greys in thick-stone-wall / thin-stone-wall9
* 2. node client/scripts/texture-wall-sprites.mjs --sync-shapes10
* (copies live → examples only if files are still face-id greyscale)11
* 3. node client/scripts/texture-wall-sprites.mjs --variant=…12
*7
* Usage:13
* Usage:8
* node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff14
* node client/scripts/texture-wall-sprites.mjs --sync-shapes9
* node client/scripts/texture-wall-sprites.mjs --variant=all15
* node client/scripts/texture-wall-sprites.mjs --variant=cobble|smooth|brick|wood|cliff|--all10
*16
*11
* cobble → thick-stone-wall / thin-stone-wall (named)17
* cobble overwrites thick/thin-stone-wall — pass --force (required) so hand tweaks are not clobbered.12
* smooth → thick-smooth-stone-wall / thin-smooth-stone-wall (named)13
* brick → thick-brick-wall / thin-brick-wall (named)14
* wood → thick-wood-wall / thin-wood-wall (magenta masks 0–15)15
* cliff → thick-cliff / thin-cliff (dirt sides + magenta top, named)16
*/18
*/17
import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync } from "node:fs";19
import { mkdirSync, writeFileSync, readdirSync, readFileSync, existsSync, cpSync } from "node:fs";18
import { deflateSync, inflateSync } from "node:zlib";20
import { deflateSync, inflateSync } from "node:zlib";19
import { fileURLToPath } from "node:url";21
import { fileURLToPath } from "node:url";20
import { dirname, join } from "node:path";22
import { dirname, join } from "node:path";@@ -339,9 +341,20 @@ function woodMagenta (role)339
return rgba(L, gHi, L);341
return rgba(L, gHi, L);340
}342
}341
343
342
function cliffShade (x, y, role)344
/**345
* Cliff magenta tops: thick = plateau only (N is a dirt north face).346
* Thin has no separate T — ridge top is role N.347
*/348
function isCliffTopRole (role, shapePrefix)349
{350
if (shapePrefix.startsWith("thin"))351
{ return role === "N"; }352
return role === "T";353
}354
355
function cliffShade (x, y, role, shapePrefix)343
{356
{344
if (isTopRole(role))357
if (isCliffTopRole(role, shapePrefix))345
{358
{346
// Full magenta top — replaced in-game by ground sample shader.359
// Full magenta top — replaced in-game by ground sample shader.347
return rgba(255, 0, 255);360
return rgba(255, 0, 255);@@ -379,7 +392,7 @@ function paintPixel (variant, prefix, g, x, y)379
if (variant === "wood")392
if (variant === "wood")380
{ return woodMagenta(role); }393
{ return woodMagenta(role); }381
if (variant === "cliff")394
if (variant === "cliff")382
{ return cliffShade(x, y, role); }395
{ return cliffShade(x, y, role, prefix); }383
throw new Error(`Unknown variant ${variant}`);396
throw new Error(`Unknown variant ${variant}`);384
}397
}385
398
@@ -440,11 +453,70 @@ function namedOutName (outPrefix, shapeName, shapeKey)440
return `${outPrefix}${suffix}`;453
return `${outPrefix}${suffix}`;441
}454
}442
455
443
function bakeVariant (variant)456
const FACE_ID_GREYS = new Set([457
0x40, 0x54, 0x6c, 0x73, 0x80, 0x95, 0xaf, 0xb6458
]);459
460
function isFaceIdMask (rgba)461
{462
for (let i = 0; i < rgba.length; i += 4)463
{464
if (rgba[i + 3] === 0)465
{ continue; }466
if (rgba[i] !== rgba[i + 1] || rgba[i] !== rgba[i + 2])467
{ return false; }468
if (!FACE_ID_GREYS.has(rgba[i]))469
{ return false; }470
}471
return true;472
}473
474
/** Copy face-id greyscale from live thick/thin-stone-wall → _examples (never textured art). */475
function syncShapesFromLive ()476
{477
mkdirSync(EXAMPLES, { recursive: true });478
let copied = 0;479
for (const kind of ["thick", "thin"])480
{481
const shapeKey = `${kind}-stone-wall`;482
const liveDir = join(ROOT, shapeKey);483
if (!existsSync(liveDir))484
{ throw new Error(`Missing live folder ${liveDir}`); }485
const files = readdirSync(liveDir)486
.filter((name) => name.startsWith(shapeKey) && name.endsWith(".png"))487
.sort();488
if (files.length !== 16)489
{ throw new Error(`Expected 16 live ${shapeKey} sprites, found ${files.length}`); }490
for (const name of files)491
{492
const rgba = decodePngRgba(join(liveDir, name));493
if (!isFaceIdMask(rgba))494
{495
throw new Error(496
`${shapeKey}/${name} is not a face-id greyscale mask (already textured?). ` +497
`Paint face-id greys in the live folder, then re-run --sync-shapes.`498
);499
}500
cpSync(join(liveDir, name), join(EXAMPLES, name));501
copied++;502
}503
console.log(` synced ${kind} → ${EXAMPLES}`);504
}505
console.log(`Synced ${copied} face-id masks into examples.`);506
}507
508
function bakeVariant (variant, { force = false } = {})444
{509
{445
const cfg = VARIANT_OUT[variant];510
const cfg = VARIANT_OUT[variant];446
if (!cfg)511
if (!cfg)447
{ throw new Error(`Unknown variant: ${variant}`); }512
{ throw new Error(`Unknown variant: ${variant}`); }513
if (variant === "cobble" && !force)514
{515
throw new Error(516
"Refusing to overwrite thick/thin-stone-wall without --force " +517
"(hand-tweaked gameplay sprites). Sync shapes with --sync-shapes first if needed."518
);519
}448
let wrote = 0;520
let wrote = 0;449
for (const kind of ["thick", "thin"])521
for (const kind of ["thick", "thin"])450
{522
{@@ -469,7 +541,6 @@ function bakeVariant (variant)469
}541
}470
else542
else471
{543
{472
// Material-connect: write 0.png … 15.png from matching named shapes.473
for (let mask = 0; mask < 16; mask++)544
for (let mask = 0; mask < 16; mask++)474
{545
{475
const suffix = cardinalConnectionSuffix(mask);546
const suffix = cardinalConnectionSuffix(mask);@@ -485,8 +556,20 @@ function bakeVariant (variant)485
return wrote;556
return wrote;486
}557
}487
558
559
if (process.argv.includes("--sync-shapes"))560
{561
syncShapesFromLive();562
process.exit(0);563
}564
488
const arg = process.argv.find((a) => a.startsWith("--variant="));565
const arg = process.argv.find((a) => a.startsWith("--variant="));489
const variant = arg ? arg.slice("--variant=".length) : "cobble";566
const variant = arg ? arg.slice("--variant=".length) : null;567
if (!variant)568
{569
console.error("Usage: --sync-shapes | --variant=cobble|smooth|brick|wood|cliff|all [--force]");570
process.exit(1);571
}572
const force = process.argv.includes("--force");490
const list = variant === "all"573
const list = variant === "all"491
? ["cobble", "smooth", "brick", "wood", "cliff"]574
? ["cobble", "smooth", "brick", "wood", "cliff"]492
: [variant];575
: [variant];@@ -498,6 +581,6 @@ let total = 0;498
for (const v of list)581
for (const v of list)499
{582
{500
console.log(`Baking ${v}…`);583
console.log(`Baking ${v}…`);501
total += bakeVariant(v);584
total += bakeVariant(v, { force });502
}585
}503
console.log(`Done (${total} sprites).`);586
console.log(`Done (${total} sprites).`);@@ -5,13 +5,14 @@ import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";
5
5
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
6
6
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
7
7
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
8
import {
9
resolveItemTint,
10
resolveEquipTint,
11
resolveItemDualTint,
12
resolveEquipDualTint,
13
normalizeRgb
14
} from "/shared/render/tint.js";
8
import
9
{
10
resolveItemTint,
11
resolveEquipTint,
12
resolveItemDualTint,
13
resolveEquipDualTint,
14
normalizeRgb
15
} from "/shared/render/tint.js";
15
16
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
16
17
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
17
18
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";
@@ -353,8 +354,9 @@ const ATLAS_LIGHTING_FRAG = [
353
354
].join("\n");
354
355
355
356
/**
356
* Block-row atlas: optional magenta → sample center crop of the ground atlas
357
* (bound as u_bump). Used so cliff tops show the ground the wall sits on.
357
* Block-row atlas: magenta → sample the ground atlas (u_bump) at the same
358
* tile-local UV (1:1 scale). The ground atlas already includes soft-terrain
359
* blending when that preference is on, so cliff tops match the floor beneath.
358
360
* Darkness matches ATLAS_LIGHTING_FRAG (lightmap in u_secondary).
359
361
*/
360
362
const ATLAS_BLOCK_GROUND_TOP_FRAG = [
@@ -370,17 +372,14 @@ const ATLAS_BLOCK_GROUND_TOP_FRAG = [
370
372
" vec4 color = texture2D(u_texture, v_texCoord);",
371
373
" if (color.a <= 0.0) { discard; }",
372
374
" vec3 rgb = color.rgb;",
373
" // Magenta family (R≈B, G<R): replace with ground tile center crop.",
375
" // Magenta family (R≈B, G<R): replace with blended ground under this pixel.",
374
376
" float rbDiff = abs(rgb.r - rgb.b);",
375
377
" if (rbDiff < 0.02 && rgb.g < rgb.r - 0.02) {",
376
378
" float tileX = floor(v_texCoord.x * 16.0);",
377
379
" float tileY = max(u_lightRow, 0.0);",
378
380
" float localX = fract(v_texCoord.x * 16.0);",
379
381
" float localY = v_texCoord.y;",
380
" vec2 groundUV = vec2(",
381
" (tileX + 0.25 + localX * 0.5) / 16.0,",
382
" (tileY + 0.25 + localY * 0.5) / 16.0",
383
" );",
382
" vec2 groundUV = vec2((tileX + localX) / 16.0, (tileY + localY) / 16.0);",
384
383
" rgb = texture2D(u_bump, groundUV).rgb;",
385
384
" }",
386
385
" vec2 lightUV = v_texCoord;",
@@ -5,13 +5,14 @@ import { bakeChunkOcclusion } from "/shared/lighting/chunkOcclusion.js";5
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";5
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";6
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";6
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";7
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";7
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";8
import {8
import9
resolveItemTint,9
{10
resolveEquipTint,10
resolveItemTint,11
resolveItemDualTint,11
resolveEquipTint,12
resolveEquipDualTint,12
resolveItemDualTint,13
normalizeRgb13
resolveEquipDualTint,14
} from "/shared/render/tint.js";14
normalizeRgb15
} from "/shared/render/tint.js";15
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";16
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";16
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";17
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";17
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";18
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight, LightOcclusion } from "/shared/definitions/tiles.js";@@ -353,8 +354,9 @@ const ATLAS_LIGHTING_FRAG = [353
].join("\n");354
].join("\n");354
355
355
/**356
/**356
* Block-row atlas: optional magenta → sample center crop of the ground atlas357
* Block-row atlas: magenta → sample the ground atlas (u_bump) at the same357
* (bound as u_bump). Used so cliff tops show the ground the wall sits on.358
* tile-local UV (1:1 scale). The ground atlas already includes soft-terrain359
* blending when that preference is on, so cliff tops match the floor beneath.358
* Darkness matches ATLAS_LIGHTING_FRAG (lightmap in u_secondary).360
* Darkness matches ATLAS_LIGHTING_FRAG (lightmap in u_secondary).359
*/361
*/360
const ATLAS_BLOCK_GROUND_TOP_FRAG = [362
const ATLAS_BLOCK_GROUND_TOP_FRAG = [@@ -370,17 +372,14 @@ const ATLAS_BLOCK_GROUND_TOP_FRAG = [370
" vec4 color = texture2D(u_texture, v_texCoord);",372
" vec4 color = texture2D(u_texture, v_texCoord);",371
" if (color.a <= 0.0) { discard; }",373
" if (color.a <= 0.0) { discard; }",372
" vec3 rgb = color.rgb;",374
" vec3 rgb = color.rgb;",373
" // Magenta family (R≈B, G<R): replace with ground tile center crop.",375
" // Magenta family (R≈B, G<R): replace with blended ground under this pixel.",374
" float rbDiff = abs(rgb.r - rgb.b);",376
" float rbDiff = abs(rgb.r - rgb.b);",375
" if (rbDiff < 0.02 && rgb.g < rgb.r - 0.02) {",377
" if (rbDiff < 0.02 && rgb.g < rgb.r - 0.02) {",376
" float tileX = floor(v_texCoord.x * 16.0);",378
" float tileX = floor(v_texCoord.x * 16.0);",377
" float tileY = max(u_lightRow, 0.0);",379
" float tileY = max(u_lightRow, 0.0);",378
" float localX = fract(v_texCoord.x * 16.0);",380
" float localX = fract(v_texCoord.x * 16.0);",379
" float localY = v_texCoord.y;",381
" float localY = v_texCoord.y;",380
" vec2 groundUV = vec2(",382
" vec2 groundUV = vec2((tileX + localX) / 16.0, (tileY + localY) / 16.0);",381
" (tileX + 0.25 + localX * 0.5) / 16.0,",382
" (tileY + 0.25 + localY * 0.5) / 16.0",383
" );",384
" rgb = texture2D(u_bump, groundUV).rgb;",383
" rgb = texture2D(u_bump, groundUV).rgb;",385
" }",384
" }",386
" vec2 lightUV = v_texCoord;",385
" vec2 lightUV = v_texCoord;",