Add lava ground with heat shader and lock water-debug defaults.
Lava is impassable, emits half-torch light, and uses a dark-red→yellow FBM shader with yellow-driven bloom. Water defaults come from water-debug.json; deep water darkens more abruptly with a Deep darker slider in the compact Water/Lava debug tabs.
The contents of this binary file are not shown.
@@ -1,86 +1,129 @@
1
1
/**
2
* Temporary always-on water shader debug panel (simplex FBM tune).
2
* Temporary always-on fluid shader debug panel (water + lava tabs).
3
3
* Export JSON when you land on values you like.
4
4
*/
5
5
6
6
export const DEFAULT_WATER_DEBUG = Object.freeze({
7
flowX: 0.33,
8
flowY: 0.21,
9
flowZ: 0.52,
10
waveScale: 0.85,
11
fbmAmp: 0.75,
12
texAmp: 0.18,
13
distort: 0.14,
14
normalZ: 0.9,
15
waveGain: 0.42,
16
crestLo: 0.72,
17
crestHi: 0.96,
18
crestPow: 2.2,
7
flowX: 0.17,
8
flowY: 0.05,
9
flowZ: 0.91,
10
waveScale: 2.07,
11
fbmAmp: 0.15,
12
texAmp: 0.43,
13
distort: 0.09,
14
normalZ: 0.88,
15
waveGain: 0.62,
16
crestLo: 0.54,
17
crestHi: 0.67,
18
crestPow: 2.05,
19
glitterPow: 13.1,
20
crestGlitter: 1.3,
21
glitterCap: 1,
22
glitterMix: 1.24,
23
shadeLo: 1.06,
24
shadeHi: 1,
25
bodyLo: 0.41,
26
bodyHi: 0.85,
27
litLo: 0.5,
28
litHi: 0.86,
29
litMix: 0.46,
30
edgeDark: 0.37,
31
lightDirX: -0.48,
32
lightDirY: -0.63,
33
lightDirZ: 0.78,
34
normalEps: 0.21,
35
foamStrength: 1,
36
shoreClip: 0.55,
37
/** 0 = baseline deep end; 1 = much darker deep water. */
38
deepDark: 0.4,
39
/** <1 = more abrupt darkening toward deep (pow curve). */
40
deepAbrupt: 0.72
41
});
42
43
export const DEFAULT_LAVA_DEBUG = Object.freeze({
44
flowX: 0.08,
45
flowY: 0.04,
46
flowZ: 0.27,
47
waveScale: 1.83,
48
fbmAmp: 0.43,
49
texAmp: 0.3,
50
distort: 0.3,
51
normalZ: 1.07,
52
waveGain: 0.52,
53
crestLo: 0.57,
54
crestHi: 0.71,
55
crestPow: 1.15,
19
56
glitterPow: 7.5,
20
crestGlitter: 0.55,
21
glitterCap: 0.72,
22
glitterMix: 0.8,
23
shadeLo: 0.9,
24
shadeHi: 1.06,
25
bodyLo: 0.12,
26
bodyHi: 0.72,
27
litLo: 0.52,
28
litHi: 0.9,
29
litMix: 0.4,
30
edgeDark: 0.4,
31
lightDirX: -0.55,
32
lightDirY: -0.5,
33
lightDirZ: 0.75,
34
normalEps: 0.1,
35
foamStrength: 0.95,
36
shoreClip: 0.42
57
crestGlitter: 1.19,
58
glitterCap: 0.31,
59
glitterMix: 0.51,
60
shadeLo: 0.88,
61
shadeHi: 1.07,
62
bodyLo: 0.05,
63
bodyHi: 1,
64
litLo: 0.59,
65
litHi: 0.74,
66
litMix: 1,
67
edgeDark: 1,
68
lightDirX: -0.48,
69
lightDirY: -0.63,
70
lightDirZ: 0.78,
71
normalEps: 0.09,
72
bloomStrength: 0.9
37
73
});
38
74
39
const SLIDERS = [
75
const WATER_SLIDERS = [
40
76
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },
41
77
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },
42
{ key: "flowZ", label: "Flow Z (time)", min: 0, max: 1.5, step: 0.01 },
78
{ key: "flowZ", label: "Flow Z", min: 0, max: 1.5, step: 0.01 },
43
79
{ key: "waveScale", label: "Wave scale", min: 0.2, max: 2.5, step: 0.01 },
44
80
{ key: "fbmAmp", label: "FBM amp", min: 0.1, max: 1.5, step: 0.01 },
45
{ key: "texAmp", label: "Tex amp", min: 0, max: 0.6, step: 0.01 },
46
{ key: "distort", label: "Distort", min: 0, max: 0.5, step: 0.01 },
47
{ key: "normalEps", label: "Normal ε", min: 0.02, max: 0.3, step: 0.01 },
48
{ key: "normalZ", label: "Normal Z", min: 0.3, max: 1.5, step: 0.01 },
49
{ key: "waveGain", label: "Wave gain", min: 0.1, max: 1, step: 0.01 },
50
{ key: "crestLo", label: "Crest lo", min: 0.3, max: 0.95, step: 0.01 },
51
{ key: "crestHi", label: "Crest hi", min: 0.5, max: 1, step: 0.01 },
52
{ key: "crestPow", label: "Crest pow", min: 0.5, max: 5, step: 0.05 },
53
81
{ key: "glitterPow", label: "Glitter pow", min: 1, max: 16, step: 0.1 },
54
{ key: "crestGlitter", label: "Crest glitter", min: 0, max: 1.5, step: 0.01 },
55
{ key: "glitterCap", label: "Glitter cap", min: 0.1, max: 1, step: 0.01 },
56
82
{ key: "glitterMix", label: "Glitter mix", min: 0, max: 1.5, step: 0.01 },
57
{ key: "shadeLo", label: "Shade lo", min: 0.5, max: 1.1, step: 0.01 },
58
{ key: "shadeHi", label: "Shade hi", min: 0.9, max: 1.4, step: 0.01 },
59
83
{ key: "bodyLo", label: "Body lo", min: 0, max: 0.5, step: 0.01 },
60
84
{ key: "bodyHi", label: "Body hi", min: 0.3, max: 1, step: 0.01 },
61
{ key: "litLo", label: "Lit lo", min: 0.2, max: 0.8, step: 0.01 },
62
{ key: "litHi", label: "Lit hi", min: 0.5, max: 1, step: 0.01 },
63
85
{ key: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },
64
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 },
65
{ key: "lightDirX", label: "Light dir X", min: -1, max: 1, step: 0.01 },
66
{ key: "lightDirY", label: "Light dir Y", min: -1, max: 1, step: 0.01 },
67
{ key: "lightDirZ", label: "Light dir Z", min: 0.1, max: 1.5, step: 0.01 },
68
{ key: "foamStrength", label: "Foam strength", min: 0, max: 1, step: 0.01 },
69
{ key: "shoreClip", label: "Shore clip", min: 0.1, max: 0.9, step: 0.01 }
86
{ key: "deepDark", label: "Deep darker", min: 0, max: 1, step: 0.01 },
87
{ key: "deepAbrupt", label: "Deep abrupt", min: 0.35, max: 1.4, step: 0.01 },
88
{ key: "foamStrength", label: "Foam", min: 0, max: 1, step: 0.01 },
89
{ key: "shoreClip", label: "Shore clip", min: 0.1, max: 0.9, step: 0.01 },
90
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }
91
];
92
93
const LAVA_SLIDERS = [
94
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },
95
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },
96
{ key: "flowZ", label: "Flow Z", min: 0, max: 1.5, step: 0.01 },
97
{ key: "waveScale", label: "Wave scale", min: 0.2, max: 2.5, step: 0.01 },
98
{ key: "fbmAmp", label: "FBM amp", min: 0.1, max: 1.5, step: 0.01 },
99
{ key: "distort", label: "Distort", min: 0, max: 0.5, step: 0.01 },
100
{ key: "glitterPow", label: "Heat pow", min: 1, max: 16, step: 0.1 },
101
{ key: "glitterMix", label: "Heat mix", min: 0, max: 1.5, step: 0.01 },
102
{ key: "glitterCap", label: "Heat cap", min: 0.1, max: 1, step: 0.01 },
103
{ key: "bodyLo", label: "Body lo", min: 0, max: 0.5, step: 0.01 },
104
{ key: "bodyHi", label: "Body hi", min: 0.3, max: 1, step: 0.01 },
105
{ key: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },
106
{ key: "bloomStrength", label: "Bloom", min: 0, max: 2, step: 0.01 },
107
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }
70
108
];
71
109
72
let params = { ...DEFAULT_WATER_DEBUG };
110
let waterParams = { ...DEFAULT_WATER_DEBUG };
111
let lavaParams = { ...DEFAULT_LAVA_DEBUG };
112
let activeTab = "water";
73
113
let panelEl = null;
74
114
75
115
export function getWaterDebugParams ()
76
116
{
77
return { ...params };
117
return { ...waterParams };
78
118
}
79
119
80
/** Uniform bag for the water ground fragment shader. */
81
export function waterDebugUniforms ()
120
export function getLavaDebugParams ()
121
{
122
return { ...lavaParams };
123
}
124
125
function uniformBagFrom (p, extras = {})
82
126
{
83
const p = params;
84
127
return {
85
128
u_flowX: p.flowX,
86
129
u_flowY: p.flowY,
@@ -110,55 +153,135 @@ export function waterDebugUniforms ()
110
153
u_lightDirY: p.lightDirY,
111
154
u_lightDirZ: p.lightDirZ,
112
155
u_normalEps: p.normalEps,
113
u_foamStrength: p.foamStrength,
114
u_shoreClip: p.shoreClip
156
...extras
115
157
};
116
158
}
117
159
160
/** Uniform bag for the water ground fragment shader. */
161
export function waterDebugUniforms ()
162
{
163
const p = waterParams;
164
return uniformBagFrom(p, {
165
u_foamStrength: p.foamStrength,
166
u_shoreClip: p.shoreClip,
167
u_deepDark: p.deepDark,
168
u_deepAbrupt: p.deepAbrupt
169
});
170
}
171
172
/** Uniform bag for lava ground / bloom shaders. */
173
export function lavaDebugUniforms ()
174
{
175
const p = lavaParams;
176
return uniformBagFrom(p, {
177
u_bloomStrength: p.bloomStrength
178
});
179
}
180
118
181
export function setWaterDebugParams (next)
119
182
{
120
params = { ...DEFAULT_WATER_DEBUG, ...params, ...next };
183
waterParams = { ...DEFAULT_WATER_DEBUG, ...waterParams, ...next };
121
184
syncInputs();
122
185
}
123
186
187
export function setLavaDebugParams (next)
188
{
189
lavaParams = { ...DEFAULT_LAVA_DEBUG, ...lavaParams, ...next };
190
syncInputs();
191
}
192
193
function activeParams ()
194
{
195
return activeTab === "lava" ? lavaParams : waterParams;
196
}
197
198
function activeSliders ()
199
{
200
return activeTab === "lava" ? LAVA_SLIDERS : WATER_SLIDERS;
201
}
202
124
203
function syncInputs ()
125
204
{
126
205
if (!panelEl)
127
206
{ return; }
128
for (const { key } of SLIDERS)
207
for (const { key } of activeSliders())
129
208
{
130
const input = panelEl.querySelector(`input[data-water-key="${key}"]`);
131
const valueEl = panelEl.querySelector(`[data-water-value="${key}"]`);
209
const input = panelEl.querySelector(`input[data-fluid-key="${key}"]`);
210
const valueEl = panelEl.querySelector(`[data-fluid-value="${key}"]`);
211
const params = activeParams();
132
212
if (input)
133
213
{ input.value = String(params[key]); }
134
214
if (valueEl)
135
215
{ valueEl.textContent = Number(params[key]).toFixed(3); }
136
216
}
217
for (const btn of panelEl.querySelectorAll("[data-fluid-tab]"))
218
{
219
const on = btn.getAttribute("data-fluid-tab") === activeTab;
220
btn.style.opacity = on ? "1" : "0.55";
221
btn.style.borderBottom = on ? "2px solid #9ec5ff" : "2px solid transparent";
222
}
137
223
}
138
224
139
225
function exportJson ()
140
226
{
141
const text = JSON.stringify(getWaterDebugParams(), null, 2);
142
void navigator.clipboard?.writeText(text).catch(() => {});
227
const isLava = activeTab === "lava";
228
const text = JSON.stringify(isLava ? getLavaDebugParams() : getWaterDebugParams(), null, 2);
229
void navigator.clipboard?.writeText(text).catch(() => { });
143
230
const blob = new Blob([text], { type: "application/json" });
144
231
const url = URL.createObjectURL(blob);
145
232
const a = document.createElement("a");
146
233
a.href = url;
147
a.download = "water-debug.json";
234
a.download = isLava ? "lava-debug.json" : "water-debug.json";
148
235
a.click();
149
236
URL.revokeObjectURL(url);
150
const status = panelEl?.querySelector("[data-water-export-status]");
237
const status = panelEl?.querySelector("[data-fluid-export-status]");
151
238
if (status)
152
239
{
153
status.textContent = "Exported (+ copied if allowed)";
240
status.textContent = "Exported";
154
241
setTimeout(() =>
155
242
{
156
if (status.textContent.startsWith("Exported"))
243
if (status.textContent === "Exported")
157
244
{ status.textContent = ""; }
158
245
}, 2000);
159
246
}
160
247
}
161
248
249
function rebuildSliderRows ()
250
{
251
const scroll = panelEl?.querySelector(".fluid-debug-scroll");
252
if (!scroll)
253
{ return; }
254
scroll.replaceChildren();
255
const params = activeParams();
256
for (const spec of activeSliders())
257
{
258
const row = document.createElement("label");
259
row.style.cssText = "display:grid;grid-template-columns:1fr 48px;gap:2px 6px;align-items:center;";
260
row.innerHTML = `
261
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>
262
<input type="range" data-fluid-key="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${params[spec.key]}">
263
<span data-fluid-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(params[spec.key]).toFixed(3)}</span>
264
`;
265
const input = row.querySelector("input");
266
input.addEventListener("input", () =>
267
{
268
const bag = activeTab === "lava" ? lavaParams : waterParams;
269
bag[spec.key] = Number(input.value);
270
const valueEl = row.querySelector(`[data-fluid-value="${spec.key}"]`);
271
if (valueEl)
272
{ valueEl.textContent = Number(bag[spec.key]).toFixed(3); }
273
});
274
scroll.appendChild(row);
275
}
276
}
277
278
function setTab (tab)
279
{
280
activeTab = tab === "lava" ? "lava" : "water";
281
rebuildSliderRows();
282
syncInputs();
283
}
284
162
285
/**
163
286
* Always-visible temporary debug dock (pointer-events on panel only).
164
287
*/
@@ -168,76 +291,88 @@ export function initWaterDebugPanel ()
168
291
{ return panelEl; }
169
292
170
293
panelEl = document.createElement("aside");
171
panelEl.id = "water-debug-panel";
294
panelEl.id = "fluid-debug-panel";
172
295
panelEl.innerHTML = `
173
<header>
174
<strong>Water debug</strong>
175
<span data-water-export-status></span>
296
<header style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">
297
<nav style="display:flex;gap:6px;">
298
<button type="button" data-fluid-tab="water">Water</button>
299
<button type="button" data-fluid-tab="lava">Lava</button>
300
</nav>
301
<span data-fluid-export-status style="margin-left:auto;opacity:0.75"></span>
176
302
</header>
177
<div class="water-debug-scroll"></div>
178
<footer>
179
<button type="button" data-water-reset>Reset</button>
180
<button type="button" data-water-export>Export JSON</button>
303
<div class="fluid-debug-scroll"></div>
304
<footer style="display:flex;gap:6px;">
305
<button type="button" data-fluid-reset>Reset</button>
306
<button type="button" data-fluid-export>Export</button>
181
307
</footer>
182
308
`;
183
309
Object.assign(panelEl.style, {
184
310
position: "fixed",
185
311
top: "8px",
186
312
right: "8px",
187
width: "280px",
313
width: "250px",
188
314
maxHeight: "calc(100vh - 16px)",
189
315
zIndex: "9999",
190
316
display: "flex",
191
317
flexDirection: "column",
192
gap: "6px",
318
gap: "4px",
193
319
padding: "8px",
194
320
background: "rgba(12, 16, 22, 0.92)",
195
321
color: "#e8eef5",
196
font: "12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
322
font: "11px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
197
323
border: "1px solid rgba(255,255,255,0.18)",
198
324
borderRadius: "6px",
199
325
boxShadow: "0 8px 24px rgba(0,0,0,0.45)",
200
326
pointerEvents: "auto"
201
327
});
202
328
203
const scroll = panelEl.querySelector(".water-debug-scroll");
329
const scroll = panelEl.querySelector(".fluid-debug-scroll");
204
330
Object.assign(scroll.style, {
205
331
overflowY: "auto",
206
332
flex: "1 1 auto",
207
333
display: "flex",
208
334
flexDirection: "column",
209
gap: "4px",
335
gap: "3px",
210
336
paddingRight: "2px"
211
337
});
212
338
213
for (const spec of SLIDERS)
339
for (const btn of panelEl.querySelectorAll("button"))
214
340
{
215
const row = document.createElement("label");
216
row.style.cssText = "display:grid;grid-template-columns:1fr 52px;gap:4px 6px;align-items:center;";
217
row.innerHTML = `
218
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>
219
<input type="range" data-water-key="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${params[spec.key]}">
220
<span data-water-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(params[spec.key]).toFixed(3)}</span>
221
`;
222
const input = row.querySelector("input");
223
input.addEventListener("input", () =>
341
Object.assign(btn.style, {
342
background: "transparent",
343
color: "inherit",
344
border: "1px solid rgba(255,255,255,0.22)",
345
borderRadius: "4px",
346
padding: "3px 8px",
347
cursor: "pointer",
348
font: "inherit"
349
});
350
}
351
for (const btn of panelEl.querySelectorAll("[data-fluid-tab]"))
352
{
353
btn.style.border = "none";
354
btn.style.borderRadius = "0";
355
btn.style.padding = "2px 4px";
356
btn.addEventListener("click", (event) =>
224
357
{
225
params[spec.key] = Number(input.value);
226
const valueEl = row.querySelector(`[data-water-value="${spec.key}"]`);
227
if (valueEl)
228
{ valueEl.textContent = Number(params[spec.key]).toFixed(3); }
358
event.preventDefault();
359
event.stopPropagation();
360
setTab(btn.getAttribute("data-fluid-tab"));
229
361
});
230
scroll.appendChild(row);
231
362
}
232
363
233
panelEl.querySelector("[data-water-reset]").addEventListener("click", (event) =>
364
panelEl.querySelector("[data-fluid-reset]").addEventListener("click", (event) =>
234
365
{
235
366
event.preventDefault();
236
367
event.stopPropagation();
237
params = { ...DEFAULT_WATER_DEBUG };
368
if (activeTab === "lava")
369
{ lavaParams = { ...DEFAULT_LAVA_DEBUG }; }
370
else
371
{ waterParams = { ...DEFAULT_WATER_DEBUG }; }
372
rebuildSliderRows();
238
373
syncInputs();
239
374
});
240
panelEl.querySelector("[data-water-export]").addEventListener("click", (event) =>
375
panelEl.querySelector("[data-fluid-export]").addEventListener("click", (event) =>
241
376
{
242
377
event.preventDefault();
243
378
event.stopPropagation();
@@ -252,6 +387,8 @@ export function initWaterDebugPanel ()
252
387
});
253
388
}
254
389
390
rebuildSliderRows();
391
syncInputs();
255
392
document.body.appendChild(panelEl);
256
393
return panelEl;
257
394
}
@@ -1,86 +1,129 @@1
/**1
/**2
* Temporary always-on water shader debug panel (simplex FBM tune).2
* Temporary always-on fluid shader debug panel (water + lava tabs).3
* Export JSON when you land on values you like.3
* Export JSON when you land on values you like.4
*/4
*/5
5
6
export const DEFAULT_WATER_DEBUG = Object.freeze({6
export const DEFAULT_WATER_DEBUG = Object.freeze({7
flowX: 0.33,7
flowX: 0.17,8
flowY: 0.21,8
flowY: 0.05,9
flowZ: 0.52,9
flowZ: 0.91,10
waveScale: 0.85,10
waveScale: 2.07,11
fbmAmp: 0.75,11
fbmAmp: 0.15,12
texAmp: 0.18,12
texAmp: 0.43,13
distort: 0.14,13
distort: 0.09,14
normalZ: 0.9,14
normalZ: 0.88,15
waveGain: 0.42,15
waveGain: 0.62,16
crestLo: 0.72,16
crestLo: 0.54,17
crestHi: 0.96,17
crestHi: 0.67,18
crestPow: 2.2,18
crestPow: 2.05,19
glitterPow: 13.1,20
crestGlitter: 1.3,21
glitterCap: 1,22
glitterMix: 1.24,23
shadeLo: 1.06,24
shadeHi: 1,25
bodyLo: 0.41,26
bodyHi: 0.85,27
litLo: 0.5,28
litHi: 0.86,29
litMix: 0.46,30
edgeDark: 0.37,31
lightDirX: -0.48,32
lightDirY: -0.63,33
lightDirZ: 0.78,34
normalEps: 0.21,35
foamStrength: 1,36
shoreClip: 0.55,37
/** 0 = baseline deep end; 1 = much darker deep water. */38
deepDark: 0.4,39
/** <1 = more abrupt darkening toward deep (pow curve). */40
deepAbrupt: 0.7241
});42
43
export const DEFAULT_LAVA_DEBUG = Object.freeze({44
flowX: 0.08,45
flowY: 0.04,46
flowZ: 0.27,47
waveScale: 1.83,48
fbmAmp: 0.43,49
texAmp: 0.3,50
distort: 0.3,51
normalZ: 1.07,52
waveGain: 0.52,53
crestLo: 0.57,54
crestHi: 0.71,55
crestPow: 1.15,19
glitterPow: 7.5,56
glitterPow: 7.5,20
crestGlitter: 0.55,57
crestGlitter: 1.19,21
glitterCap: 0.72,58
glitterCap: 0.31,22
glitterMix: 0.8,59
glitterMix: 0.51,23
shadeLo: 0.9,60
shadeLo: 0.88,24
shadeHi: 1.06,61
shadeHi: 1.07,25
bodyLo: 0.12,62
bodyLo: 0.05,26
bodyHi: 0.72,63
bodyHi: 1,27
litLo: 0.52,64
litLo: 0.59,28
litHi: 0.9,65
litHi: 0.74,29
litMix: 0.4,66
litMix: 1,30
edgeDark: 0.4,67
edgeDark: 1,31
lightDirX: -0.55,68
lightDirX: -0.48,32
lightDirY: -0.5,69
lightDirY: -0.63,33
lightDirZ: 0.75,70
lightDirZ: 0.78,34
normalEps: 0.1,71
normalEps: 0.09,35
foamStrength: 0.95,72
bloomStrength: 0.936
shoreClip: 0.4237
});73
});38
74
39
const SLIDERS = [75
const WATER_SLIDERS = [40
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },76
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },41
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },77
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },42
{ key: "flowZ", label: "Flow Z (time)", min: 0, max: 1.5, step: 0.01 },78
{ key: "flowZ", label: "Flow Z", min: 0, max: 1.5, step: 0.01 },43
{ key: "waveScale", label: "Wave scale", min: 0.2, max: 2.5, step: 0.01 },79
{ key: "waveScale", label: "Wave scale", min: 0.2, max: 2.5, step: 0.01 },44
{ key: "fbmAmp", label: "FBM amp", min: 0.1, max: 1.5, step: 0.01 },80
{ key: "fbmAmp", label: "FBM amp", min: 0.1, max: 1.5, step: 0.01 },45
{ key: "texAmp", label: "Tex amp", min: 0, max: 0.6, step: 0.01 },46
{ key: "distort", label: "Distort", min: 0, max: 0.5, step: 0.01 },47
{ key: "normalEps", label: "Normal ε", min: 0.02, max: 0.3, step: 0.01 },48
{ key: "normalZ", label: "Normal Z", min: 0.3, max: 1.5, step: 0.01 },49
{ key: "waveGain", label: "Wave gain", min: 0.1, max: 1, step: 0.01 },50
{ key: "crestLo", label: "Crest lo", min: 0.3, max: 0.95, step: 0.01 },51
{ key: "crestHi", label: "Crest hi", min: 0.5, max: 1, step: 0.01 },52
{ key: "crestPow", label: "Crest pow", min: 0.5, max: 5, step: 0.05 },53
{ key: "glitterPow", label: "Glitter pow", min: 1, max: 16, step: 0.1 },81
{ key: "glitterPow", label: "Glitter pow", min: 1, max: 16, step: 0.1 },54
{ key: "crestGlitter", label: "Crest glitter", min: 0, max: 1.5, step: 0.01 },55
{ key: "glitterCap", label: "Glitter cap", min: 0.1, max: 1, step: 0.01 },56
{ key: "glitterMix", label: "Glitter mix", min: 0, max: 1.5, step: 0.01 },82
{ key: "glitterMix", label: "Glitter mix", min: 0, max: 1.5, step: 0.01 },57
{ key: "shadeLo", label: "Shade lo", min: 0.5, max: 1.1, step: 0.01 },58
{ key: "shadeHi", label: "Shade hi", min: 0.9, max: 1.4, step: 0.01 },59
{ key: "bodyLo", label: "Body lo", min: 0, max: 0.5, step: 0.01 },83
{ key: "bodyLo", label: "Body lo", min: 0, max: 0.5, step: 0.01 },60
{ key: "bodyHi", label: "Body hi", min: 0.3, max: 1, step: 0.01 },84
{ key: "bodyHi", label: "Body hi", min: 0.3, max: 1, step: 0.01 },61
{ key: "litLo", label: "Lit lo", min: 0.2, max: 0.8, step: 0.01 },62
{ key: "litHi", label: "Lit hi", min: 0.5, max: 1, step: 0.01 },63
{ key: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },85
{ key: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },64
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 },86
{ key: "deepDark", label: "Deep darker", min: 0, max: 1, step: 0.01 },65
{ key: "lightDirX", label: "Light dir X", min: -1, max: 1, step: 0.01 },87
{ key: "deepAbrupt", label: "Deep abrupt", min: 0.35, max: 1.4, step: 0.01 },66
{ key: "lightDirY", label: "Light dir Y", min: -1, max: 1, step: 0.01 },88
{ key: "foamStrength", label: "Foam", min: 0, max: 1, step: 0.01 },67
{ key: "lightDirZ", label: "Light dir Z", min: 0.1, max: 1.5, step: 0.01 },89
{ key: "shoreClip", label: "Shore clip", min: 0.1, max: 0.9, step: 0.01 },68
{ key: "foamStrength", label: "Foam strength", min: 0, max: 1, step: 0.01 },90
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }69
{ key: "shoreClip", label: "Shore clip", min: 0.1, max: 0.9, step: 0.01 }91
];92
93
const LAVA_SLIDERS = [94
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },95
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },96
{ key: "flowZ", label: "Flow Z", min: 0, max: 1.5, step: 0.01 },97
{ key: "waveScale", label: "Wave scale", min: 0.2, max: 2.5, step: 0.01 },98
{ key: "fbmAmp", label: "FBM amp", min: 0.1, max: 1.5, step: 0.01 },99
{ key: "distort", label: "Distort", min: 0, max: 0.5, step: 0.01 },100
{ key: "glitterPow", label: "Heat pow", min: 1, max: 16, step: 0.1 },101
{ key: "glitterMix", label: "Heat mix", min: 0, max: 1.5, step: 0.01 },102
{ key: "glitterCap", label: "Heat cap", min: 0.1, max: 1, step: 0.01 },103
{ key: "bodyLo", label: "Body lo", min: 0, max: 0.5, step: 0.01 },104
{ key: "bodyHi", label: "Body hi", min: 0.3, max: 1, step: 0.01 },105
{ key: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },106
{ key: "bloomStrength", label: "Bloom", min: 0, max: 2, step: 0.01 },107
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }70
];108
];71
109
72
let params = { ...DEFAULT_WATER_DEBUG };110
let waterParams = { ...DEFAULT_WATER_DEBUG };111
let lavaParams = { ...DEFAULT_LAVA_DEBUG };112
let activeTab = "water";73
let panelEl = null;113
let panelEl = null;74
114
75
export function getWaterDebugParams ()115
export function getWaterDebugParams ()76
{116
{77
return { ...params };117
return { ...waterParams };78
}118
}79
119
80
/** Uniform bag for the water ground fragment shader. */120
export function getLavaDebugParams ()81
export function waterDebugUniforms ()121
{122
return { ...lavaParams };123
}124
125
function uniformBagFrom (p, extras = {})82
{126
{83
const p = params;84
return {127
return {85
u_flowX: p.flowX,128
u_flowX: p.flowX,86
u_flowY: p.flowY,129
u_flowY: p.flowY,@@ -110,55 +153,135 @@ export function waterDebugUniforms ()110
u_lightDirY: p.lightDirY,153
u_lightDirY: p.lightDirY,111
u_lightDirZ: p.lightDirZ,154
u_lightDirZ: p.lightDirZ,112
u_normalEps: p.normalEps,155
u_normalEps: p.normalEps,113
u_foamStrength: p.foamStrength,156
...extras114
u_shoreClip: p.shoreClip115
};157
};116
}158
}117
159
160
/** Uniform bag for the water ground fragment shader. */161
export function waterDebugUniforms ()162
{163
const p = waterParams;164
return uniformBagFrom(p, {165
u_foamStrength: p.foamStrength,166
u_shoreClip: p.shoreClip,167
u_deepDark: p.deepDark,168
u_deepAbrupt: p.deepAbrupt169
});170
}171
172
/** Uniform bag for lava ground / bloom shaders. */173
export function lavaDebugUniforms ()174
{175
const p = lavaParams;176
return uniformBagFrom(p, {177
u_bloomStrength: p.bloomStrength178
});179
}180
118
export function setWaterDebugParams (next)181
export function setWaterDebugParams (next)119
{182
{120
params = { ...DEFAULT_WATER_DEBUG, ...params, ...next };183
waterParams = { ...DEFAULT_WATER_DEBUG, ...waterParams, ...next };121
syncInputs();184
syncInputs();122
}185
}123
186
187
export function setLavaDebugParams (next)188
{189
lavaParams = { ...DEFAULT_LAVA_DEBUG, ...lavaParams, ...next };190
syncInputs();191
}192
193
function activeParams ()194
{195
return activeTab === "lava" ? lavaParams : waterParams;196
}197
198
function activeSliders ()199
{200
return activeTab === "lava" ? LAVA_SLIDERS : WATER_SLIDERS;201
}202
124
function syncInputs ()203
function syncInputs ()125
{204
{126
if (!panelEl)205
if (!panelEl)127
{ return; }206
{ return; }128
for (const { key } of SLIDERS)207
for (const { key } of activeSliders())129
{208
{130
const input = panelEl.querySelector(`input[data-water-key="${key}"]`);209
const input = panelEl.querySelector(`input[data-fluid-key="${key}"]`);131
const valueEl = panelEl.querySelector(`[data-water-value="${key}"]`);210
const valueEl = panelEl.querySelector(`[data-fluid-value="${key}"]`);211
const params = activeParams();132
if (input)212
if (input)133
{ input.value = String(params[key]); }213
{ input.value = String(params[key]); }134
if (valueEl)214
if (valueEl)135
{ valueEl.textContent = Number(params[key]).toFixed(3); }215
{ valueEl.textContent = Number(params[key]).toFixed(3); }136
}216
}217
for (const btn of panelEl.querySelectorAll("[data-fluid-tab]"))218
{219
const on = btn.getAttribute("data-fluid-tab") === activeTab;220
btn.style.opacity = on ? "1" : "0.55";221
btn.style.borderBottom = on ? "2px solid #9ec5ff" : "2px solid transparent";222
}137
}223
}138
224
139
function exportJson ()225
function exportJson ()140
{226
{141
const text = JSON.stringify(getWaterDebugParams(), null, 2);227
const isLava = activeTab === "lava";142
void navigator.clipboard?.writeText(text).catch(() => {});228
const text = JSON.stringify(isLava ? getLavaDebugParams() : getWaterDebugParams(), null, 2);229
void navigator.clipboard?.writeText(text).catch(() => { });143
const blob = new Blob([text], { type: "application/json" });230
const blob = new Blob([text], { type: "application/json" });144
const url = URL.createObjectURL(blob);231
const url = URL.createObjectURL(blob);145
const a = document.createElement("a");232
const a = document.createElement("a");146
a.href = url;233
a.href = url;147
a.download = "water-debug.json";234
a.download = isLava ? "lava-debug.json" : "water-debug.json";148
a.click();235
a.click();149
URL.revokeObjectURL(url);236
URL.revokeObjectURL(url);150
const status = panelEl?.querySelector("[data-water-export-status]");237
const status = panelEl?.querySelector("[data-fluid-export-status]");151
if (status)238
if (status)152
{239
{153
status.textContent = "Exported (+ copied if allowed)";240
status.textContent = "Exported";154
setTimeout(() =>241
setTimeout(() =>155
{242
{156
if (status.textContent.startsWith("Exported"))243
if (status.textContent === "Exported")157
{ status.textContent = ""; }244
{ status.textContent = ""; }158
}, 2000);245
}, 2000);159
}246
}160
}247
}161
248
249
function rebuildSliderRows ()250
{251
const scroll = panelEl?.querySelector(".fluid-debug-scroll");252
if (!scroll)253
{ return; }254
scroll.replaceChildren();255
const params = activeParams();256
for (const spec of activeSliders())257
{258
const row = document.createElement("label");259
row.style.cssText = "display:grid;grid-template-columns:1fr 48px;gap:2px 6px;align-items:center;";260
row.innerHTML = `261
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>262
<input type="range" data-fluid-key="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${params[spec.key]}">263
<span data-fluid-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(params[spec.key]).toFixed(3)}</span>264
`;265
const input = row.querySelector("input");266
input.addEventListener("input", () =>267
{268
const bag = activeTab === "lava" ? lavaParams : waterParams;269
bag[spec.key] = Number(input.value);270
const valueEl = row.querySelector(`[data-fluid-value="${spec.key}"]`);271
if (valueEl)272
{ valueEl.textContent = Number(bag[spec.key]).toFixed(3); }273
});274
scroll.appendChild(row);275
}276
}277
278
function setTab (tab)279
{280
activeTab = tab === "lava" ? "lava" : "water";281
rebuildSliderRows();282
syncInputs();283
}284
162
/**285
/**163
* Always-visible temporary debug dock (pointer-events on panel only).286
* Always-visible temporary debug dock (pointer-events on panel only).164
*/287
*/@@ -168,76 +291,88 @@ export function initWaterDebugPanel ()168
{ return panelEl; }291
{ return panelEl; }169
292
170
panelEl = document.createElement("aside");293
panelEl = document.createElement("aside");171
panelEl.id = "water-debug-panel";294
panelEl.id = "fluid-debug-panel";172
panelEl.innerHTML = `295
panelEl.innerHTML = `173
<header>296
<header style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">174
<strong>Water debug</strong>297
<nav style="display:flex;gap:6px;">175
<span data-water-export-status></span>298
<button type="button" data-fluid-tab="water">Water</button>299
<button type="button" data-fluid-tab="lava">Lava</button>300
</nav>301
<span data-fluid-export-status style="margin-left:auto;opacity:0.75"></span>176
</header>302
</header>177
<div class="water-debug-scroll"></div>303
<div class="fluid-debug-scroll"></div>178
<footer>304
<footer style="display:flex;gap:6px;">179
<button type="button" data-water-reset>Reset</button>305
<button type="button" data-fluid-reset>Reset</button>180
<button type="button" data-water-export>Export JSON</button>306
<button type="button" data-fluid-export>Export</button>181
</footer>307
</footer>182
`;308
`;183
Object.assign(panelEl.style, {309
Object.assign(panelEl.style, {184
position: "fixed",310
position: "fixed",185
top: "8px",311
top: "8px",186
right: "8px",312
right: "8px",187
width: "280px",313
width: "250px",188
maxHeight: "calc(100vh - 16px)",314
maxHeight: "calc(100vh - 16px)",189
zIndex: "9999",315
zIndex: "9999",190
display: "flex",316
display: "flex",191
flexDirection: "column",317
flexDirection: "column",192
gap: "6px",318
gap: "4px",193
padding: "8px",319
padding: "8px",194
background: "rgba(12, 16, 22, 0.92)",320
background: "rgba(12, 16, 22, 0.92)",195
color: "#e8eef5",321
color: "#e8eef5",196
font: "12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",322
font: "11px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",197
border: "1px solid rgba(255,255,255,0.18)",323
border: "1px solid rgba(255,255,255,0.18)",198
borderRadius: "6px",324
borderRadius: "6px",199
boxShadow: "0 8px 24px rgba(0,0,0,0.45)",325
boxShadow: "0 8px 24px rgba(0,0,0,0.45)",200
pointerEvents: "auto"326
pointerEvents: "auto"201
});327
});202
328
203
const scroll = panelEl.querySelector(".water-debug-scroll");329
const scroll = panelEl.querySelector(".fluid-debug-scroll");204
Object.assign(scroll.style, {330
Object.assign(scroll.style, {205
overflowY: "auto",331
overflowY: "auto",206
flex: "1 1 auto",332
flex: "1 1 auto",207
display: "flex",333
display: "flex",208
flexDirection: "column",334
flexDirection: "column",209
gap: "4px",335
gap: "3px",210
paddingRight: "2px"336
paddingRight: "2px"211
});337
});212
338
213
for (const spec of SLIDERS)339
for (const btn of panelEl.querySelectorAll("button"))214
{340
{215
const row = document.createElement("label");341
Object.assign(btn.style, {216
row.style.cssText = "display:grid;grid-template-columns:1fr 52px;gap:4px 6px;align-items:center;";342
background: "transparent",217
row.innerHTML = `343
color: "inherit",218
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>344
border: "1px solid rgba(255,255,255,0.22)",219
<input type="range" data-water-key="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${params[spec.key]}">345
borderRadius: "4px",220
<span data-water-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(params[spec.key]).toFixed(3)}</span>346
padding: "3px 8px",221
`;347
cursor: "pointer",222
const input = row.querySelector("input");348
font: "inherit"223
input.addEventListener("input", () =>349
});350
}351
for (const btn of panelEl.querySelectorAll("[data-fluid-tab]"))352
{353
btn.style.border = "none";354
btn.style.borderRadius = "0";355
btn.style.padding = "2px 4px";356
btn.addEventListener("click", (event) =>224
{357
{225
params[spec.key] = Number(input.value);358
event.preventDefault();226
const valueEl = row.querySelector(`[data-water-value="${spec.key}"]`);359
event.stopPropagation();227
if (valueEl)360
setTab(btn.getAttribute("data-fluid-tab"));228
{ valueEl.textContent = Number(params[spec.key]).toFixed(3); }229
});361
});230
scroll.appendChild(row);231
}362
}232
363
233
panelEl.querySelector("[data-water-reset]").addEventListener("click", (event) =>364
panelEl.querySelector("[data-fluid-reset]").addEventListener("click", (event) =>234
{365
{235
event.preventDefault();366
event.preventDefault();236
event.stopPropagation();367
event.stopPropagation();237
params = { ...DEFAULT_WATER_DEBUG };368
if (activeTab === "lava")369
{ lavaParams = { ...DEFAULT_LAVA_DEBUG }; }370
else371
{ waterParams = { ...DEFAULT_WATER_DEBUG }; }372
rebuildSliderRows();238
syncInputs();373
syncInputs();239
});374
});240
panelEl.querySelector("[data-water-export]").addEventListener("click", (event) =>375
panelEl.querySelector("[data-fluid-export]").addEventListener("click", (event) =>241
{376
{242
event.preventDefault();377
event.preventDefault();243
event.stopPropagation();378
event.stopPropagation();@@ -252,6 +387,8 @@ export function initWaterDebugPanel ()252
});387
});253
}388
}254
389
390
rebuildSliderRows();391
syncInputs();255
document.body.appendChild(panelEl);392
document.body.appendChild(panelEl);256
return panelEl;393
return panelEl;257
}394
}@@ -2,7 +2,7 @@ import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BO
2
2
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";
3
3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4
4
import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";
5
import { collectBlockLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";
5
import { collectBlockLightSources, collectGroundLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";
6
6
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";
7
7
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
8
8
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";
@@ -16,7 +16,7 @@ import
16
16
} from "/shared/render/tint.js";
17
17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
18
18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";
19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";
20
20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
21
21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
22
22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -27,7 +27,7 @@ import
27
27
invalidateCanvasTexture
28
28
} from "./canvasSprite.js";
29
29
import { setNearestFilter } from "./sprites.js";
30
import { waterDebugUniforms } from "../play/waterDebug.js";
30
import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";
31
31
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";
32
32
import
33
33
{
@@ -168,6 +168,8 @@ const WATER_GROUND_FRAG = [
168
168
"uniform float u_normalEps;",
169
169
"uniform float u_foamStrength;",
170
170
"uniform float u_shoreClip;",
171
"uniform float u_deepDark;",
172
"uniform float u_deepAbrupt;",
171
173
// 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).
172
174
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
173
175
"vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
@@ -283,10 +285,12 @@ const WATER_GROUND_FRAG = [
283
285
" float deepTop = mix(u_deepNW, u_deepNE, puv.x);",
284
286
" float deepBot = mix(u_deepSW, u_deepSE, puv.x);",
285
287
" float deepMix = mix(deepTop, deepBot, puv.y);",
286
" vec3 deepCol = mix(vec3(0.12, 0.34, 0.54), vec3(0.07, 0.22, 0.42), deepMix);",
287
" vec3 midCol = mix(vec3(0.24, 0.52, 0.70), vec3(0.12, 0.34, 0.54), deepMix);",
288
" vec3 litCol = mix(vec3(0.52, 0.78, 0.90), vec3(0.30, 0.52, 0.72), deepMix);",
289
" vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), vec3(0.78, 0.92, 1.0), deepMix);",
288
" float deepAmt = pow(clamp(deepMix, 0.0, 1.0), max(u_deepAbrupt, 0.05));",
289
" float darkW = clamp(u_deepDark, 0.0, 1.0);",
290
" vec3 deepCol = mix(vec3(0.12, 0.34, 0.54), mix(vec3(0.05, 0.16, 0.34), vec3(0.015, 0.055, 0.14), darkW), deepAmt);",
291
" vec3 midCol = mix(vec3(0.24, 0.52, 0.70), mix(vec3(0.10, 0.30, 0.50), vec3(0.04, 0.14, 0.28), darkW), deepAmt);",
292
" vec3 litCol = mix(vec3(0.52, 0.78, 0.90), mix(vec3(0.26, 0.46, 0.66), vec3(0.12, 0.28, 0.46), darkW), deepAmt);",
293
" vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), mix(vec3(0.72, 0.88, 0.98), vec3(0.48, 0.68, 0.86), darkW), deepAmt);",
290
294
" vec3 foamCol = vec3(0.94, 0.99, 1.0);",
291
295
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",
292
296
" vec3 rgb = mix(deepCol, midCol, smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody));",
@@ -337,6 +341,275 @@ const WATER_GROUND_FRAG = [
337
341
"}"
338
342
].join("\n");
339
343
344
/** Lava heat: dark red → red → orange → yellow; yellow drives bloom companion. */
345
const LAVA_FBM_COMMON = [
346
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
347
"vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
348
"vec4 permute(vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }",
349
"vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }",
350
"float snoise(vec3 v) {",
351
" vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);",
352
" vec4 D = vec4(0.0, 0.5, 1.0, 2.0);",
353
" vec3 i = floor(v + dot(v, C.yyy));",
354
" vec3 x0 = v - i + dot(i, C.xxx);",
355
" vec3 g = step(x0.yzx, x0.xyz);",
356
" vec3 l = 1.0 - g;",
357
" vec3 i1 = min(g.xyz, l.zxy);",
358
" vec3 i2 = max(g.xyz, l.zxy);",
359
" vec3 x1 = x0 - i1 + C.xxx;",
360
" vec3 x2 = x0 - i2 + C.yyy;",
361
" vec3 x3 = x0 - D.yyy;",
362
" i = mod289(i);",
363
" vec4 p = permute(permute(permute(",
364
" i.z + vec4(0.0, i1.z, i2.z, 1.0))",
365
" + i.y + vec4(0.0, i1.y, i2.y, 1.0))",
366
" + i.x + vec4(0.0, i1.x, i2.x, 1.0));",
367
" float n_ = 0.142857142857;",
368
" vec3 ns = n_ * D.wyz - D.xzx;",
369
" vec4 j = p - 49.0 * floor(p * ns.z * ns.z);",
370
" vec4 x_ = floor(j * ns.z);",
371
" vec4 y_ = floor(j - 7.0 * x_);",
372
" vec4 x = x_ * ns.x + ns.yyyy;",
373
" vec4 y = y_ * ns.x + ns.yyyy;",
374
" vec4 h = 1.0 - abs(x) - abs(y);",
375
" vec4 b0 = vec4(x.xy, y.xy);",
376
" vec4 b1 = vec4(x.zw, y.zw);",
377
" vec4 s0 = floor(b0) * 2.0 + 1.0;",
378
" vec4 s1 = floor(b1) * 2.0 + 1.0;",
379
" vec4 sh = -step(h, vec4(0.0));",
380
" vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;",
381
" vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;",
382
" vec3 p0 = vec3(a0.xy, h.x);",
383
" vec3 p1 = vec3(a0.zw, h.y);",
384
" vec3 p2 = vec3(a1.xy, h.z);",
385
" vec3 p3 = vec3(a1.zw, h.w);",
386
" vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));",
387
" p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;",
388
" vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);",
389
" m = m * m;",
390
" return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));",
391
"}",
392
"float fbm(vec3 p) {",
393
" float sum = 0.0;",
394
" float amp = 0.5;",
395
" sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
396
" sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
397
" sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",
398
" sum += amp * snoise(p);",
399
" return sum;",
400
"}",
401
"vec2 wrapUv(vec2 uv) {",
402
" return fract(uv) * 0.998 + 0.001;",
403
"}"
404
];
405
406
const LAVA_GROUND_FRAG = [
407
"precision mediump float;",
408
"varying vec2 v_texCoord;",
409
"uniform sampler2D u_texture;",
410
"uniform float u_alpha;",
411
"uniform float u_ambientDark;",
412
"uniform float u_litNW;",
413
"uniform float u_litNE;",
414
"uniform float u_litSW;",
415
"uniform float u_litSE;",
416
"uniform float u_time;",
417
"uniform float u_tileX;",
418
"uniform float u_tileY;",
419
"uniform float u_edgeN;",
420
"uniform float u_edgeE;",
421
"uniform float u_edgeS;",
422
"uniform float u_edgeW;",
423
"uniform float u_edgeNE;",
424
"uniform float u_edgeNW;",
425
"uniform float u_edgeSE;",
426
"uniform float u_edgeSW;",
427
"uniform float u_flowX;",
428
"uniform float u_flowY;",
429
"uniform float u_flowZ;",
430
"uniform float u_waveScale;",
431
"uniform float u_fbmAmp;",
432
"uniform float u_texAmp;",
433
"uniform float u_distort;",
434
"uniform float u_normalZ;",
435
"uniform float u_waveGain;",
436
"uniform float u_crestLo;",
437
"uniform float u_crestHi;",
438
"uniform float u_crestPow;",
439
"uniform float u_glitterPow;",
440
"uniform float u_crestGlitter;",
441
"uniform float u_glitterCap;",
442
"uniform float u_glitterMix;",
443
"uniform float u_shadeLo;",
444
"uniform float u_shadeHi;",
445
"uniform float u_bodyLo;",
446
"uniform float u_bodyHi;",
447
"uniform float u_litLo;",
448
"uniform float u_litHi;",
449
"uniform float u_litMix;",
450
"uniform float u_edgeDark;",
451
"uniform float u_lightDirX;",
452
"uniform float u_lightDirY;",
453
"uniform float u_lightDirZ;",
454
"uniform float u_normalEps;",
455
...LAVA_FBM_COMMON,
456
"void main() {",
457
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",
458
" vec2 puv = px / 16.0;",
459
" vec2 world = vec2(u_tileX, u_tileY) + puv;",
460
" float t = u_time;",
461
" vec2 flow = vec2(t * u_flowX, t * u_flowY);",
462
" float eps = max(u_normalEps, 0.001);",
463
" vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
464
" float nC = fbm(base);",
465
" float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
466
" float nR = fbm(base + vec3(eps, 0.0, 0.0));",
467
" float nD = fbm(base + vec3(0.0, -eps, 0.0));",
468
" float nU = fbm(base + vec3(0.0, eps, 0.0));",
469
" vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
470
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
471
" float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
472
" vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
473
" float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
474
" float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
475
" float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
476
" float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
477
" glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
478
" float edgeProx = 0.0;",
479
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
480
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
481
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
482
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
483
" if (u_edgeNE > 0.5) {",
484
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
485
" }",
486
" if (u_edgeNW > 0.5) {",
487
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
488
" }",
489
" if (u_edgeSE > 0.5) {",
490
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
491
" }",
492
" if (u_edgeSW > 0.5) {",
493
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
494
" }",
495
" float waveBody = wave * (1.0 - edgeProx * 0.55);",
496
" float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",
497
" heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",
498
" heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",
499
" vec3 darkRed = vec3(0.16, 0.015, 0.01);",
500
" vec3 brightRed = vec3(0.78, 0.08, 0.02);",
501
" vec3 orange = vec3(0.98, 0.38, 0.04);",
502
" vec3 yellow = vec3(1.0, 0.9, 0.28);",
503
" vec3 rgb = mix(darkRed, brightRed, smoothstep(0.0, 0.38, heat));",
504
" rgb = mix(rgb, orange, smoothstep(0.28, 0.68, heat));",
505
" float yellowAmt = smoothstep(0.55, 0.98, heat);",
506
" rgb = mix(rgb, yellow, yellowAmt);",
507
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",
508
" rgb *= shade;",
509
" rgb = mix(rgb, darkRed, edgeProx * u_edgeDark);",
510
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
511
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
512
" float lit = mix(litTop, litBottom, v_texCoord.y);",
513
" float darkness = u_ambientDark * (1.0 - lit);",
514
" rgb = mix(rgb, vec3(0.0), darkness);",
515
" gl_FragColor = vec4(rgb, u_alpha);",
516
"}"
517
].join("\n");
518
519
/** Unlit bloom overlay — strength tracks yellow heat (exempt from world darkness). */
520
const LAVA_BLOOM_FRAG = [
521
"precision mediump float;",
522
"varying vec2 v_texCoord;",
523
"uniform sampler2D u_texture;",
524
"uniform float u_alpha;",
525
"uniform float u_time;",
526
"uniform float u_tileX;",
527
"uniform float u_tileY;",
528
"uniform float u_edgeN;",
529
"uniform float u_edgeE;",
530
"uniform float u_edgeS;",
531
"uniform float u_edgeW;",
532
"uniform float u_edgeNE;",
533
"uniform float u_edgeNW;",
534
"uniform float u_edgeSE;",
535
"uniform float u_edgeSW;",
536
"uniform float u_flowX;",
537
"uniform float u_flowY;",
538
"uniform float u_flowZ;",
539
"uniform float u_waveScale;",
540
"uniform float u_fbmAmp;",
541
"uniform float u_texAmp;",
542
"uniform float u_distort;",
543
"uniform float u_normalZ;",
544
"uniform float u_waveGain;",
545
"uniform float u_crestLo;",
546
"uniform float u_crestHi;",
547
"uniform float u_crestPow;",
548
"uniform float u_glitterPow;",
549
"uniform float u_crestGlitter;",
550
"uniform float u_glitterCap;",
551
"uniform float u_glitterMix;",
552
"uniform float u_bodyLo;",
553
"uniform float u_bodyHi;",
554
"uniform float u_litLo;",
555
"uniform float u_litHi;",
556
"uniform float u_litMix;",
557
"uniform float u_lightDirX;",
558
"uniform float u_lightDirY;",
559
"uniform float u_lightDirZ;",
560
"uniform float u_normalEps;",
561
"uniform float u_bloomStrength;",
562
...LAVA_FBM_COMMON,
563
"void main() {",
564
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",
565
" vec2 puv = px / 16.0;",
566
" vec2 world = vec2(u_tileX, u_tileY) + puv;",
567
" float t = u_time;",
568
" vec2 flow = vec2(t * u_flowX, t * u_flowY);",
569
" float eps = max(u_normalEps, 0.001);",
570
" vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
571
" float nC = fbm(base);",
572
" float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
573
" float nR = fbm(base + vec3(eps, 0.0, 0.0));",
574
" float nD = fbm(base + vec3(0.0, -eps, 0.0));",
575
" float nU = fbm(base + vec3(0.0, eps, 0.0));",
576
" vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
577
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
578
" float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
579
" vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
580
" float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
581
" float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
582
" float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
583
" float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
584
" glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
585
" float edgeProx = 0.0;",
586
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
587
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
588
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",
589
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",
590
" if (u_edgeNE > 0.5) {",
591
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",
592
" }",
593
" if (u_edgeNW > 0.5) {",
594
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",
595
" }",
596
" if (u_edgeSE > 0.5) {",
597
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",
598
" }",
599
" if (u_edgeSW > 0.5) {",
600
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",
601
" }",
602
" float waveBody = wave * (1.0 - edgeProx * 0.55);",
603
" float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",
604
" heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",
605
" heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",
606
" float yellowAmt = smoothstep(0.55, 0.98, heat) * (1.0 - edgeProx * 0.85);",
607
" float bloom = yellowAmt * max(u_bloomStrength, 0.0);",
608
" vec3 glow = vec3(1.0, 0.82, 0.28) * bloom;",
609
" gl_FragColor = vec4(glow, bloom * u_alpha);",
610
"}"
611
].join("\n");
612
340
613
/** Magenta-tint (R==B, G < R) then lit effects; darkness always after tint. */
341
614
const TINT_LIT_SPRITE_FRAG = [
342
615
"precision mediump float;",
@@ -585,6 +858,8 @@ let spriteLightingShader = null;
585
858
let atlasLightingShader = null;
586
859
let cliffGroundTopShader = null;
587
860
let waterGroundShader = null;
861
let lavaGroundShader = null;
862
let lavaBloomShader = null;
588
863
let tintLitSpriteShader = null;
589
864
let dualTintLitSpriteShader = null;
590
865
let tightFitTintLitSpriteShader = null;
@@ -618,6 +893,20 @@ function getWaterGroundShader ()
618
893
return waterGroundShader;
619
894
}
620
895
896
function getLavaGroundShader ()
897
{
898
if (!lavaGroundShader)
899
{ lavaGroundShader = Shader.fragment(LAVA_GROUND_FRAG); }
900
return lavaGroundShader;
901
}
902
903
function getLavaBloomShader ()
904
{
905
if (!lavaBloomShader)
906
{ lavaBloomShader = Shader.fragment(LAVA_BLOOM_FRAG); }
907
return lavaBloomShader;
908
}
909
621
910
function getTintLitSpriteShader ()
622
911
{
623
912
if (!tintLitSpriteShader)
@@ -919,6 +1208,7 @@ export class WorldView
919
1208
{
920
1209
objects.ground?.destroy();
921
1210
objects.groundBloom?.destroy();
1211
objects.lavaBloom?.destroy();
922
1212
objects.block?.destroy();
923
1213
objects.blockBloom?.destroy();
924
1214
this.tiles.delete(tileKey);
@@ -3584,11 +3874,18 @@ export class WorldView
3584
3874
};
3585
3875
}
3586
3876
3587
/** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. */
3877
/** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. Lava is procedural heat. */
3588
3878
#syncGroundWaterFx (objects, ambientDark, timeSec, baked = null)
3589
3879
{
3590
3880
if (!objects?.ground)
3591
3881
{ return; }
3882
if (isLavaGround(objects.groundTypeId))
3883
{
3884
objects.waterEdges = null;
3885
this.#syncLavaGroundFx(objects, ambientDark, timeSec, baked);
3886
return;
3887
}
3888
this.#clearLavaBloom(objects);
3592
3889
if (!isLiquidWaterGround(objects.groundTypeId, this.worldSeason))
3593
3890
{
3594
3891
objects.waterEdges = null;
@@ -3629,6 +3926,171 @@ export class WorldView
3629
3926
});
3630
3927
}
3631
3928
3929
#lavaCoastEdges (tileX, tileY)
3930
{
3931
const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));
3932
const n = lava(tileX, tileY - 1);
3933
const e = lava(tileX + 1, tileY);
3934
const s = lava(tileX, tileY + 1);
3935
const w = lava(tileX - 1, tileY);
3936
const ne = lava(tileX + 1, tileY - 1);
3937
const nw = lava(tileX - 1, tileY - 1);
3938
const se = lava(tileX + 1, tileY + 1);
3939
const sw = lava(tileX - 1, tileY + 1);
3940
return {
3941
n: n ? 0 : 1,
3942
e: e ? 0 : 1,
3943
s: s ? 0 : 1,
3944
w: w ? 0 : 1,
3945
ne: (!ne && n && e) ? 1 : 0,
3946
nw: (!nw && n && w) ? 1 : 0,
3947
se: (!se && s && e) ? 1 : 0,
3948
sw: (!sw && s && w) ? 1 : 0
3949
};
3950
}
3951
3952
#clearLavaBloom (objects)
3953
{
3954
if (!objects)
3955
{ return; }
3956
objects.lavaBloom?.destroy();
3957
objects.lavaBloom = null;
3958
}
3959
3960
#ensureLavaBloom (objects)
3961
{
3962
const sprite = objects.ground?.renderer?.sprite;
3963
if (!sprite)
3964
{ return null; }
3965
if (!objects.lavaBloom)
3966
{
3967
const bloom = new GameObject(0, 0, sprite, LAYER_GROUND);
3968
bloom.renderer.layer = RENDER_LAYER_BLOOM;
3969
this.#markUnlit(bloom);
3970
this.scene.addObject(bloom);
3971
objects.lavaBloom = bloom;
3972
}
3973
else if (objects.lavaBloom.renderer)
3974
{ objects.lavaBloom.renderer.sprite = sprite; }
3975
const size = this.tileSize();
3976
objects.lavaBloom.transform.position.x = objects.tileX * size + size / 2;
3977
objects.lavaBloom.transform.position.y = objects.tileY * size + size / 2;
3978
objects.lavaBloom.transform.size = new vector(size, size);
3979
this.#setLayer(objects.lavaBloom, LAYER_GROUND);
3980
return objects.lavaBloom;
3981
}
3982
3983
#syncLavaGroundFx (objects, ambientDark, timeSec, baked = null)
3984
{
3985
const fallbackLit = 1 - (objects.shadeAlpha ?? 0);
3986
const chunkX = Math.floor(objects.tileX / CHUNK_SIZE);
3987
const chunkY = Math.floor(objects.tileY / CHUNK_SIZE);
3988
const chunkBaked = baked ?? this.bakedChunks.get(`${chunkX},${chunkY}`);
3989
const localX = objects.tileX - chunkX * CHUNK_SIZE;
3990
const localY = objects.tileY - chunkY * CHUNK_SIZE;
3991
let litCorners = null;
3992
if (chunkBaked)
3993
{
3994
if (this.lightingMode === "simple")
3995
{
3996
const gridW = CHUNK_SIZE + 2;
3997
const intensity = chunkBaked.lightIntensityGrid?.[(localY + 1) * gridW + (localX + 1)] ?? fallbackLit;
3998
litCorners = { nw: intensity, ne: intensity, sw: intensity, se: intensity };
3999
}
4000
else
4001
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }
4002
}
4003
const edges = this.#lavaCoastEdges(objects.tileX, objects.tileY);
4004
this.#syncLavaGroundSprite(objects.ground, {
4005
corners: litCorners,
4006
ambientDark,
4007
edges,
4008
timeSec,
4009
fallbackLit,
4010
tileX: objects.tileX,
4011
tileY: objects.tileY
4012
});
4013
const bloom = this.#ensureLavaBloom(objects);
4014
if (bloom)
4015
{
4016
this.#syncLavaBloomSprite(bloom, {
4017
edges,
4018
timeSec,
4019
tileX: objects.tileX,
4020
tileY: objects.tileY
4021
});
4022
}
4023
}
4024
4025
#syncLavaGroundSprite (object, {
4026
corners = null,
4027
ambientDark = 0,
4028
edges = null,
4029
timeSec = 0,
4030
fallbackLit = 1,
4031
tileX = 0,
4032
tileY = 0
4033
} = {})
4034
{
4035
if (!object?.renderer)
4036
{ return; }
4037
const lit = corners ?? {
4038
nw: fallbackLit,
4039
ne: fallbackLit,
4040
sw: fallbackLit,
4041
se: fallbackLit
4042
};
4043
const dark = Math.min(1, Math.max(0, ambientDark ?? 0));
4044
object._lit = true;
4045
object.renderer.shader = getLavaGroundShader();
4046
object.renderer.secondaryMap = null;
4047
object.renderer.shaderUniforms = {
4048
u_ambientDark: dark,
4049
u_litNW: lit.nw,
4050
u_litNE: lit.ne,
4051
u_litSW: lit.sw,
4052
u_litSE: lit.se,
4053
u_time: timeSec,
4054
u_tileX: tileX | 0,
4055
u_tileY: tileY | 0,
4056
u_edgeN: edges?.n ?? 0,
4057
u_edgeE: edges?.e ?? 0,
4058
u_edgeS: edges?.s ?? 0,
4059
u_edgeW: edges?.w ?? 0,
4060
u_edgeNE: edges?.ne ?? 0,
4061
u_edgeNW: edges?.nw ?? 0,
4062
u_edgeSE: edges?.se ?? 0,
4063
u_edgeSW: edges?.sw ?? 0,
4064
...lavaDebugUniforms()
4065
};
4066
}
4067
4068
#syncLavaBloomSprite (object, {
4069
edges = null,
4070
timeSec = 0,
4071
tileX = 0,
4072
tileY = 0
4073
} = {})
4074
{
4075
if (!object?.renderer)
4076
{ return; }
4077
object.renderer.shader = getLavaBloomShader();
4078
object.renderer.shaderUniforms = {
4079
u_time: timeSec,
4080
u_tileX: tileX | 0,
4081
u_tileY: tileY | 0,
4082
u_edgeN: edges?.n ?? 0,
4083
u_edgeE: edges?.e ?? 0,
4084
u_edgeS: edges?.s ?? 0,
4085
u_edgeW: edges?.w ?? 0,
4086
u_edgeNE: edges?.ne ?? 0,
4087
u_edgeNW: edges?.nw ?? 0,
4088
u_edgeSE: edges?.se ?? 0,
4089
u_edgeSW: edges?.sw ?? 0,
4090
...lavaDebugUniforms()
4091
};
4092
}
4093
3632
4094
#ambientDarkness ()
3633
4095
{
3634
4096
const hour = this.nightPreview ?? this.worldHour;
@@ -4360,11 +4822,14 @@ export class WorldView
4360
4822
const timeSec = performance.now() / 1000;
4361
4823
for (const objects of this.tiles.values())
4362
4824
{
4363
if (!objects.ground || !isWaterGround(objects.groundTypeId))
4825
if (!objects.ground)
4826
{ continue; }
4827
const fluid = isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId);
4828
if (!fluid)
4364
4829
{ continue; }
4365
4830
if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)
4366
4831
{ continue; }
4367
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
4832
// Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.
4368
4833
this.#syncGroundWaterFx(objects, 1, timeSec);
4369
4834
}
4370
4835
}
@@ -4409,7 +4874,7 @@ export class WorldView
4409
4874
}
4410
4875
if (animatedGround.bloom)
4411
4876
{ objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }
4412
else
4877
else if (!isLavaGround(animatedGround.typeId))
4413
4878
{
4414
4879
objects.groundBloom?.destroy();
4415
4880
objects.groundBloom = null;
@@ -4421,6 +4886,7 @@ export class WorldView
4421
4886
objects.ground = null;
4422
4887
objects.groundBloom?.destroy();
4423
4888
objects.groundBloom = null;
4889
this.#clearLavaBloom(objects);
4424
4890
objects.groundTypeId = null;
4425
4891
objects.waterEdges = null;
4426
4892
}
@@ -4719,27 +5185,33 @@ export class WorldView
4719
5185
);
4720
5186
}
4721
5187
4722
/** Authored torches/furnaces in chunks that can light the active 3×3 (or all chunks in editor). */
5188
/** Authored torches/furnaces/lava in chunks that can light the active 3×3 (or all chunks in editor). */
4723
5189
#collectBlockLightsForShading ()
4724
5190
{
4725
5191
const center = this.#activeLightingCenterChunk();
4726
5192
const maxRange = maxBlockLightRangeTiles();
4727
5193
const halo = Math.ceil(maxRange / CHUNK_SIZE) + 1;
4728
5194
const sources = [];
5195
const pushChunk = (snapshot) =>
5196
{
5197
if (!snapshot)
5198
{ return; }
5199
if (snapshot.blocks)
5200
{ sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }
5201
if (snapshot.grounds)
5202
{ sources.push(...collectGroundLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.grounds)); }
5203
};
4729
5204
if (!center)
4730
5205
{
4731
5206
for (const snapshot of this.chunks.values())
4732
{ sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }
5207
{ pushChunk(snapshot); }
4733
5208
return sources;
4734
5209
}
4735
5210
for (let dy = -1 - halo; dy <= 1 + halo; dy++)
4736
5211
{
4737
5212
for (let dx = -1 - halo; dx <= 1 + halo; dx++)
4738
5213
{
4739
const snapshot = this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`);
4740
if (!snapshot?.blocks)
4741
{ continue; }
4742
sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks));
5214
pushChunk(this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`));
4743
5215
}
4744
5216
}
4745
5217
return sources;
@@ -4867,14 +5339,17 @@ export class WorldView
4867
5339
else
4868
5340
{ this.#syncLitSprite(objects.block, objects.shadeAlpha); }
4869
5341
}
4870
if (objects.ground && isWaterGround(objects.groundTypeId))
5342
if (objects.ground && (isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId)))
4871
5343
{
4872
5344
const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);
4873
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.
5345
// Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.
4874
5346
this.#syncGroundWaterFx(objects, 1, timeSec, baked);
4875
5347
}
4876
5348
else if (objects.ground)
4877
{ this.#syncLitSprite(objects.ground, objects.shadeAlpha); }
5349
{
5350
this.#clearLavaBloom(objects);
5351
this.#syncLitSprite(objects.ground, objects.shadeAlpha);
5352
}
4878
5353
}
4879
5354
4880
5355
for (const item of this.groundItems.values())
@@ -2,7 +2,7 @@ import { CHUNK_SIZE, SPRITE_SIZE_PX, GAIT, DEFAULT_WORLD_SETTINGS, PIVOT_FROM_BO2
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";2
import { dynamicLightAtTile, dynamicDarknessAtTile, lightIntensity } from "/shared/lighting/raycast.js";3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";3
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";4
import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";4
import { bakeChunkOcclusion, tileLightOcclusionAt } from "/shared/lighting/chunkOcclusion.js";5
import { collectBlockLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";5
import { collectBlockLightSources, collectGroundLightSources, maxBlockLightRangeTiles } from "/shared/lighting/blockLights.js";6
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";6
import { smoothLitCorner } from "/shared/lighting/lightCorners.js";7
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";7
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";8
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";8
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemSpriteNameForStack, itemDefinition } from "/shared/definitions/items.js";@@ -16,7 +16,7 @@ import16
} from "/shared/render/tint.js";16
} from "/shared/render/tint.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";@@ -27,7 +27,7 @@ import27
invalidateCanvasTexture27
invalidateCanvasTexture28
} from "./canvasSprite.js";28
} from "./canvasSprite.js";29
import { setNearestFilter } from "./sprites.js";29
import { setNearestFilter } from "./sprites.js";30
import { waterDebugUniforms } from "../play/waterDebug.js";30
import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";31
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";31
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";32
import32
import33
{33
{@@ -168,6 +168,8 @@ const WATER_GROUND_FRAG = [168
"uniform float u_normalEps;",168
"uniform float u_normalEps;",169
"uniform float u_foamStrength;",169
"uniform float u_foamStrength;",170
"uniform float u_shoreClip;",170
"uniform float u_shoreClip;",171
"uniform float u_deepDark;",172
"uniform float u_deepAbrupt;",171
// 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).173
// 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).172
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",174
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",173
"vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",175
"vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",@@ -283,10 +285,12 @@ const WATER_GROUND_FRAG = [283
" float deepTop = mix(u_deepNW, u_deepNE, puv.x);",285
" float deepTop = mix(u_deepNW, u_deepNE, puv.x);",284
" float deepBot = mix(u_deepSW, u_deepSE, puv.x);",286
" float deepBot = mix(u_deepSW, u_deepSE, puv.x);",285
" float deepMix = mix(deepTop, deepBot, puv.y);",287
" float deepMix = mix(deepTop, deepBot, puv.y);",286
" vec3 deepCol = mix(vec3(0.12, 0.34, 0.54), vec3(0.07, 0.22, 0.42), deepMix);",288
" float deepAmt = pow(clamp(deepMix, 0.0, 1.0), max(u_deepAbrupt, 0.05));",287
" vec3 midCol = mix(vec3(0.24, 0.52, 0.70), vec3(0.12, 0.34, 0.54), deepMix);",289
" float darkW = clamp(u_deepDark, 0.0, 1.0);",288
" vec3 litCol = mix(vec3(0.52, 0.78, 0.90), vec3(0.30, 0.52, 0.72), deepMix);",290
" vec3 deepCol = mix(vec3(0.12, 0.34, 0.54), mix(vec3(0.05, 0.16, 0.34), vec3(0.015, 0.055, 0.14), darkW), deepAmt);",289
" vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), vec3(0.78, 0.92, 1.0), deepMix);",291
" vec3 midCol = mix(vec3(0.24, 0.52, 0.70), mix(vec3(0.10, 0.30, 0.50), vec3(0.04, 0.14, 0.28), darkW), deepAmt);",292
" vec3 litCol = mix(vec3(0.52, 0.78, 0.90), mix(vec3(0.26, 0.46, 0.66), vec3(0.12, 0.28, 0.46), darkW), deepAmt);",293
" vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), mix(vec3(0.72, 0.88, 0.98), vec3(0.48, 0.68, 0.86), darkW), deepAmt);",290
" vec3 foamCol = vec3(0.94, 0.99, 1.0);",294
" vec3 foamCol = vec3(0.94, 0.99, 1.0);",291
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",295
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",292
" vec3 rgb = mix(deepCol, midCol, smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody));",296
" vec3 rgb = mix(deepCol, midCol, smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody));",@@ -337,6 +341,275 @@ const WATER_GROUND_FRAG = [337
"}"341
"}"338
].join("\n");342
].join("\n");339
343
344
/** Lava heat: dark red → red → orange → yellow; yellow drives bloom companion. */345
const LAVA_FBM_COMMON = [346
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",347
"vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",348
"vec4 permute(vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }",349
"vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }",350
"float snoise(vec3 v) {",351
" vec2 C = vec2(1.0 / 6.0, 1.0 / 3.0);",352
" vec4 D = vec4(0.0, 0.5, 1.0, 2.0);",353
" vec3 i = floor(v + dot(v, C.yyy));",354
" vec3 x0 = v - i + dot(i, C.xxx);",355
" vec3 g = step(x0.yzx, x0.xyz);",356
" vec3 l = 1.0 - g;",357
" vec3 i1 = min(g.xyz, l.zxy);",358
" vec3 i2 = max(g.xyz, l.zxy);",359
" vec3 x1 = x0 - i1 + C.xxx;",360
" vec3 x2 = x0 - i2 + C.yyy;",361
" vec3 x3 = x0 - D.yyy;",362
" i = mod289(i);",363
" vec4 p = permute(permute(permute(",364
" i.z + vec4(0.0, i1.z, i2.z, 1.0))",365
" + i.y + vec4(0.0, i1.y, i2.y, 1.0))",366
" + i.x + vec4(0.0, i1.x, i2.x, 1.0));",367
" float n_ = 0.142857142857;",368
" vec3 ns = n_ * D.wyz - D.xzx;",369
" vec4 j = p - 49.0 * floor(p * ns.z * ns.z);",370
" vec4 x_ = floor(j * ns.z);",371
" vec4 y_ = floor(j - 7.0 * x_);",372
" vec4 x = x_ * ns.x + ns.yyyy;",373
" vec4 y = y_ * ns.x + ns.yyyy;",374
" vec4 h = 1.0 - abs(x) - abs(y);",375
" vec4 b0 = vec4(x.xy, y.xy);",376
" vec4 b1 = vec4(x.zw, y.zw);",377
" vec4 s0 = floor(b0) * 2.0 + 1.0;",378
" vec4 s1 = floor(b1) * 2.0 + 1.0;",379
" vec4 sh = -step(h, vec4(0.0));",380
" vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;",381
" vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;",382
" vec3 p0 = vec3(a0.xy, h.x);",383
" vec3 p1 = vec3(a0.zw, h.y);",384
" vec3 p2 = vec3(a1.xy, h.z);",385
" vec3 p3 = vec3(a1.zw, h.w);",386
" vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));",387
" p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;",388
" vec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);",389
" m = m * m;",390
" return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));",391
"}",392
"float fbm(vec3 p) {",393
" float sum = 0.0;",394
" float amp = 0.5;",395
" sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",396
" sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",397
" sum += amp * snoise(p); p *= 2.0; amp *= 0.5;",398
" sum += amp * snoise(p);",399
" return sum;",400
"}",401
"vec2 wrapUv(vec2 uv) {",402
" return fract(uv) * 0.998 + 0.001;",403
"}"404
];405
406
const LAVA_GROUND_FRAG = [407
"precision mediump float;",408
"varying vec2 v_texCoord;",409
"uniform sampler2D u_texture;",410
"uniform float u_alpha;",411
"uniform float u_ambientDark;",412
"uniform float u_litNW;",413
"uniform float u_litNE;",414
"uniform float u_litSW;",415
"uniform float u_litSE;",416
"uniform float u_time;",417
"uniform float u_tileX;",418
"uniform float u_tileY;",419
"uniform float u_edgeN;",420
"uniform float u_edgeE;",421
"uniform float u_edgeS;",422
"uniform float u_edgeW;",423
"uniform float u_edgeNE;",424
"uniform float u_edgeNW;",425
"uniform float u_edgeSE;",426
"uniform float u_edgeSW;",427
"uniform float u_flowX;",428
"uniform float u_flowY;",429
"uniform float u_flowZ;",430
"uniform float u_waveScale;",431
"uniform float u_fbmAmp;",432
"uniform float u_texAmp;",433
"uniform float u_distort;",434
"uniform float u_normalZ;",435
"uniform float u_waveGain;",436
"uniform float u_crestLo;",437
"uniform float u_crestHi;",438
"uniform float u_crestPow;",439
"uniform float u_glitterPow;",440
"uniform float u_crestGlitter;",441
"uniform float u_glitterCap;",442
"uniform float u_glitterMix;",443
"uniform float u_shadeLo;",444
"uniform float u_shadeHi;",445
"uniform float u_bodyLo;",446
"uniform float u_bodyHi;",447
"uniform float u_litLo;",448
"uniform float u_litHi;",449
"uniform float u_litMix;",450
"uniform float u_edgeDark;",451
"uniform float u_lightDirX;",452
"uniform float u_lightDirY;",453
"uniform float u_lightDirZ;",454
"uniform float u_normalEps;",455
...LAVA_FBM_COMMON,456
"void main() {",457
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",458
" vec2 puv = px / 16.0;",459
" vec2 world = vec2(u_tileX, u_tileY) + puv;",460
" float t = u_time;",461
" vec2 flow = vec2(t * u_flowX, t * u_flowY);",462
" float eps = max(u_normalEps, 0.001);",463
" vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",464
" float nC = fbm(base);",465
" float nL = fbm(base + vec3(-eps, 0.0, 0.0));",466
" float nR = fbm(base + vec3(eps, 0.0, 0.0));",467
" float nD = fbm(base + vec3(0.0, -eps, 0.0));",468
" float nU = fbm(base + vec3(0.0, eps, 0.0));",469
" vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",470
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",471
" float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",472
" vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",473
" float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",474
" float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",475
" float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",476
" float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",477
" glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",478
" float edgeProx = 0.0;",479
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",480
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",481
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",482
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",483
" if (u_edgeNE > 0.5) {",484
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",485
" }",486
" if (u_edgeNW > 0.5) {",487
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",488
" }",489
" if (u_edgeSE > 0.5) {",490
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",491
" }",492
" if (u_edgeSW > 0.5) {",493
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",494
" }",495
" float waveBody = wave * (1.0 - edgeProx * 0.55);",496
" float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",497
" heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",498
" heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",499
" vec3 darkRed = vec3(0.16, 0.015, 0.01);",500
" vec3 brightRed = vec3(0.78, 0.08, 0.02);",501
" vec3 orange = vec3(0.98, 0.38, 0.04);",502
" vec3 yellow = vec3(1.0, 0.9, 0.28);",503
" vec3 rgb = mix(darkRed, brightRed, smoothstep(0.0, 0.38, heat));",504
" rgb = mix(rgb, orange, smoothstep(0.28, 0.68, heat));",505
" float yellowAmt = smoothstep(0.55, 0.98, heat);",506
" rgb = mix(rgb, yellow, yellowAmt);",507
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",508
" rgb *= shade;",509
" rgb = mix(rgb, darkRed, edgeProx * u_edgeDark);",510
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",511
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",512
" float lit = mix(litTop, litBottom, v_texCoord.y);",513
" float darkness = u_ambientDark * (1.0 - lit);",514
" rgb = mix(rgb, vec3(0.0), darkness);",515
" gl_FragColor = vec4(rgb, u_alpha);",516
"}"517
].join("\n");518
519
/** Unlit bloom overlay — strength tracks yellow heat (exempt from world darkness). */520
const LAVA_BLOOM_FRAG = [521
"precision mediump float;",522
"varying vec2 v_texCoord;",523
"uniform sampler2D u_texture;",524
"uniform float u_alpha;",525
"uniform float u_time;",526
"uniform float u_tileX;",527
"uniform float u_tileY;",528
"uniform float u_edgeN;",529
"uniform float u_edgeE;",530
"uniform float u_edgeS;",531
"uniform float u_edgeW;",532
"uniform float u_edgeNE;",533
"uniform float u_edgeNW;",534
"uniform float u_edgeSE;",535
"uniform float u_edgeSW;",536
"uniform float u_flowX;",537
"uniform float u_flowY;",538
"uniform float u_flowZ;",539
"uniform float u_waveScale;",540
"uniform float u_fbmAmp;",541
"uniform float u_texAmp;",542
"uniform float u_distort;",543
"uniform float u_normalZ;",544
"uniform float u_waveGain;",545
"uniform float u_crestLo;",546
"uniform float u_crestHi;",547
"uniform float u_crestPow;",548
"uniform float u_glitterPow;",549
"uniform float u_crestGlitter;",550
"uniform float u_glitterCap;",551
"uniform float u_glitterMix;",552
"uniform float u_bodyLo;",553
"uniform float u_bodyHi;",554
"uniform float u_litLo;",555
"uniform float u_litHi;",556
"uniform float u_litMix;",557
"uniform float u_lightDirX;",558
"uniform float u_lightDirY;",559
"uniform float u_lightDirZ;",560
"uniform float u_normalEps;",561
"uniform float u_bloomStrength;",562
...LAVA_FBM_COMMON,563
"void main() {",564
" vec2 px = floor(v_texCoord * 16.0) + 0.5;",565
" vec2 puv = px / 16.0;",566
" vec2 world = vec2(u_tileX, u_tileY) + puv;",567
" float t = u_time;",568
" vec2 flow = vec2(t * u_flowX, t * u_flowY);",569
" float eps = max(u_normalEps, 0.001);",570
" vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",571
" float nC = fbm(base);",572
" float nL = fbm(base + vec3(-eps, 0.0, 0.0));",573
" float nR = fbm(base + vec3(eps, 0.0, 0.0));",574
" float nD = fbm(base + vec3(0.0, -eps, 0.0));",575
" float nU = fbm(base + vec3(0.0, eps, 0.0));",576
" vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",577
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",578
" float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",579
" vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",580
" float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",581
" float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",582
" float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",583
" float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",584
" glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",585
" float edgeProx = 0.0;",586
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",587
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",588
" if (u_edgeW > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.x)); }",589
" if (u_edgeE > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.x)); }",590
" if (u_edgeNE > 0.5) {",591
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, puv.y))));",592
" }",593
" if (u_edgeNW > 0.5) {",594
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, puv.y))));",595
" }",596
" if (u_edgeSE > 0.5) {",597
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(1.0 - puv.x, 1.0 - puv.y))));",598
" }",599
" if (u_edgeSW > 0.5) {",600
" edgeProx = max(edgeProx, 1.0 - smoothstep(0.0, 0.78, length(vec2(puv.x, 1.0 - puv.y))));",601
" }",602
" float waveBody = wave * (1.0 - edgeProx * 0.55);",603
" float heat = smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody);",604
" heat = mix(heat, 1.0, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix * 0.35);",605
" heat = clamp(heat + min(glitter, u_glitterCap) * u_glitterMix * 0.45, 0.0, 1.0);",606
" float yellowAmt = smoothstep(0.55, 0.98, heat) * (1.0 - edgeProx * 0.85);",607
" float bloom = yellowAmt * max(u_bloomStrength, 0.0);",608
" vec3 glow = vec3(1.0, 0.82, 0.28) * bloom;",609
" gl_FragColor = vec4(glow, bloom * u_alpha);",610
"}"611
].join("\n");612
340
/** Magenta-tint (R==B, G < R) then lit effects; darkness always after tint. */613
/** Magenta-tint (R==B, G < R) then lit effects; darkness always after tint. */341
const TINT_LIT_SPRITE_FRAG = [614
const TINT_LIT_SPRITE_FRAG = [342
"precision mediump float;",615
"precision mediump float;",@@ -585,6 +858,8 @@ let spriteLightingShader = null;585
let atlasLightingShader = null;858
let atlasLightingShader = null;586
let cliffGroundTopShader = null;859
let cliffGroundTopShader = null;587
let waterGroundShader = null;860
let waterGroundShader = null;861
let lavaGroundShader = null;862
let lavaBloomShader = null;588
let tintLitSpriteShader = null;863
let tintLitSpriteShader = null;589
let dualTintLitSpriteShader = null;864
let dualTintLitSpriteShader = null;590
let tightFitTintLitSpriteShader = null;865
let tightFitTintLitSpriteShader = null;@@ -618,6 +893,20 @@ function getWaterGroundShader ()618
return waterGroundShader;893
return waterGroundShader;619
}894
}620
895
896
function getLavaGroundShader ()897
{898
if (!lavaGroundShader)899
{ lavaGroundShader = Shader.fragment(LAVA_GROUND_FRAG); }900
return lavaGroundShader;901
}902
903
function getLavaBloomShader ()904
{905
if (!lavaBloomShader)906
{ lavaBloomShader = Shader.fragment(LAVA_BLOOM_FRAG); }907
return lavaBloomShader;908
}909
621
function getTintLitSpriteShader ()910
function getTintLitSpriteShader ()622
{911
{623
if (!tintLitSpriteShader)912
if (!tintLitSpriteShader)@@ -919,6 +1208,7 @@ export class WorldView919
{1208
{920
objects.ground?.destroy();1209
objects.ground?.destroy();921
objects.groundBloom?.destroy();1210
objects.groundBloom?.destroy();1211
objects.lavaBloom?.destroy();922
objects.block?.destroy();1212
objects.block?.destroy();923
objects.blockBloom?.destroy();1213
objects.blockBloom?.destroy();924
this.tiles.delete(tileKey);1214
this.tiles.delete(tileKey);@@ -3584,11 +3874,18 @@ export class WorldView3584
};3874
};3585
}3875
}3586
3876
3587
/** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. */3877
/** Liquid water gets coast foam; frozen shallow ice uses the normal lit sprite. Lava is procedural heat. */3588
#syncGroundWaterFx (objects, ambientDark, timeSec, baked = null)3878
#syncGroundWaterFx (objects, ambientDark, timeSec, baked = null)3589
{3879
{3590
if (!objects?.ground)3880
if (!objects?.ground)3591
{ return; }3881
{ return; }3882
if (isLavaGround(objects.groundTypeId))3883
{3884
objects.waterEdges = null;3885
this.#syncLavaGroundFx(objects, ambientDark, timeSec, baked);3886
return;3887
}3888
this.#clearLavaBloom(objects);3592
if (!isLiquidWaterGround(objects.groundTypeId, this.worldSeason))3889
if (!isLiquidWaterGround(objects.groundTypeId, this.worldSeason))3593
{3890
{3594
objects.waterEdges = null;3891
objects.waterEdges = null;@@ -3629,6 +3926,171 @@ export class WorldView3629
});3926
});3630
}3927
}3631
3928
3929
#lavaCoastEdges (tileX, tileY)3930
{3931
const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));3932
const n = lava(tileX, tileY - 1);3933
const e = lava(tileX + 1, tileY);3934
const s = lava(tileX, tileY + 1);3935
const w = lava(tileX - 1, tileY);3936
const ne = lava(tileX + 1, tileY - 1);3937
const nw = lava(tileX - 1, tileY - 1);3938
const se = lava(tileX + 1, tileY + 1);3939
const sw = lava(tileX - 1, tileY + 1);3940
return {3941
n: n ? 0 : 1,3942
e: e ? 0 : 1,3943
s: s ? 0 : 1,3944
w: w ? 0 : 1,3945
ne: (!ne && n && e) ? 1 : 0,3946
nw: (!nw && n && w) ? 1 : 0,3947
se: (!se && s && e) ? 1 : 0,3948
sw: (!sw && s && w) ? 1 : 03949
};3950
}3951
3952
#clearLavaBloom (objects)3953
{3954
if (!objects)3955
{ return; }3956
objects.lavaBloom?.destroy();3957
objects.lavaBloom = null;3958
}3959
3960
#ensureLavaBloom (objects)3961
{3962
const sprite = objects.ground?.renderer?.sprite;3963
if (!sprite)3964
{ return null; }3965
if (!objects.lavaBloom)3966
{3967
const bloom = new GameObject(0, 0, sprite, LAYER_GROUND);3968
bloom.renderer.layer = RENDER_LAYER_BLOOM;3969
this.#markUnlit(bloom);3970
this.scene.addObject(bloom);3971
objects.lavaBloom = bloom;3972
}3973
else if (objects.lavaBloom.renderer)3974
{ objects.lavaBloom.renderer.sprite = sprite; }3975
const size = this.tileSize();3976
objects.lavaBloom.transform.position.x = objects.tileX * size + size / 2;3977
objects.lavaBloom.transform.position.y = objects.tileY * size + size / 2;3978
objects.lavaBloom.transform.size = new vector(size, size);3979
this.#setLayer(objects.lavaBloom, LAYER_GROUND);3980
return objects.lavaBloom;3981
}3982
3983
#syncLavaGroundFx (objects, ambientDark, timeSec, baked = null)3984
{3985
const fallbackLit = 1 - (objects.shadeAlpha ?? 0);3986
const chunkX = Math.floor(objects.tileX / CHUNK_SIZE);3987
const chunkY = Math.floor(objects.tileY / CHUNK_SIZE);3988
const chunkBaked = baked ?? this.bakedChunks.get(`${chunkX},${chunkY}`);3989
const localX = objects.tileX - chunkX * CHUNK_SIZE;3990
const localY = objects.tileY - chunkY * CHUNK_SIZE;3991
let litCorners = null;3992
if (chunkBaked)3993
{3994
if (this.lightingMode === "simple")3995
{3996
const gridW = CHUNK_SIZE + 2;3997
const intensity = chunkBaked.lightIntensityGrid?.[(localY + 1) * gridW + (localX + 1)] ?? fallbackLit;3998
litCorners = { nw: intensity, ne: intensity, sw: intensity, se: intensity };3999
}4000
else4001
{ litCorners = this.#tileLitCorners(chunkBaked, localX, localY); }4002
}4003
const edges = this.#lavaCoastEdges(objects.tileX, objects.tileY);4004
this.#syncLavaGroundSprite(objects.ground, {4005
corners: litCorners,4006
ambientDark,4007
edges,4008
timeSec,4009
fallbackLit,4010
tileX: objects.tileX,4011
tileY: objects.tileY4012
});4013
const bloom = this.#ensureLavaBloom(objects);4014
if (bloom)4015
{4016
this.#syncLavaBloomSprite(bloom, {4017
edges,4018
timeSec,4019
tileX: objects.tileX,4020
tileY: objects.tileY4021
});4022
}4023
}4024
4025
#syncLavaGroundSprite (object, {4026
corners = null,4027
ambientDark = 0,4028
edges = null,4029
timeSec = 0,4030
fallbackLit = 1,4031
tileX = 0,4032
tileY = 04033
} = {})4034
{4035
if (!object?.renderer)4036
{ return; }4037
const lit = corners ?? {4038
nw: fallbackLit,4039
ne: fallbackLit,4040
sw: fallbackLit,4041
se: fallbackLit4042
};4043
const dark = Math.min(1, Math.max(0, ambientDark ?? 0));4044
object._lit = true;4045
object.renderer.shader = getLavaGroundShader();4046
object.renderer.secondaryMap = null;4047
object.renderer.shaderUniforms = {4048
u_ambientDark: dark,4049
u_litNW: lit.nw,4050
u_litNE: lit.ne,4051
u_litSW: lit.sw,4052
u_litSE: lit.se,4053
u_time: timeSec,4054
u_tileX: tileX | 0,4055
u_tileY: tileY | 0,4056
u_edgeN: edges?.n ?? 0,4057
u_edgeE: edges?.e ?? 0,4058
u_edgeS: edges?.s ?? 0,4059
u_edgeW: edges?.w ?? 0,4060
u_edgeNE: edges?.ne ?? 0,4061
u_edgeNW: edges?.nw ?? 0,4062
u_edgeSE: edges?.se ?? 0,4063
u_edgeSW: edges?.sw ?? 0,4064
...lavaDebugUniforms()4065
};4066
}4067
4068
#syncLavaBloomSprite (object, {4069
edges = null,4070
timeSec = 0,4071
tileX = 0,4072
tileY = 04073
} = {})4074
{4075
if (!object?.renderer)4076
{ return; }4077
object.renderer.shader = getLavaBloomShader();4078
object.renderer.shaderUniforms = {4079
u_time: timeSec,4080
u_tileX: tileX | 0,4081
u_tileY: tileY | 0,4082
u_edgeN: edges?.n ?? 0,4083
u_edgeE: edges?.e ?? 0,4084
u_edgeS: edges?.s ?? 0,4085
u_edgeW: edges?.w ?? 0,4086
u_edgeNE: edges?.ne ?? 0,4087
u_edgeNW: edges?.nw ?? 0,4088
u_edgeSE: edges?.se ?? 0,4089
u_edgeSW: edges?.sw ?? 0,4090
...lavaDebugUniforms()4091
};4092
}4093
3632
#ambientDarkness ()4094
#ambientDarkness ()3633
{4095
{3634
const hour = this.nightPreview ?? this.worldHour;4096
const hour = this.nightPreview ?? this.worldHour;@@ -4360,11 +4822,14 @@ export class WorldView4360
const timeSec = performance.now() / 1000;4822
const timeSec = performance.now() / 1000;4361
for (const objects of this.tiles.values())4823
for (const objects of this.tiles.values())4362
{4824
{4363
if (!objects.ground || !isWaterGround(objects.groundTypeId))4825
if (!objects.ground)4826
{ continue; }4827
const fluid = isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId);4828
if (!fluid)4364
{ continue; }4829
{ continue; }4365
if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)4830
if (Math.abs(objects.chunkX - chunkX) > 1 || Math.abs(objects.chunkY - chunkY) > 1)4366
{ continue; }4831
{ continue; }4367
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.4832
// Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.4368
this.#syncGroundWaterFx(objects, 1, timeSec);4833
this.#syncGroundWaterFx(objects, 1, timeSec);4369
}4834
}4370
}4835
}@@ -4409,7 +4874,7 @@ export class WorldView4409
}4874
}4410
if (animatedGround.bloom)4875
if (animatedGround.bloom)4411
{ objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }4876
{ objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }4412
else4877
else if (!isLavaGround(animatedGround.typeId))4413
{4878
{4414
objects.groundBloom?.destroy();4879
objects.groundBloom?.destroy();4415
objects.groundBloom = null;4880
objects.groundBloom = null;@@ -4421,6 +4886,7 @@ export class WorldView4421
objects.ground = null;4886
objects.ground = null;4422
objects.groundBloom?.destroy();4887
objects.groundBloom?.destroy();4423
objects.groundBloom = null;4888
objects.groundBloom = null;4889
this.#clearLavaBloom(objects);4424
objects.groundTypeId = null;4890
objects.groundTypeId = null;4425
objects.waterEdges = null;4891
objects.waterEdges = null;4426
}4892
}@@ -4719,27 +5185,33 @@ export class WorldView4719
);5185
);4720
}5186
}4721
5187
4722
/** Authored torches/furnaces in chunks that can light the active 3×3 (or all chunks in editor). */5188
/** Authored torches/furnaces/lava in chunks that can light the active 3×3 (or all chunks in editor). */4723
#collectBlockLightsForShading ()5189
#collectBlockLightsForShading ()4724
{5190
{4725
const center = this.#activeLightingCenterChunk();5191
const center = this.#activeLightingCenterChunk();4726
const maxRange = maxBlockLightRangeTiles();5192
const maxRange = maxBlockLightRangeTiles();4727
const halo = Math.ceil(maxRange / CHUNK_SIZE) + 1;5193
const halo = Math.ceil(maxRange / CHUNK_SIZE) + 1;4728
const sources = [];5194
const sources = [];5195
const pushChunk = (snapshot) =>5196
{5197
if (!snapshot)5198
{ return; }5199
if (snapshot.blocks)5200
{ sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }5201
if (snapshot.grounds)5202
{ sources.push(...collectGroundLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.grounds)); }5203
};4729
if (!center)5204
if (!center)4730
{5205
{4731
for (const snapshot of this.chunks.values())5206
for (const snapshot of this.chunks.values())4732
{ sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks)); }5207
{ pushChunk(snapshot); }4733
return sources;5208
return sources;4734
}5209
}4735
for (let dy = -1 - halo; dy <= 1 + halo; dy++)5210
for (let dy = -1 - halo; dy <= 1 + halo; dy++)4736
{5211
{4737
for (let dx = -1 - halo; dx <= 1 + halo; dx++)5212
for (let dx = -1 - halo; dx <= 1 + halo; dx++)4738
{5213
{4739
const snapshot = this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`);5214
pushChunk(this.chunks.get(`${center.chunkX + dx},${center.chunkY + dy}`));4740
if (!snapshot?.blocks)4741
{ continue; }4742
sources.push(...collectBlockLightSources(snapshot.chunkX, snapshot.chunkY, snapshot.blocks));4743
}5215
}4744
}5216
}4745
return sources;5217
return sources;@@ -4867,14 +5339,17 @@ export class WorldView4867
else5339
else4868
{ this.#syncLitSprite(objects.block, objects.shadeAlpha); }5340
{ this.#syncLitSprite(objects.block, objects.shadeAlpha); }4869
}5341
}4870
if (objects.ground && isWaterGround(objects.groundTypeId))5342
if (objects.ground && (isWaterGround(objects.groundTypeId) || isLavaGround(objects.groundTypeId)))4871
{5343
{4872
const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);5344
const baked = this.bakedChunks.get(`${objects.chunkX},${objects.chunkY}`);4873
// Light intensity grid is visible light (1 − shade); water shader uses ambient=1.5345
// Light intensity grid is visible light (1 − shade); fluid shaders use ambient=1.4874
this.#syncGroundWaterFx(objects, 1, timeSec, baked);5346
this.#syncGroundWaterFx(objects, 1, timeSec, baked);4875
}5347
}4876
else if (objects.ground)5348
else if (objects.ground)4877
{ this.#syncLitSprite(objects.ground, objects.shadeAlpha); }5349
{5350
this.#clearLavaBloom(objects);5351
this.#syncLitSprite(objects.ground, objects.shadeAlpha);5352
}4878
}5353
}4879
5354
4880
for (const item of this.groundItems.values())5355
for (const item of this.groundItems.values())@@ -1,8 +1,7 @@
1
import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock } from "../../../shared/definitions/tiles.js";
1
import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock, BLOCK_DEFINITIONS, GROUND_DEFINITIONS } from "../../../shared/definitions/tiles.js";
2
2
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";
3
3
import { localToTile } from "../world/coordinates.js";
4
4
import { cloneChunkData, createEmptyChunkData, decodeChunkBlob, encodeChunkBlob, normalizeSpawner } from "../world/chunkData.js";
5
import { BLOCK_DEFINITIONS } from "../../../shared/definitions/tiles.js";
6
5
import { bakeLightMaps, maxDefinitionLightRange } from "../lighting/baker.js";
7
6
import { closedNeighborEdges } from "../world/chunkFlags.js";
8
7
import { coerceSettingValue, diffSettings, diffItemSeedValues, allSettingFields, itemSeedMapsEqual } from "../../../shared/definitions/worldSettings.js";
@@ -101,7 +100,7 @@ export class EditorService
101
100
chunkX,
102
101
chunkY,
103
102
(x, y) => this.#loadForBake(x, y, revisionId, defaultGroundTypeId, chunkX, chunkY, next, dimId),
104
maxDefinitionLightRange(BLOCK_DEFINITIONS)
103
maxDefinitionLightRange(BLOCK_DEFINITIONS, GROUND_DEFINITIONS)
105
104
);
106
105
107
106
for (const result of baked)
@@ -1,8 +1,7 @@1
import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock } from "../../../shared/definitions/tiles.js";1
import { groundDefinition, blockDefinition, normalizeGround, normalizeBlock, BLOCK_DEFINITIONS, GROUND_DEFINITIONS } from "../../../shared/definitions/tiles.js";2
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";2
import { CHUNK_SIZE } from "../../../shared/protocol/constants.js";3
import { localToTile } from "../world/coordinates.js";3
import { localToTile } from "../world/coordinates.js";4
import { cloneChunkData, createEmptyChunkData, decodeChunkBlob, encodeChunkBlob, normalizeSpawner } from "../world/chunkData.js";4
import { cloneChunkData, createEmptyChunkData, decodeChunkBlob, encodeChunkBlob, normalizeSpawner } from "../world/chunkData.js";5
import { BLOCK_DEFINITIONS } from "../../../shared/definitions/tiles.js";6
import { bakeLightMaps, maxDefinitionLightRange } from "../lighting/baker.js";5
import { bakeLightMaps, maxDefinitionLightRange } from "../lighting/baker.js";7
import { closedNeighborEdges } from "../world/chunkFlags.js";6
import { closedNeighborEdges } from "../world/chunkFlags.js";8
import { coerceSettingValue, diffSettings, diffItemSeedValues, allSettingFields, itemSeedMapsEqual } from "../../../shared/definitions/worldSettings.js";7
import { coerceSettingValue, diffSettings, diffItemSeedValues, allSettingFields, itemSeedMapsEqual } from "../../../shared/definitions/worldSettings.js";@@ -101,7 +100,7 @@ export class EditorService101
chunkX,100
chunkX,102
chunkY,101
chunkY,103
(x, y) => this.#loadForBake(x, y, revisionId, defaultGroundTypeId, chunkX, chunkY, next, dimId),102
(x, y) => this.#loadForBake(x, y, revisionId, defaultGroundTypeId, chunkX, chunkY, next, dimId),104
maxDefinitionLightRange(BLOCK_DEFINITIONS)103
maxDefinitionLightRange(BLOCK_DEFINITIONS, GROUND_DEFINITIONS)105
);104
);106
105
107
for (const result of baked)106
for (const result of baked)@@ -6,11 +6,16 @@ import { cloneChunkData, collectLightSources, createEmptyChunkData, chunkTileLig
6
6
7
7
export { bresenhamTiles, encodeLight, falloffAtDistance, lightIntensity, rayReaches } from "../../../shared/lighting/raycast.js";
8
8
9
export function maxDefinitionLightRange (blockDefs)
9
export function maxDefinitionLightRange (blockDefs, groundDefs = null)
10
10
{
11
11
let max = 0;
12
for (const def of Object.values(blockDefs))
12
for (const def of Object.values(blockDefs ?? {}))
13
13
{ max = Math.max(max, def.lightRangeTiles ?? 0); }
14
if (groundDefs)
15
{
16
for (const def of Object.values(groundDefs))
17
{ max = Math.max(max, def.lightRangeTiles ?? 0); }
18
}
14
19
return max;
15
20
}
16
21
@@ -6,11 +6,16 @@ import { cloneChunkData, collectLightSources, createEmptyChunkData, chunkTileLig6
6
7
export { bresenhamTiles, encodeLight, falloffAtDistance, lightIntensity, rayReaches } from "../../../shared/lighting/raycast.js";7
export { bresenhamTiles, encodeLight, falloffAtDistance, lightIntensity, rayReaches } from "../../../shared/lighting/raycast.js";8
8
9
export function maxDefinitionLightRange (blockDefs)9
export function maxDefinitionLightRange (blockDefs, groundDefs = null)10
{10
{11
let max = 0;11
let max = 0;12
for (const def of Object.values(blockDefs))12
for (const def of Object.values(blockDefs ?? {}))13
{ max = Math.max(max, def.lightRangeTiles ?? 0); }13
{ max = Math.max(max, def.lightRangeTiles ?? 0); }14
if (groundDefs)15
{16
for (const def of Object.values(groundDefs))17
{ max = Math.max(max, def.lightRangeTiles ?? 0); }18
}14
return max;19
return max;15
}20
}16
21
@@ -12,7 +12,7 @@ import {
12
12
} from "../../../shared/definitions/tiles.js";
13
13
import { isDoorTraversable } from "../../../shared/world/doors.js";
14
14
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";
15
import { collectBlockLightSources } from "../../../shared/lighting/blockLights.js";
15
import { collectBlockLightSources, collectGroundLightSources } from "../../../shared/lighting/blockLights.js";
16
16
import {
17
17
flowerBlockState,
18
18
flowerColorIdFromBlockState,
@@ -211,7 +211,10 @@ export function isChunkTileClearForRangedAttacks (data, localX, localY)
211
211
212
212
export function collectLightSources (chunkX, chunkY, data)
213
213
{
214
return collectBlockLightSources(chunkX, chunkY, data?.blocks);
214
return [
215
...collectBlockLightSources(chunkX, chunkY, data?.blocks),
216
...collectGroundLightSources(chunkX, chunkY, data?.grounds)
217
];
215
218
}
216
219
217
220
function migrateLegacySpawners (blocks, authored, parsedHint)
@@ -12,7 +12,7 @@ import {12
} from "../../../shared/definitions/tiles.js";12
} from "../../../shared/definitions/tiles.js";13
import { isDoorTraversable } from "../../../shared/world/doors.js";13
import { isDoorTraversable } from "../../../shared/world/doors.js";14
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";14
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";15
import { collectBlockLightSources } from "../../../shared/lighting/blockLights.js";15
import { collectBlockLightSources, collectGroundLightSources } from "../../../shared/lighting/blockLights.js";16
import {16
import {17
flowerBlockState,17
flowerBlockState,18
flowerColorIdFromBlockState,18
flowerColorIdFromBlockState,@@ -211,7 +211,10 @@ export function isChunkTileClearForRangedAttacks (data, localX, localY)211
211
212
export function collectLightSources (chunkX, chunkY, data)212
export function collectLightSources (chunkX, chunkY, data)213
{213
{214
return collectBlockLightSources(chunkX, chunkY, data?.blocks);214
return [215
...collectBlockLightSources(chunkX, chunkY, data?.blocks),216
...collectGroundLightSources(chunkX, chunkY, data?.grounds)217
];215
}218
}216
219
217
function migrateLegacySpawners (blocks, authored, parsedHint)220
function migrateLegacySpawners (blocks, authored, parsedHint)@@ -4,9 +4,9 @@ import { createEmptyChunkData } from "../src/world/chunkData.js";
4
4
import { bakeLightMaps } from "../src/lighting/baker.js";
5
5
import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";
6
6
import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";
7
import { collectBlockLightSources } from "../../shared/lighting/blockLights.js";
7
import { collectBlockLightSources, collectGroundLightSources } from "../../shared/lighting/blockLights.js";
8
8
import { tileLightOcclusionAt, bakeChunkOcclusion } from "../../shared/lighting/chunkOcclusion.js";
9
import { BlockType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";
9
import { BlockType, GroundType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";
10
10
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";
11
11
import { tileLightAt } from "../src/combat/service.js";
12
12
import { maybeOpenDoorOnApproach } from "../src/doors/service.js";
@@ -235,6 +235,17 @@ test("collectBlockLightSources finds torches", () =>
235
235
assert.ok(sources[0].range > 0);
236
236
});
237
237
238
test("collectGroundLightSources finds lava", () =>
239
{
240
const data = createEmptyChunkData();
241
data.grounds[0] = { typeId: GroundType.lava, state: null };
242
const sources = collectGroundLightSources(0, 0, data.grounds);
243
assert.equal(sources.length, 1);
244
assert.equal(sources[0].tileX, 0);
245
assert.equal(sources[0].tileY, 0);
246
assert.equal(sources[0].range, 4);
247
});
248
238
249
test("dynamic block light is blocked by a resting door and passes when passage-open", () =>
239
250
{
240
251
const chunks = new Map();
@@ -4,9 +4,9 @@ import { createEmptyChunkData } from "../src/world/chunkData.js";4
import { bakeLightMaps } from "../src/lighting/baker.js";4
import { bakeLightMaps } from "../src/lighting/baker.js";5
import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";5
import { bresenhamTiles, dynamicLightAtTile, evaluateLightRay, rayReaches } from "../../shared/lighting/raycast.js";6
import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";6
import { makeSnapshotLightOcclusion } from "../../shared/lighting/tilePassable.js";7
import { collectBlockLightSources } from "../../shared/lighting/blockLights.js";7
import { collectBlockLightSources, collectGroundLightSources } from "../../shared/lighting/blockLights.js";8
import { tileLightOcclusionAt, bakeChunkOcclusion } from "../../shared/lighting/chunkOcclusion.js";8
import { tileLightOcclusionAt, bakeChunkOcclusion } from "../../shared/lighting/chunkOcclusion.js";9
import { BlockType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";9
import { BlockType, GroundType, blockLightOcclusionForBlock, LightOcclusion } from "../../shared/definitions/tiles.js";10
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";10
import { CHUNK_SIZE } from "../../shared/protocol/constants.js";11
import { tileLightAt } from "../src/combat/service.js";11
import { tileLightAt } from "../src/combat/service.js";12
import { maybeOpenDoorOnApproach } from "../src/doors/service.js";12
import { maybeOpenDoorOnApproach } from "../src/doors/service.js";@@ -235,6 +235,17 @@ test("collectBlockLightSources finds torches", () =>235
assert.ok(sources[0].range > 0);235
assert.ok(sources[0].range > 0);236
});236
});237
237
238
test("collectGroundLightSources finds lava", () =>239
{240
const data = createEmptyChunkData();241
data.grounds[0] = { typeId: GroundType.lava, state: null };242
const sources = collectGroundLightSources(0, 0, data.grounds);243
assert.equal(sources.length, 1);244
assert.equal(sources[0].tileX, 0);245
assert.equal(sources[0].tileY, 0);246
assert.equal(sources[0].range, 4);247
});248
238
test("dynamic block light is blocked by a resting door and passes when passage-open", () =>249
test("dynamic block light is blocked by a resting door and passes when passage-open", () =>239
{250
{240
const chunks = new Map();251
const chunks = new Map();@@ -1,6 +1,6 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
import { GroundType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, LightOcclusion } from "../../shared/definitions/tiles.js";
3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";
4
4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";
5
5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";
6
6
@@ -30,6 +30,20 @@ test("deep water does not occlude light rays", () =>
30
30
assert.equal(isChunkTilePassable(data, 3, 3), false);
31
31
});
32
32
33
test("lava is impassable, clear for light, and emits half-torch light", () =>
34
{
35
assert.equal(isGroundPassable(GroundType.lava), false);
36
assert.equal(isWaterGround(GroundType.lava), false);
37
assert.equal(groundLightOcclusion(GroundType.lava), LightOcclusion.clear);
38
assert.equal(groundLightRange(GroundType.lava), 4);
39
assert.equal(blockLightRange(BlockType.torch), 8);
40
41
const data = createEmptyChunkData();
42
setGround(data, 4, 4, GroundType.lava);
43
assert.equal(isChunkTilePassable(data, 4, 4), false);
44
assert.equal(isChunkTileClearForLight(data, 4, 4), true);
45
});
46
33
47
test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>
34
48
{
35
49
assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);
@@ -1,6 +1,6 @@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 { GroundType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, LightOcclusion } from "../../shared/definitions/tiles.js";3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";6
6
@@ -30,6 +30,20 @@ test("deep water does not occlude light rays", () =>30
assert.equal(isChunkTilePassable(data, 3, 3), false);30
assert.equal(isChunkTilePassable(data, 3, 3), false);31
});31
});32
32
33
test("lava is impassable, clear for light, and emits half-torch light", () =>34
{35
assert.equal(isGroundPassable(GroundType.lava), false);36
assert.equal(isWaterGround(GroundType.lava), false);37
assert.equal(groundLightOcclusion(GroundType.lava), LightOcclusion.clear);38
assert.equal(groundLightRange(GroundType.lava), 4);39
assert.equal(blockLightRange(BlockType.torch), 8);40
41
const data = createEmptyChunkData();42
setGround(data, 4, 4, GroundType.lava);43
assert.equal(isChunkTilePassable(data, 4, 4), false);44
assert.equal(isChunkTileClearForLight(data, 4, 4), true);45
});46
33
test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>47
test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>34
{48
{35
assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);49
assert.equal(isLiquidWaterGround(GroundType.water, SeasonId.summer), true);