Add shared fluid refresh-rate debug slider for water and lava.
Quantizes shader time to N Hz (0 = smooth) so procedural fluids can match stepped sprite animation cadence.
@@ -3,6 +3,12 @@
3
3
* Export JSON when you land on values you like.
4
4
*/
5
5
6
/** Shared across water + lava (top of debug panel). */
7
export const DEFAULT_FLUID_SHARED = Object.freeze({
8
/** Shader time steps per second; 0 = continuous. */
9
refreshRate: 0
10
});
11
6
12
export const DEFAULT_WATER_DEBUG = Object.freeze({
7
13
flowX: 0.17,
8
14
flowY: 0.05,
@@ -73,6 +79,10 @@ export const DEFAULT_LAVA_DEBUG = Object.freeze({
73
79
shoreClip: 0.55
74
80
});
75
81
82
const SHARED_SLIDERS = [
83
{ key: "refreshRate", label: "Refresh rate (Hz, 0=smooth)", min: 0, max: 24, step: 1 }
84
];
85
76
86
const WATER_SLIDERS = [
77
87
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },
78
88
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },
@@ -109,11 +119,17 @@ const LAVA_SLIDERS = [
109
119
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }
110
120
];
111
121
122
let sharedParams = { ...DEFAULT_FLUID_SHARED };
112
123
let waterParams = { ...DEFAULT_WATER_DEBUG };
113
124
let lavaParams = { ...DEFAULT_LAVA_DEBUG };
114
125
let activeTab = "water";
115
126
let panelEl = null;
116
127
128
export function getFluidSharedParams ()
129
{
130
return { ...sharedParams };
131
}
132
117
133
export function getWaterDebugParams ()
118
134
{
119
135
return { ...waterParams };
@@ -124,6 +140,19 @@ export function getLavaDebugParams ()
124
140
return { ...lavaParams };
125
141
}
126
142
143
/**
144
* Quantized shader clock for water/lava (matches sprite-like refresh when rate > 0).
145
* @param {number} [nowMs]
146
*/
147
export function fluidTimeSec (nowMs = performance.now())
148
{
149
const t = nowMs / 1000;
150
const rate = Number(sharedParams.refreshRate) || 0;
151
if (rate <= 0)
152
{ return t; }
153
return Math.floor(t * rate) / rate;
154
}
155
127
156
function uniformBagFrom (p, extras = {})
128
157
{
129
158
return {
@@ -193,6 +222,12 @@ export function setLavaDebugParams (next)
193
222
syncInputs();
194
223
}
195
224
225
export function setFluidSharedParams (next)
226
{
227
sharedParams = { ...DEFAULT_FLUID_SHARED, ...sharedParams, ...next };
228
syncInputs();
229
}
230
196
231
function activeParams ()
197
232
{
198
233
return activeTab === "lava" ? lavaParams : waterParams;
@@ -207,6 +242,15 @@ function syncInputs ()
207
242
{
208
243
if (!panelEl)
209
244
{ return; }
245
for (const { key } of SHARED_SLIDERS)
246
{
247
const input = panelEl.querySelector(`input[data-fluid-shared="${key}"]`);
248
const valueEl = panelEl.querySelector(`[data-fluid-shared-value="${key}"]`);
249
if (input)
250
{ input.value = String(sharedParams[key]); }
251
if (valueEl)
252
{ valueEl.textContent = Number(sharedParams[key]).toFixed(0); }
253
}
210
254
for (const { key } of activeSliders())
211
255
{
212
256
const input = panelEl.querySelector(`input[data-fluid-key="${key}"]`);
@@ -228,7 +272,11 @@ function syncInputs ()
228
272
function exportJson ()
229
273
{
230
274
const isLava = activeTab === "lava";
231
const text = JSON.stringify(isLava ? getLavaDebugParams() : getWaterDebugParams(), null, 2);
275
const payload = {
276
...getFluidSharedParams(),
277
...(isLava ? getLavaDebugParams() : getWaterDebugParams())
278
};
279
const text = JSON.stringify(payload, null, 2);
232
280
void navigator.clipboard?.writeText(text).catch(() => { });
233
281
const blob = new Blob([text], { type: "application/json" });
234
282
const url = URL.createObjectURL(blob);
@@ -296,6 +344,7 @@ export function initWaterDebugPanel ()
296
344
panelEl = document.createElement("aside");
297
345
panelEl.id = "fluid-debug-panel";
298
346
panelEl.innerHTML = `
347
<div class="fluid-debug-shared"></div>
299
348
<header style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">
300
349
<nav style="display:flex;gap:6px;">
301
350
<button type="button" data-fluid-tab="water">Water</button>
@@ -329,6 +378,34 @@ export function initWaterDebugPanel ()
329
378
pointerEvents: "auto"
330
379
});
331
380
381
const sharedBox = panelEl.querySelector(".fluid-debug-shared");
382
Object.assign(sharedBox.style, {
383
display: "flex",
384
flexDirection: "column",
385
gap: "3px",
386
paddingBottom: "4px",
387
borderBottom: "1px solid rgba(255,255,255,0.12)"
388
});
389
for (const spec of SHARED_SLIDERS)
390
{
391
const row = document.createElement("label");
392
row.style.cssText = "display:grid;grid-template-columns:1fr 48px;gap:2px 6px;align-items:center;";
393
row.innerHTML = `
394
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>
395
<input type="range" data-fluid-shared="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${sharedParams[spec.key]}">
396
<span data-fluid-shared-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(sharedParams[spec.key]).toFixed(0)}</span>
397
`;
398
const input = row.querySelector("input");
399
input.addEventListener("input", () =>
400
{
401
sharedParams[spec.key] = Number(input.value);
402
const valueEl = row.querySelector(`[data-fluid-shared-value="${spec.key}"]`);
403
if (valueEl)
404
{ valueEl.textContent = Number(sharedParams[spec.key]).toFixed(0); }
405
});
406
sharedBox.appendChild(row);
407
}
408
332
409
const scroll = panelEl.querySelector(".fluid-debug-scroll");
333
410
Object.assign(scroll.style, {
334
411
overflowY: "auto",
@@ -368,6 +445,7 @@ export function initWaterDebugPanel ()
368
445
{
369
446
event.preventDefault();
370
447
event.stopPropagation();
448
sharedParams = { ...DEFAULT_FLUID_SHARED };
371
449
if (activeTab === "lava")
372
450
{ lavaParams = { ...DEFAULT_LAVA_DEBUG }; }
373
451
else
@@ -3,6 +3,12 @@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
/** Shared across water + lava (top of debug panel). */7
export const DEFAULT_FLUID_SHARED = Object.freeze({8
/** Shader time steps per second; 0 = continuous. */9
refreshRate: 010
});11
6
export const DEFAULT_WATER_DEBUG = Object.freeze({12
export const DEFAULT_WATER_DEBUG = Object.freeze({7
flowX: 0.17,13
flowX: 0.17,8
flowY: 0.05,14
flowY: 0.05,@@ -73,6 +79,10 @@ export const DEFAULT_LAVA_DEBUG = Object.freeze({73
shoreClip: 0.5579
shoreClip: 0.5574
});80
});75
81
82
const SHARED_SLIDERS = [83
{ key: "refreshRate", label: "Refresh rate (Hz, 0=smooth)", min: 0, max: 24, step: 1 }84
];85
76
const WATER_SLIDERS = [86
const WATER_SLIDERS = [77
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },87
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },78
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },88
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },@@ -109,11 +119,17 @@ const LAVA_SLIDERS = [109
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }119
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }110
];120
];111
121
122
let sharedParams = { ...DEFAULT_FLUID_SHARED };112
let waterParams = { ...DEFAULT_WATER_DEBUG };123
let waterParams = { ...DEFAULT_WATER_DEBUG };113
let lavaParams = { ...DEFAULT_LAVA_DEBUG };124
let lavaParams = { ...DEFAULT_LAVA_DEBUG };114
let activeTab = "water";125
let activeTab = "water";115
let panelEl = null;126
let panelEl = null;116
127
128
export function getFluidSharedParams ()129
{130
return { ...sharedParams };131
}132
117
export function getWaterDebugParams ()133
export function getWaterDebugParams ()118
{134
{119
return { ...waterParams };135
return { ...waterParams };@@ -124,6 +140,19 @@ export function getLavaDebugParams ()124
return { ...lavaParams };140
return { ...lavaParams };125
}141
}126
142
143
/**144
* Quantized shader clock for water/lava (matches sprite-like refresh when rate > 0).145
* @param {number} [nowMs]146
*/147
export function fluidTimeSec (nowMs = performance.now())148
{149
const t = nowMs / 1000;150
const rate = Number(sharedParams.refreshRate) || 0;151
if (rate <= 0)152
{ return t; }153
return Math.floor(t * rate) / rate;154
}155
127
function uniformBagFrom (p, extras = {})156
function uniformBagFrom (p, extras = {})128
{157
{129
return {158
return {@@ -193,6 +222,12 @@ export function setLavaDebugParams (next)193
syncInputs();222
syncInputs();194
}223
}195
224
225
export function setFluidSharedParams (next)226
{227
sharedParams = { ...DEFAULT_FLUID_SHARED, ...sharedParams, ...next };228
syncInputs();229
}230
196
function activeParams ()231
function activeParams ()197
{232
{198
return activeTab === "lava" ? lavaParams : waterParams;233
return activeTab === "lava" ? lavaParams : waterParams;@@ -207,6 +242,15 @@ function syncInputs ()207
{242
{208
if (!panelEl)243
if (!panelEl)209
{ return; }244
{ return; }245
for (const { key } of SHARED_SLIDERS)246
{247
const input = panelEl.querySelector(`input[data-fluid-shared="${key}"]`);248
const valueEl = panelEl.querySelector(`[data-fluid-shared-value="${key}"]`);249
if (input)250
{ input.value = String(sharedParams[key]); }251
if (valueEl)252
{ valueEl.textContent = Number(sharedParams[key]).toFixed(0); }253
}210
for (const { key } of activeSliders())254
for (const { key } of activeSliders())211
{255
{212
const input = panelEl.querySelector(`input[data-fluid-key="${key}"]`);256
const input = panelEl.querySelector(`input[data-fluid-key="${key}"]`);@@ -228,7 +272,11 @@ function syncInputs ()228
function exportJson ()272
function exportJson ()229
{273
{230
const isLava = activeTab === "lava";274
const isLava = activeTab === "lava";231
const text = JSON.stringify(isLava ? getLavaDebugParams() : getWaterDebugParams(), null, 2);275
const payload = {276
...getFluidSharedParams(),277
...(isLava ? getLavaDebugParams() : getWaterDebugParams())278
};279
const text = JSON.stringify(payload, null, 2);232
void navigator.clipboard?.writeText(text).catch(() => { });280
void navigator.clipboard?.writeText(text).catch(() => { });233
const blob = new Blob([text], { type: "application/json" });281
const blob = new Blob([text], { type: "application/json" });234
const url = URL.createObjectURL(blob);282
const url = URL.createObjectURL(blob);@@ -296,6 +344,7 @@ export function initWaterDebugPanel ()296
panelEl = document.createElement("aside");344
panelEl = document.createElement("aside");297
panelEl.id = "fluid-debug-panel";345
panelEl.id = "fluid-debug-panel";298
panelEl.innerHTML = `346
panelEl.innerHTML = `347
<div class="fluid-debug-shared"></div>299
<header style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">348
<header style="display:flex;align-items:center;gap:8px;flex-wrap:wrap;">300
<nav style="display:flex;gap:6px;">349
<nav style="display:flex;gap:6px;">301
<button type="button" data-fluid-tab="water">Water</button>350
<button type="button" data-fluid-tab="water">Water</button>@@ -329,6 +378,34 @@ export function initWaterDebugPanel ()329
pointerEvents: "auto"378
pointerEvents: "auto"330
});379
});331
380
381
const sharedBox = panelEl.querySelector(".fluid-debug-shared");382
Object.assign(sharedBox.style, {383
display: "flex",384
flexDirection: "column",385
gap: "3px",386
paddingBottom: "4px",387
borderBottom: "1px solid rgba(255,255,255,0.12)"388
});389
for (const spec of SHARED_SLIDERS)390
{391
const row = document.createElement("label");392
row.style.cssText = "display:grid;grid-template-columns:1fr 48px;gap:2px 6px;align-items:center;";393
row.innerHTML = `394
<span style="grid-column:1/-1;opacity:0.85">${spec.label}</span>395
<input type="range" data-fluid-shared="${spec.key}" min="${spec.min}" max="${spec.max}" step="${spec.step}" value="${sharedParams[spec.key]}">396
<span data-fluid-shared-value="${spec.key}" style="text-align:right;opacity:0.9">${Number(sharedParams[spec.key]).toFixed(0)}</span>397
`;398
const input = row.querySelector("input");399
input.addEventListener("input", () =>400
{401
sharedParams[spec.key] = Number(input.value);402
const valueEl = row.querySelector(`[data-fluid-shared-value="${spec.key}"]`);403
if (valueEl)404
{ valueEl.textContent = Number(sharedParams[spec.key]).toFixed(0); }405
});406
sharedBox.appendChild(row);407
}408
332
const scroll = panelEl.querySelector(".fluid-debug-scroll");409
const scroll = panelEl.querySelector(".fluid-debug-scroll");333
Object.assign(scroll.style, {410
Object.assign(scroll.style, {334
overflowY: "auto",411
overflowY: "auto",@@ -368,6 +445,7 @@ export function initWaterDebugPanel ()368
{445
{369
event.preventDefault();446
event.preventDefault();370
event.stopPropagation();447
event.stopPropagation();448
sharedParams = { ...DEFAULT_FLUID_SHARED };371
if (activeTab === "lava")449
if (activeTab === "lava")372
{ lavaParams = { ...DEFAULT_LAVA_DEBUG }; }450
{ lavaParams = { ...DEFAULT_LAVA_DEBUG }; }373
else451
else@@ -27,7 +27,7 @@ import
27
27
invalidateCanvasTexture
28
28
} from "./canvasSprite.js";
29
29
import { setNearestFilter } from "./sprites.js";
30
import { waterDebugUniforms, lavaDebugUniforms } from "../play/waterDebug.js";
30
import { waterDebugUniforms, lavaDebugUniforms, fluidTimeSec } from "../play/waterDebug.js";
31
31
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";
32
32
import
33
33
{
@@ -4909,7 +4909,7 @@ export class WorldView
4909
4909
4910
4910
#refreshWaterCoastsNear (chunkX, chunkY)
4911
4911
{
4912
const timeSec = performance.now() / 1000;
4912
const timeSec = fluidTimeSec(performance.now());
4913
4913
for (const objects of this.tiles.values())
4914
4914
{
4915
4915
if (!objects.ground)
@@ -4960,7 +4960,7 @@ export class WorldView
4960
4960
objects.ground.transform.size = new vector(size, size);
4961
4961
this.#setLayer(objects.ground, LAYER_GROUND);
4962
4962
objects.groundTypeId = animatedGround.typeId;
4963
this.#syncGroundWaterFx(objects, 1, performance.now() / 1000);
4963
this.#syncGroundWaterFx(objects, 1, fluidTimeSec());
4964
4964
}
4965
4965
if (animatedGround.bloom)
4966
4966
{ objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }
@@ -5406,7 +5406,7 @@ export class WorldView
5406
5406
}
5407
5407
}
5408
5408
5409
const timeSec = now / 1000;
5409
const timeSec = fluidTimeSec(now);
5410
5410
for (const objects of this.tiles.values())
5411
5411
{
5412
5412
if (objects._inViewport === false)
@@ -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, lavaDebugUniforms } from "../play/waterDebug.js";30
import { waterDebugUniforms, lavaDebugUniforms, fluidTimeSec } 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
{@@ -4909,7 +4909,7 @@ export class WorldView4909
4909
4910
#refreshWaterCoastsNear (chunkX, chunkY)4910
#refreshWaterCoastsNear (chunkX, chunkY)4911
{4911
{4912
const timeSec = performance.now() / 1000;4912
const timeSec = fluidTimeSec(performance.now());4913
for (const objects of this.tiles.values())4913
for (const objects of this.tiles.values())4914
{4914
{4915
if (!objects.ground)4915
if (!objects.ground)@@ -4960,7 +4960,7 @@ export class WorldView4960
objects.ground.transform.size = new vector(size, size);4960
objects.ground.transform.size = new vector(size, size);4961
this.#setLayer(objects.ground, LAYER_GROUND);4961
this.#setLayer(objects.ground, LAYER_GROUND);4962
objects.groundTypeId = animatedGround.typeId;4962
objects.groundTypeId = animatedGround.typeId;4963
this.#syncGroundWaterFx(objects, 1, performance.now() / 1000);4963
this.#syncGroundWaterFx(objects, 1, fluidTimeSec());4964
}4964
}4965
if (animatedGround.bloom)4965
if (animatedGround.bloom)4966
{ objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }4966
{ objects.groundBloom = this.#placeBloomOverlay(objects.groundBloom, animatedGround.bloom, tilePivot(tileX, tileY, this.tileSize()), LAYER_GROUND); }@@ -5406,7 +5406,7 @@ export class WorldView5406
}5406
}5407
}5407
}5408
5408
5409
const timeSec = now / 1000;5409
const timeSec = fluidTimeSec(now);5410
for (const objects of this.tiles.values())5410
for (const objects of this.tiles.values())5411
{5411
{5412
if (objects._inViewport === false)5412
if (objects._inViewport === false)