Lock nature tint values and soft-blend across chunk edges.
Bake an 18×18 noise halo so bilinear sampling matches neighbor tiles, remove the debug panel, and ship the playtested scale/contrast/tint/darken.
@@ -38,7 +38,6 @@ import { bindHairControls } from "./hairControls.js";
38
38
import { bindCreateClothingControls } from "./createClothingControls.js";
39
39
import { paintCharacterPreview } from "./characterPreview.js";
40
40
import { initGraphicsSettings } from "./graphicsSettings.js";
41
import { initNatureTintDebugPanel } from "./natureTintDebug.js";
42
41
import { CraftingStationId } from "/shared/definitions/craftingStations.js";
43
42
import { isOreBoulderState } from "/shared/definitions/materialTiers.js";
44
43
import { formatQuantity } from "/shared/items/formatQuantity.js";
@@ -1832,13 +1831,6 @@ async function main ()
1832
1831
onChange: applyGraphicsSettings,
1833
1832
onSuppressWorldClick: consumeWorldClick
1834
1833
});
1835
initNatureTintDebugPanel({
1836
onChange ({ rebuildNoise })
1837
{
1838
if (rebuildNoise)
1839
{ view?.refreshNatureNoise?.(); }
1840
}
1841
});
1842
1834
social = initSocial({
1843
1835
socket: { send (payload) { socket.send(payload); } },
1844
1836
MessageType,
@@ -38,7 +38,6 @@ import { bindHairControls } from "./hairControls.js";38
import { bindCreateClothingControls } from "./createClothingControls.js";38
import { bindCreateClothingControls } from "./createClothingControls.js";39
import { paintCharacterPreview } from "./characterPreview.js";39
import { paintCharacterPreview } from "./characterPreview.js";40
import { initGraphicsSettings } from "./graphicsSettings.js";40
import { initGraphicsSettings } from "./graphicsSettings.js";41
import { initNatureTintDebugPanel } from "./natureTintDebug.js";42
import { CraftingStationId } from "/shared/definitions/craftingStations.js";41
import { CraftingStationId } from "/shared/definitions/craftingStations.js";43
import { isOreBoulderState } from "/shared/definitions/materialTiers.js";42
import { isOreBoulderState } from "/shared/definitions/materialTiers.js";44
import { formatQuantity } from "/shared/items/formatQuantity.js";43
import { formatQuantity } from "/shared/items/formatQuantity.js";@@ -1832,13 +1831,6 @@ async function main ()1832
onChange: applyGraphicsSettings,1831
onChange: applyGraphicsSettings,1833
onSuppressWorldClick: consumeWorldClick1832
onSuppressWorldClick: consumeWorldClick1834
});1833
});1835
initNatureTintDebugPanel({1836
onChange ({ rebuildNoise })1837
{1838
if (rebuildNoise)1839
{ view?.refreshNatureNoise?.(); }1840
}1841
});1842
social = initSocial({1834
social = initSocial({1843
socket: { send (payload) { socket.send(payload); } },1835
socket: { send (payload) { socket.send(payload); } },1844
MessageType,1836
MessageType,@@ -1,166 +0,0 @@
1
/**
2
* Temporary always-on nature tint debug panel (blendable “nature” grounds).
3
*/
4
5
export const DEFAULT_NATURE_TINT = Object.freeze({
6
/** World-space noise frequency (tiles). */
7
scale: 0.08,
8
/** 0..1 how hard to reshape noise around mid-grey. */
9
contrast: 1,
10
/** Warm/cool recolor strength (0 = none, 1 = full cool↔warm). */
11
tint: 0.35,
12
/** Brightness variation strength. */
13
darken: 0.08
14
});
15
16
const SLIDERS = [
17
{ key: "scale", label: "Noise scale", min: 0.01, max: 0.4, step: 0.005 },
18
{ key: "contrast", label: "Contrast", min: 0.4, max: 2.5, step: 0.05 },
19
{ key: "tint", label: "Tint", min: 0, max: 1, step: 0.01 },
20
{ key: "darken", label: "Darken", min: 0, max: 0.4, step: 0.01 }
21
];
22
23
let params = { ...DEFAULT_NATURE_TINT };
24
let panelEl = null;
25
let onChange = null;
26
27
export function getNatureTintParams ()
28
{
29
return { ...params };
30
}
31
32
/** Shader uniforms for atlas nature tint (ground only). */
33
export function natureTintUniforms ()
34
{
35
const p = params;
36
return {
37
u_useNature: 1,
38
u_natureTint: p.tint,
39
u_natureDark: p.darken,
40
u_natureContrast: p.contrast
41
};
42
}
43
44
export function setNatureTintParams (next)
45
{
46
const prevScale = params.scale;
47
params = { ...DEFAULT_NATURE_TINT, ...params, ...next };
48
syncInputs();
49
onChange?.({
50
rebuildNoise: params.scale !== prevScale || next?.scale != null
51
});
52
}
53
54
function syncInputs ()
55
{
56
if (!panelEl)
57
{ return; }
58
for (const { key } of SLIDERS)
59
{
60
const input = panelEl.querySelector(`input[data-nature-key="${key}"]`);
61
const valueEl = panelEl.querySelector(`[data-nature-value="${key}"]`);
62
if (input)
63
{ input.value = String(params[key]); }
64
if (valueEl)
65
{ valueEl.textContent = Number(params[key]).toFixed(3); }
66
}
67
}
68
69
/**
70
* @param {{ onChange?: (info: { rebuildNoise: boolean }) => void }} [opts]
71
*/
72
export function initNatureTintDebugPanel (opts = {})
73
{
74
if (panelEl)
75
{ return panelEl; }
76
onChange = opts.onChange ?? null;
77
78
panelEl = document.createElement("aside");
79
panelEl.id = "nature-tint-debug-panel";
80
panelEl.innerHTML = `
81
<header style="display:flex;align-items:center;gap:8px;">
82
<strong>Nature tint</strong>
83
</header>
84
<div class="nature-tint-scroll"></div>
85
<footer style="display:flex;gap:6px;">
86
<button type="button" data-nature-reset>Reset</button>
87
</footer>
88
`;
89
Object.assign(panelEl.style, {
90
position: "fixed",
91
top: "8px",
92
right: "8px",
93
width: "240px",
94
zIndex: "9999",
95
display: "flex",
96
flexDirection: "column",
97
gap: "4px",
98
padding: "8px",
99
background: "rgba(12, 16, 22, 0.92)",
100
color: "#e8eef5",
101
font: "11px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
102
border: "1px solid rgba(255,255,255,0.18)",
103
borderRadius: "6px",
104
boxShadow: "0 8px 24px rgba(0,0,0,0.45)",
105
pointerEvents: "auto"
106
});
107
108
const scroll = panelEl.querySelector(".nature-tint-scroll");
109
Object.assign(scroll.style, {
110
display: "flex",
111
flexDirection: "column",
112
gap: "3px"
113
});
114
115
for (const spec of SLIDERS)
116
{
117
const row = document.createElement("label");
118
row.style.cssText = "display:grid;grid-template-columns:1fr 48px;gap:2px 6px;align-items:center;";
119
row.innerHTML = `
120
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>
121
<input type="range" data-nature-key="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${params[spec.key]}">
122
<span data-nature-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(params[spec.key]).toFixed(3)}</span>
123
`;
124
const input = row.querySelector("input");
125
input.addEventListener("input", () =>
126
{
127
const prevScale = params.scale;
128
params[spec.key] = Number(input.value);
129
const valueEl = row.querySelector(`[data-nature-value="${spec.key}"]`);
130
if (valueEl)
131
{ valueEl.textContent = Number(params[spec.key]).toFixed(3); }
132
onChange?.({ rebuildNoise: spec.key === "scale" && params.scale !== prevScale });
133
});
134
scroll.appendChild(row);
135
}
136
137
const resetBtn = panelEl.querySelector("[data-nature-reset]");
138
Object.assign(resetBtn.style, {
139
background: "transparent",
140
color: "inherit",
141
border: "1px solid rgba(255,255,255,0.22)",
142
borderRadius: "4px",
143
padding: "3px 8px",
144
cursor: "pointer",
145
font: "inherit"
146
});
147
resetBtn.addEventListener("click", (event) =>
148
{
149
event.preventDefault();
150
event.stopPropagation();
151
params = { ...DEFAULT_NATURE_TINT };
152
syncInputs();
153
onChange?.({ rebuildNoise: true });
154
});
155
156
for (const type of ["mousedown", "mouseup", "click", "wheel", "contextmenu", "pointerdown"])
157
{
158
panelEl.addEventListener(type, (event) =>
159
{
160
event.stopPropagation();
161
});
162
}
163
164
document.body.appendChild(panelEl);
165
return panelEl;
166
}
@@ -1,166 +0,0 @@1
/**2
* Temporary always-on nature tint debug panel (blendable “nature” grounds).3
*/4
5
export const DEFAULT_NATURE_TINT = Object.freeze({6
/** World-space noise frequency (tiles). */7
scale: 0.08,8
/** 0..1 how hard to reshape noise around mid-grey. */9
contrast: 1,10
/** Warm/cool recolor strength (0 = none, 1 = full cool↔warm). */11
tint: 0.35,12
/** Brightness variation strength. */13
darken: 0.0814
});15
16
const SLIDERS = [17
{ key: "scale", label: "Noise scale", min: 0.01, max: 0.4, step: 0.005 },18
{ key: "contrast", label: "Contrast", min: 0.4, max: 2.5, step: 0.05 },19
{ key: "tint", label: "Tint", min: 0, max: 1, step: 0.01 },20
{ key: "darken", label: "Darken", min: 0, max: 0.4, step: 0.01 }21
];22
23
let params = { ...DEFAULT_NATURE_TINT };24
let panelEl = null;25
let onChange = null;26
27
export function getNatureTintParams ()28
{29
return { ...params };30
}31
32
/** Shader uniforms for atlas nature tint (ground only). */33
export function natureTintUniforms ()34
{35
const p = params;36
return {37
u_useNature: 1,38
u_natureTint: p.tint,39
u_natureDark: p.darken,40
u_natureContrast: p.contrast41
};42
}43
44
export function setNatureTintParams (next)45
{46
const prevScale = params.scale;47
params = { ...DEFAULT_NATURE_TINT, ...params, ...next };48
syncInputs();49
onChange?.({50
rebuildNoise: params.scale !== prevScale || next?.scale != null51
});52
}53
54
function syncInputs ()55
{56
if (!panelEl)57
{ return; }58
for (const { key } of SLIDERS)59
{60
const input = panelEl.querySelector(`input[data-nature-key="${key}"]`);61
const valueEl = panelEl.querySelector(`[data-nature-value="${key}"]`);62
if (input)63
{ input.value = String(params[key]); }64
if (valueEl)65
{ valueEl.textContent = Number(params[key]).toFixed(3); }66
}67
}68
69
/**70
* @param {{ onChange?: (info: { rebuildNoise: boolean }) => void }} [opts]71
*/72
export function initNatureTintDebugPanel (opts = {})73
{74
if (panelEl)75
{ return panelEl; }76
onChange = opts.onChange ?? null;77
78
panelEl = document.createElement("aside");79
panelEl.id = "nature-tint-debug-panel";80
panelEl.innerHTML = `81
<header style="display:flex;align-items:center;gap:8px;">82
<strong>Nature tint</strong>83
</header>84
<div class="nature-tint-scroll"></div>85
<footer style="display:flex;gap:6px;">86
<button type="button" data-nature-reset>Reset</button>87
</footer>88
`;89
Object.assign(panelEl.style, {90
position: "fixed",91
top: "8px",92
right: "8px",93
width: "240px",94
zIndex: "9999",95
display: "flex",96
flexDirection: "column",97
gap: "4px",98
padding: "8px",99
background: "rgba(12, 16, 22, 0.92)",100
color: "#e8eef5",101
font: "11px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",102
border: "1px solid rgba(255,255,255,0.18)",103
borderRadius: "6px",104
boxShadow: "0 8px 24px rgba(0,0,0,0.45)",105
pointerEvents: "auto"106
});107
108
const scroll = panelEl.querySelector(".nature-tint-scroll");109
Object.assign(scroll.style, {110
display: "flex",111
flexDirection: "column",112
gap: "3px"113
});114
115
for (const spec of SLIDERS)116
{117
const row = document.createElement("label");118
row.style.cssText = "display:grid;grid-template-columns:1fr 48px;gap:2px 6px;align-items:center;";119
row.innerHTML = `120
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>121
<input type="range" data-nature-key="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${params[spec.key]}">122
<span data-nature-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(params[spec.key]).toFixed(3)}</span>123
`;124
const input = row.querySelector("input");125
input.addEventListener("input", () =>126
{127
const prevScale = params.scale;128
params[spec.key] = Number(input.value);129
const valueEl = row.querySelector(`[data-nature-value="${spec.key}"]`);130
if (valueEl)131
{ valueEl.textContent = Number(params[spec.key]).toFixed(3); }132
onChange?.({ rebuildNoise: spec.key === "scale" && params.scale !== prevScale });133
});134
scroll.appendChild(row);135
}136
137
const resetBtn = panelEl.querySelector("[data-nature-reset]");138
Object.assign(resetBtn.style, {139
background: "transparent",140
color: "inherit",141
border: "1px solid rgba(255,255,255,0.22)",142
borderRadius: "4px",143
padding: "3px 8px",144
cursor: "pointer",145
font: "inherit"146
});147
resetBtn.addEventListener("click", (event) =>148
{149
event.preventDefault();150
event.stopPropagation();151
params = { ...DEFAULT_NATURE_TINT };152
syncInputs();153
onChange?.({ rebuildNoise: true });154
});155
156
for (const type of ["mousedown", "mouseup", "click", "wheel", "contextmenu", "pointerdown"])157
{158
panelEl.addEventListener(type, (event) =>159
{160
event.stopPropagation();161
});162
}163
164
document.body.appendChild(panelEl);165
return panelEl;166
}@@ -28,8 +28,7 @@ import
28
28
} from "./canvasSprite.js";
29
29
import { setNearestFilter } from "./sprites.js";
30
30
import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";
31
import { getNatureTintParams, natureTintUniforms } from "../play/natureTintDebug.js";
32
import { natureNoise01 } from "/shared/render/natureNoise.js";
31
import { natureNoise01, natureTintUniforms, NATURE_TINT, NATURE_NOISE_SIZE, NATURE_NOISE_PAD } from "/shared/render/natureNoise.js";
33
32
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";
34
33
import
35
34
{
@@ -889,15 +888,15 @@ const ATLAS_LIGHTING_FRAG = [
889
888
" if (color.a <= 0.0) { discard; }",
890
889
" vec3 rgb = color.rgb;",
891
890
" if (u_useNature > 0.5) {",
892
// Soft bilinear over the 16×16 noise (textures are NEAREST globally).
891
// Soft bilinear over 18×18 noise (1-tile halo) so blend crosses chunk edges.
893
892
" vec2 texel = v_texCoord * 16.0 - 0.5;",
894
893
" vec2 i0 = floor(texel);",
895
894
" vec2 f = fract(texel);",
896
895
" vec2 i1 = i0 + 1.0;",
897
" vec2 c00 = (clamp(i0, 0.0, 15.0) + 0.5) / 16.0;",
898
" vec2 c10 = (clamp(vec2(i1.x, i0.y), 0.0, 15.0) + 0.5) / 16.0;",
899
" vec2 c01 = (clamp(vec2(i0.x, i1.y), 0.0, 15.0) + 0.5) / 16.0;",
900
" vec2 c11 = (clamp(i1, 0.0, 15.0) + 0.5) / 16.0;",
896
" vec2 c00 = (i0 + 1.5) / 18.0;",
897
" vec2 c10 = (vec2(i1.x, i0.y) + 1.5) / 18.0;",
898
" vec2 c01 = (vec2(i0.x, i1.y) + 1.5) / 18.0;",
899
" vec2 c11 = (i1 + 1.5) / 18.0;",
901
900
" vec4 s00 = texture2D(u_bump, c00);",
902
901
" vec4 s10 = texture2D(u_bump, c10);",
903
902
" vec4 s01 = texture2D(u_bump, c01);",
@@ -4729,7 +4728,6 @@ export class WorldView
4729
4728
chunkX: snapshot.chunkX,
4730
4729
chunkY: snapshot.chunkY
4731
4730
};
4732
this.#fillNatureNoise(baked, snapshot);
4733
4731
baked.groundObject = new GameObject(0, 0, baked.groundImage, LAYER_GROUND);
4734
4732
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage);
4735
4733
this.scene.addObject(baked.groundObject);
@@ -4755,7 +4753,6 @@ export class WorldView
4755
4753
baked.natureCanvas = makeNatureNoiseCanvas();
4756
4754
baked.natureImage = frameworkImageFromCanvas(baked.natureCanvas);
4757
4755
}
4758
this.#fillNatureNoise(baked, snapshot);
4759
4756
if (baked.groundCanvas !== atlases.ground)
4760
4757
{
4761
4758
baked.groundCanvas = atlases.ground;
@@ -4790,6 +4787,7 @@ export class WorldView
4790
4787
}
4791
4788
baked.chunkX = snapshot.chunkX;
4792
4789
baked.chunkY = snapshot.chunkY;
4790
this.#refreshNatureNoiseAround(snapshot.chunkX, snapshot.chunkY);
4793
4791
baked.lightmapCacheKey = null;
4794
4792
this.#invalidateNeighborLightmapCaches(snapshot.chunkX, snapshot.chunkY);
4795
4793
this.#layoutBakedChunk(snapshot);
@@ -4894,17 +4892,23 @@ export class WorldView
4894
4892
};
4895
4893
}
4896
4894
4897
/** Rebuild 16×16 nature noise for every loaded chunk (e.g. debug scale change). */
4898
refreshNatureNoise ()
4895
/** Rebuild nature noise for a chunk and neighbors (halo needs adjacent grounds). */
4896
#refreshNatureNoiseAround (chunkX, chunkY)
4899
4897
{
4900
for (const baked of this.bakedChunks.values())
4898
for (let dy = -1; dy <= 1; dy++)
4901
4899
{
4902
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);
4903
if (!snapshot || !baked.natureCanvas)
4904
{ continue; }
4905
this.#fillNatureNoise(baked, snapshot);
4906
if (baked.groundObject)
4907
{ this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage); }
4900
for (let dx = -1; dx <= 1; dx++)
4901
{
4902
const cx = chunkX + dx;
4903
const cy = chunkY + dy;
4904
const baked = this.bakedChunks.get(`${cx},${cy}`);
4905
const snapshot = this.chunks.get(`${cx},${cy}`);
4906
if (!baked?.natureCanvas || !snapshot)
4907
{ continue; }
4908
this.#fillNatureNoise(baked, snapshot);
4909
if (baked.groundObject)
4910
{ this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage); }
4911
}
4908
4912
}
4909
4913
}
4910
4914
@@ -4912,21 +4916,31 @@ export class WorldView
4912
4916
{
4913
4917
if (!baked?.natureCanvas || !snapshot)
4914
4918
{ return; }
4915
const scale = getNatureTintParams().scale;
4916
const ctx = baked.natureCanvas.getContext("2d");
4917
const image = ctx.createImageData(CHUNK_SIZE, CHUNK_SIZE);
4918
const grounds = snapshot.grounds;
4919
const canvas = baked.natureCanvas;
4920
if (canvas.width !== NATURE_NOISE_SIZE || canvas.height !== NATURE_NOISE_SIZE)
4921
{
4922
canvas.width = NATURE_NOISE_SIZE;
4923
canvas.height = NATURE_NOISE_SIZE;
4924
}
4925
const scale = NATURE_TINT.scale;
4926
const ctx = canvas.getContext("2d");
4927
const image = ctx.createImageData(NATURE_NOISE_SIZE, NATURE_NOISE_SIZE);
4919
4928
const baseX = snapshot.chunkX * CHUNK_SIZE;
4920
4929
const baseY = snapshot.chunkY * CHUNK_SIZE;
4921
for (let ly = 0; ly < CHUNK_SIZE; ly++)
4930
const pad = NATURE_NOISE_PAD;
4931
for (let py = 0; py < NATURE_NOISE_SIZE; py++)
4922
4932
{
4923
for (let lx = 0; lx < CHUNK_SIZE; lx++)
4933
for (let px = 0; px < NATURE_NOISE_SIZE; px++)
4924
4934
{
4925
const index = ly * CHUNK_SIZE + lx;
4926
const ground = normalizeGround(grounds?.[index]);
4927
const blendable = !!GROUND_DEFINITIONS[ground.typeId]?.blendable;
4928
const n = natureNoise01(baseX + lx, baseY + ly, scale);
4929
const i = index * 4;
4935
const lx = px - pad;
4936
const ly = py - pad;
4937
const worldX = baseX + lx;
4938
const worldY = baseY + ly;
4939
const ground = this.#groundAtTile(worldX, worldY);
4940
const typeId = ground == null ? null : normalizeGround(ground).typeId;
4941
const blendable = typeId != null && !!GROUND_DEFINITIONS[typeId]?.blendable;
4942
const n = natureNoise01(worldX, worldY, scale);
4943
const i = (py * NATURE_NOISE_SIZE + px) * 4;
4930
4944
const v = Math.round(n * 255);
4931
4945
image.data[i] = v;
4932
4946
image.data[i + 1] = v;
@@ -6129,8 +6143,8 @@ function makeLightmapCanvas (size)
6129
6143
function makeNatureNoiseCanvas ()
6130
6144
{
6131
6145
const canvas = document.createElement("canvas");
6132
canvas.width = CHUNK_SIZE;
6133
canvas.height = CHUNK_SIZE;
6146
canvas.width = NATURE_NOISE_SIZE;
6147
canvas.height = NATURE_NOISE_SIZE;
6134
6148
return canvas;
6135
6149
}
6136
6150
@@ -28,8 +28,7 @@ import28
} from "./canvasSprite.js";28
} from "./canvasSprite.js";29
import { setNearestFilter } from "./sprites.js";29
import { setNearestFilter } from "./sprites.js";30
import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";30
import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";31
import { getNatureTintParams, natureTintUniforms } from "../play/natureTintDebug.js";31
import { natureNoise01, natureTintUniforms, NATURE_TINT, NATURE_NOISE_SIZE, NATURE_NOISE_PAD } from "/shared/render/natureNoise.js";32
import { natureNoise01 } from "/shared/render/natureNoise.js";33
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";32
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";34
import33
import35
{34
{@@ -889,15 +888,15 @@ const ATLAS_LIGHTING_FRAG = [889
" if (color.a <= 0.0) { discard; }",888
" if (color.a <= 0.0) { discard; }",890
" vec3 rgb = color.rgb;",889
" vec3 rgb = color.rgb;",891
" if (u_useNature > 0.5) {",890
" if (u_useNature > 0.5) {",892
// Soft bilinear over the 16×16 noise (textures are NEAREST globally).891
// Soft bilinear over 18×18 noise (1-tile halo) so blend crosses chunk edges.893
" vec2 texel = v_texCoord * 16.0 - 0.5;",892
" vec2 texel = v_texCoord * 16.0 - 0.5;",894
" vec2 i0 = floor(texel);",893
" vec2 i0 = floor(texel);",895
" vec2 f = fract(texel);",894
" vec2 f = fract(texel);",896
" vec2 i1 = i0 + 1.0;",895
" vec2 i1 = i0 + 1.0;",897
" vec2 c00 = (clamp(i0, 0.0, 15.0) + 0.5) / 16.0;",896
" vec2 c00 = (i0 + 1.5) / 18.0;",898
" vec2 c10 = (clamp(vec2(i1.x, i0.y), 0.0, 15.0) + 0.5) / 16.0;",897
" vec2 c10 = (vec2(i1.x, i0.y) + 1.5) / 18.0;",899
" vec2 c01 = (clamp(vec2(i0.x, i1.y), 0.0, 15.0) + 0.5) / 16.0;",898
" vec2 c01 = (vec2(i0.x, i1.y) + 1.5) / 18.0;",900
" vec2 c11 = (clamp(i1, 0.0, 15.0) + 0.5) / 16.0;",899
" vec2 c11 = (i1 + 1.5) / 18.0;",901
" vec4 s00 = texture2D(u_bump, c00);",900
" vec4 s00 = texture2D(u_bump, c00);",902
" vec4 s10 = texture2D(u_bump, c10);",901
" vec4 s10 = texture2D(u_bump, c10);",903
" vec4 s01 = texture2D(u_bump, c01);",902
" vec4 s01 = texture2D(u_bump, c01);",@@ -4729,7 +4728,6 @@ export class WorldView4729
chunkX: snapshot.chunkX,4728
chunkX: snapshot.chunkX,4730
chunkY: snapshot.chunkY4729
chunkY: snapshot.chunkY4731
};4730
};4732
this.#fillNatureNoise(baked, snapshot);4733
baked.groundObject = new GameObject(0, 0, baked.groundImage, LAYER_GROUND);4731
baked.groundObject = new GameObject(0, 0, baked.groundImage, LAYER_GROUND);4734
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage);4732
this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage);4735
this.scene.addObject(baked.groundObject);4733
this.scene.addObject(baked.groundObject);@@ -4755,7 +4753,6 @@ export class WorldView4755
baked.natureCanvas = makeNatureNoiseCanvas();4753
baked.natureCanvas = makeNatureNoiseCanvas();4756
baked.natureImage = frameworkImageFromCanvas(baked.natureCanvas);4754
baked.natureImage = frameworkImageFromCanvas(baked.natureCanvas);4757
}4755
}4758
this.#fillNatureNoise(baked, snapshot);4759
if (baked.groundCanvas !== atlases.ground)4756
if (baked.groundCanvas !== atlases.ground)4760
{4757
{4761
baked.groundCanvas = atlases.ground;4758
baked.groundCanvas = atlases.ground;@@ -4790,6 +4787,7 @@ export class WorldView4790
}4787
}4791
baked.chunkX = snapshot.chunkX;4788
baked.chunkX = snapshot.chunkX;4792
baked.chunkY = snapshot.chunkY;4789
baked.chunkY = snapshot.chunkY;4790
this.#refreshNatureNoiseAround(snapshot.chunkX, snapshot.chunkY);4793
baked.lightmapCacheKey = null;4791
baked.lightmapCacheKey = null;4794
this.#invalidateNeighborLightmapCaches(snapshot.chunkX, snapshot.chunkY);4792
this.#invalidateNeighborLightmapCaches(snapshot.chunkX, snapshot.chunkY);4795
this.#layoutBakedChunk(snapshot);4793
this.#layoutBakedChunk(snapshot);@@ -4894,17 +4892,23 @@ export class WorldView4894
};4892
};4895
}4893
}4896
4894
4897
/** Rebuild 16×16 nature noise for every loaded chunk (e.g. debug scale change). */4895
/** Rebuild nature noise for a chunk and neighbors (halo needs adjacent grounds). */4898
refreshNatureNoise ()4896
#refreshNatureNoiseAround (chunkX, chunkY)4899
{4897
{4900
for (const baked of this.bakedChunks.values())4898
for (let dy = -1; dy <= 1; dy++)4901
{4899
{4902
const snapshot = this.chunks.get(`${baked.chunkX},${baked.chunkY}`);4900
for (let dx = -1; dx <= 1; dx++)4903
if (!snapshot || !baked.natureCanvas)4901
{4904
{ continue; }4902
const cx = chunkX + dx;4905
this.#fillNatureNoise(baked, snapshot);4903
const cy = chunkY + dy;4906
if (baked.groundObject)4904
const baked = this.bakedChunks.get(`${cx},${cy}`);4907
{ this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage); }4905
const snapshot = this.chunks.get(`${cx},${cy}`);4906
if (!baked?.natureCanvas || !snapshot)4907
{ continue; }4908
this.#fillNatureNoise(baked, snapshot);4909
if (baked.groundObject)4910
{ this.#applyAtlasLighting(baked.groundObject, baked.lightmapImage, -1, baked.natureImage); }4911
}4908
}4912
}4909
}4913
}4910
4914
@@ -4912,21 +4916,31 @@ export class WorldView4912
{4916
{4913
if (!baked?.natureCanvas || !snapshot)4917
if (!baked?.natureCanvas || !snapshot)4914
{ return; }4918
{ return; }4915
const scale = getNatureTintParams().scale;4919
const canvas = baked.natureCanvas;4916
const ctx = baked.natureCanvas.getContext("2d");4920
if (canvas.width !== NATURE_NOISE_SIZE || canvas.height !== NATURE_NOISE_SIZE)4917
const image = ctx.createImageData(CHUNK_SIZE, CHUNK_SIZE);4921
{4918
const grounds = snapshot.grounds;4922
canvas.width = NATURE_NOISE_SIZE;4923
canvas.height = NATURE_NOISE_SIZE;4924
}4925
const scale = NATURE_TINT.scale;4926
const ctx = canvas.getContext("2d");4927
const image = ctx.createImageData(NATURE_NOISE_SIZE, NATURE_NOISE_SIZE);4919
const baseX = snapshot.chunkX * CHUNK_SIZE;4928
const baseX = snapshot.chunkX * CHUNK_SIZE;4920
const baseY = snapshot.chunkY * CHUNK_SIZE;4929
const baseY = snapshot.chunkY * CHUNK_SIZE;4921
for (let ly = 0; ly < CHUNK_SIZE; ly++)4930
const pad = NATURE_NOISE_PAD;4931
for (let py = 0; py < NATURE_NOISE_SIZE; py++)4922
{4932
{4923
for (let lx = 0; lx < CHUNK_SIZE; lx++)4933
for (let px = 0; px < NATURE_NOISE_SIZE; px++)4924
{4934
{4925
const index = ly * CHUNK_SIZE + lx;4935
const lx = px - pad;4926
const ground = normalizeGround(grounds?.[index]);4936
const ly = py - pad;4927
const blendable = !!GROUND_DEFINITIONS[ground.typeId]?.blendable;4937
const worldX = baseX + lx;4928
const n = natureNoise01(baseX + lx, baseY + ly, scale);4938
const worldY = baseY + ly;4929
const i = index * 4;4939
const ground = this.#groundAtTile(worldX, worldY);4940
const typeId = ground == null ? null : normalizeGround(ground).typeId;4941
const blendable = typeId != null && !!GROUND_DEFINITIONS[typeId]?.blendable;4942
const n = natureNoise01(worldX, worldY, scale);4943
const i = (py * NATURE_NOISE_SIZE + px) * 4;4930
const v = Math.round(n * 255);4944
const v = Math.round(n * 255);4931
image.data[i] = v;4945
image.data[i] = v;4932
image.data[i + 1] = v;4946
image.data[i + 1] = v;@@ -6129,8 +6143,8 @@ function makeLightmapCanvas (size)6129
function makeNatureNoiseCanvas ()6143
function makeNatureNoiseCanvas ()6130
{6144
{6131
const canvas = document.createElement("canvas");6145
const canvas = document.createElement("canvas");6132
canvas.width = CHUNK_SIZE;6146
canvas.width = NATURE_NOISE_SIZE;6133
canvas.height = CHUNK_SIZE;6147
canvas.height = NATURE_NOISE_SIZE;6134
return canvas;6148
return canvas;6135
}6149
}6136
6150
@@ -1,11 +1,11 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
import { natureNoise01, perlin2 } from "../../shared/render/natureNoise.js";
3
import { natureNoise01, perlin2, NATURE_TINT, NATURE_NOISE_SIZE } from "../../shared/render/natureNoise.js";
4
4
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
5
5
6
6
test("nature noise is continuous across chunk borders", () =>
7
7
{
8
const scale = 0.08;
8
const scale = NATURE_TINT.scale;
9
9
const a = natureNoise01(CHUNK_SIZE - 1, 5, scale);
10
10
const b = natureNoise01(CHUNK_SIZE, 5, scale);
11
11
assert.ok(Math.abs(a - b) < 0.25, `border jump too large: ${a} vs ${b}`);
@@ -14,6 +14,11 @@ test("nature noise is continuous across chunk borders", () =>
14
14
test("perlin is deterministic and bounded", () =>
15
15
{
16
16
assert.equal(perlin2(1.5, 2.5), perlin2(1.5, 2.5));
17
const n = natureNoise01(12, 34, 0.1);
17
const n = natureNoise01(12, 34, NATURE_TINT.scale);
18
18
assert.ok(n >= 0 && n <= 1);
19
19
});
20
21
test("nature noise texture includes a one-tile halo", () =>
22
{
23
assert.equal(NATURE_NOISE_SIZE, CHUNK_SIZE + 2);
24
});
@@ -1,11 +1,11 @@1
import test from "node:test";1
import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { natureNoise01, perlin2 } from "../../shared/render/natureNoise.js";3
import { natureNoise01, perlin2, NATURE_TINT, NATURE_NOISE_SIZE } from "../../shared/render/natureNoise.js";4
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";4
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";5
5
6
test("nature noise is continuous across chunk borders", () =>6
test("nature noise is continuous across chunk borders", () =>7
{7
{8
const scale = 0.08;8
const scale = NATURE_TINT.scale;9
const a = natureNoise01(CHUNK_SIZE - 1, 5, scale);9
const a = natureNoise01(CHUNK_SIZE - 1, 5, scale);10
const b = natureNoise01(CHUNK_SIZE, 5, scale);10
const b = natureNoise01(CHUNK_SIZE, 5, scale);11
assert.ok(Math.abs(a - b) < 0.25, `border jump too large: ${a} vs ${b}`);11
assert.ok(Math.abs(a - b) < 0.25, `border jump too large: ${a} vs ${b}`);@@ -14,6 +14,11 @@ test("nature noise is continuous across chunk borders", () =>14
test("perlin is deterministic and bounded", () =>14
test("perlin is deterministic and bounded", () =>15
{15
{16
assert.equal(perlin2(1.5, 2.5), perlin2(1.5, 2.5));16
assert.equal(perlin2(1.5, 2.5), perlin2(1.5, 2.5));17
const n = natureNoise01(12, 34, 0.1);17
const n = natureNoise01(12, 34, NATURE_TINT.scale);18
assert.ok(n >= 0 && n <= 1);18
assert.ok(n >= 0 && n <= 1);19
});19
});20
21
test("nature noise texture includes a one-tile halo", () =>22
{23
assert.equal(NATURE_NOISE_SIZE, CHUNK_SIZE + 2);24
});