Add always-on water debug sliders with JSON export.
Expose flow, scale, glitter, shading, light dir, and coast knobs as live uniforms; panel stays visible and can dump the current tune as JSON.
@@ -38,6 +38,7 @@ import { bindHairControls } from "./hairControls.js";
38
38
import { bindCreateClothingControls } from "./createClothingControls.js";
39
39
import { paintCharacterPreview } from "./characterPreview.js";
40
40
import { initGraphicsSettings } from "./graphicsSettings.js";
41
import { initWaterDebugPanel } from "./waterDebug.js";
41
42
import { CraftingStationId } from "/shared/definitions/craftingStations.js";
42
43
import { isOreBoulderState } from "/shared/definitions/materialTiers.js";
43
44
import { formatQuantity } from "/shared/items/formatQuantity.js";
@@ -1831,6 +1832,7 @@ async function main ()
1831
1832
onChange: applyGraphicsSettings,
1832
1833
onSuppressWorldClick: consumeWorldClick
1833
1834
});
1835
initWaterDebugPanel();
1834
1836
social = initSocial({
1835
1837
socket: { send (payload) { socket.send(payload); } },
1836
1838
MessageType,
@@ -38,6 +38,7 @@ import { bindHairControls } from "./hairControls.js";38
import { bindCreateClothingControls } from "./createClothingControls.js";38
import { bindCreateClothingControls } from "./createClothingControls.js";39
import { paintCharacterPreview } from "./characterPreview.js";39
import { paintCharacterPreview } from "./characterPreview.js";40
import { initGraphicsSettings } from "./graphicsSettings.js";40
import { initGraphicsSettings } from "./graphicsSettings.js";41
import { initWaterDebugPanel } from "./waterDebug.js";41
import { CraftingStationId } from "/shared/definitions/craftingStations.js";42
import { CraftingStationId } from "/shared/definitions/craftingStations.js";42
import { isOreBoulderState } from "/shared/definitions/materialTiers.js";43
import { isOreBoulderState } from "/shared/definitions/materialTiers.js";43
import { formatQuantity } from "/shared/items/formatQuantity.js";44
import { formatQuantity } from "/shared/items/formatQuantity.js";@@ -1831,6 +1832,7 @@ async function main ()1831
onChange: applyGraphicsSettings,1832
onChange: applyGraphicsSettings,1832
onSuppressWorldClick: consumeWorldClick1833
onSuppressWorldClick: consumeWorldClick1833
});1834
});1835
initWaterDebugPanel();1834
social = initSocial({1836
social = initSocial({1835
socket: { send (payload) { socket.send(payload); } },1837
socket: { send (payload) { socket.send(payload); } },1836
MessageType,1838
MessageType,@@ -0,0 +1,257 @@
1
/**
2
* Temporary always-on water shader debug panel (simplex FBM tune).
3
* Export JSON when you land on values you like.
4
*/
5
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,
19
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
37
});
38
39
const SLIDERS = [
40
{ 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 },
42
{ key: "flowZ", label: "Flow Z (time)", min: 0, max: 1.5, step: 0.01 },
43
{ 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 },
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 },
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 },
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 },
60
{ 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 },
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 }
70
];
71
72
let params = { ...DEFAULT_WATER_DEBUG };
73
let panelEl = null;
74
75
export function getWaterDebugParams ()
76
{
77
return { ...params };
78
}
79
80
/** Uniform bag for the water ground fragment shader. */
81
export function waterDebugUniforms ()
82
{
83
const p = params;
84
return {
85
u_flowX: p.flowX,
86
u_flowY: p.flowY,
87
u_flowZ: p.flowZ,
88
u_waveScale: p.waveScale,
89
u_fbmAmp: p.fbmAmp,
90
u_texAmp: p.texAmp,
91
u_distort: p.distort,
92
u_normalZ: p.normalZ,
93
u_waveGain: p.waveGain,
94
u_crestLo: p.crestLo,
95
u_crestHi: p.crestHi,
96
u_crestPow: p.crestPow,
97
u_glitterPow: p.glitterPow,
98
u_crestGlitter: p.crestGlitter,
99
u_glitterCap: p.glitterCap,
100
u_glitterMix: p.glitterMix,
101
u_shadeLo: p.shadeLo,
102
u_shadeHi: p.shadeHi,
103
u_bodyLo: p.bodyLo,
104
u_bodyHi: p.bodyHi,
105
u_litLo: p.litLo,
106
u_litHi: p.litHi,
107
u_litMix: p.litMix,
108
u_edgeDark: p.edgeDark,
109
u_lightDirX: p.lightDirX,
110
u_lightDirY: p.lightDirY,
111
u_lightDirZ: p.lightDirZ,
112
u_normalEps: p.normalEps,
113
u_foamStrength: p.foamStrength,
114
u_shoreClip: p.shoreClip
115
};
116
}
117
118
export function setWaterDebugParams (next)
119
{
120
params = { ...DEFAULT_WATER_DEBUG, ...params, ...next };
121
syncInputs();
122
}
123
124
function syncInputs ()
125
{
126
if (!panelEl)
127
{ return; }
128
for (const { key } of SLIDERS)
129
{
130
const input = panelEl.querySelector(`input[data-water-key="${key}"]`);
131
const valueEl = panelEl.querySelector(`[data-water-value="${key}"]`);
132
if (input)
133
{ input.value = String(params[key]); }
134
if (valueEl)
135
{ valueEl.textContent = Number(params[key]).toFixed(3); }
136
}
137
}
138
139
function exportJson ()
140
{
141
const text = JSON.stringify(getWaterDebugParams(), null, 2);
142
void navigator.clipboard?.writeText(text).catch(() => {});
143
const blob = new Blob([text], { type: "application/json" });
144
const url = URL.createObjectURL(blob);
145
const a = document.createElement("a");
146
a.href = url;
147
a.download = "water-debug.json";
148
a.click();
149
URL.revokeObjectURL(url);
150
const status = panelEl?.querySelector("[data-water-export-status]");
151
if (status)
152
{
153
status.textContent = "Exported (+ copied if allowed)";
154
setTimeout(() =>
155
{
156
if (status.textContent.startsWith("Exported"))
157
{ status.textContent = ""; }
158
}, 2000);
159
}
160
}
161
162
/**
163
* Always-visible temporary debug dock (pointer-events on panel only).
164
*/
165
export function initWaterDebugPanel ()
166
{
167
if (panelEl)
168
{ return panelEl; }
169
170
panelEl = document.createElement("aside");
171
panelEl.id = "water-debug-panel";
172
panelEl.innerHTML = `
173
<header>
174
<strong>Water debug</strong>
175
<span data-water-export-status></span>
176
</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>
181
</footer>
182
`;
183
Object.assign(panelEl.style, {
184
position: "fixed",
185
top: "8px",
186
right: "8px",
187
width: "280px",
188
maxHeight: "calc(100vh - 16px)",
189
zIndex: "9999",
190
display: "flex",
191
flexDirection: "column",
192
gap: "6px",
193
padding: "8px",
194
background: "rgba(12, 16, 22, 0.92)",
195
color: "#e8eef5",
196
font: "12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
197
border: "1px solid rgba(255,255,255,0.18)",
198
borderRadius: "6px",
199
boxShadow: "0 8px 24px rgba(0,0,0,0.45)",
200
pointerEvents: "auto"
201
});
202
203
const scroll = panelEl.querySelector(".water-debug-scroll");
204
Object.assign(scroll.style, {
205
overflowY: "auto",
206
flex: "1 1 auto",
207
display: "flex",
208
flexDirection: "column",
209
gap: "4px",
210
paddingRight: "2px"
211
});
212
213
for (const spec of SLIDERS)
214
{
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", () =>
224
{
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); }
229
});
230
scroll.appendChild(row);
231
}
232
233
panelEl.querySelector("[data-water-reset]").addEventListener("click", (event) =>
234
{
235
event.preventDefault();
236
event.stopPropagation();
237
params = { ...DEFAULT_WATER_DEBUG };
238
syncInputs();
239
});
240
panelEl.querySelector("[data-water-export]").addEventListener("click", (event) =>
241
{
242
event.preventDefault();
243
event.stopPropagation();
244
exportJson();
245
});
246
247
for (const type of ["mousedown", "mouseup", "click", "wheel", "contextmenu", "pointerdown"])
248
{
249
panelEl.addEventListener(type, (event) =>
250
{
251
event.stopPropagation();
252
});
253
}
254
255
document.body.appendChild(panelEl);
256
return panelEl;
257
}
@@ -0,0 +1,257 @@1
/**2
* Temporary always-on water shader debug panel (simplex FBM tune).3
* Export JSON when you land on values you like.4
*/5
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,19
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.4237
});38
39
const SLIDERS = [40
{ 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 },42
{ key: "flowZ", label: "Flow Z (time)", min: 0, max: 1.5, step: 0.01 },43
{ 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 },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 },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 },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 },60
{ 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 },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 }70
];71
72
let params = { ...DEFAULT_WATER_DEBUG };73
let panelEl = null;74
75
export function getWaterDebugParams ()76
{77
return { ...params };78
}79
80
/** Uniform bag for the water ground fragment shader. */81
export function waterDebugUniforms ()82
{83
const p = params;84
return {85
u_flowX: p.flowX,86
u_flowY: p.flowY,87
u_flowZ: p.flowZ,88
u_waveScale: p.waveScale,89
u_fbmAmp: p.fbmAmp,90
u_texAmp: p.texAmp,91
u_distort: p.distort,92
u_normalZ: p.normalZ,93
u_waveGain: p.waveGain,94
u_crestLo: p.crestLo,95
u_crestHi: p.crestHi,96
u_crestPow: p.crestPow,97
u_glitterPow: p.glitterPow,98
u_crestGlitter: p.crestGlitter,99
u_glitterCap: p.glitterCap,100
u_glitterMix: p.glitterMix,101
u_shadeLo: p.shadeLo,102
u_shadeHi: p.shadeHi,103
u_bodyLo: p.bodyLo,104
u_bodyHi: p.bodyHi,105
u_litLo: p.litLo,106
u_litHi: p.litHi,107
u_litMix: p.litMix,108
u_edgeDark: p.edgeDark,109
u_lightDirX: p.lightDirX,110
u_lightDirY: p.lightDirY,111
u_lightDirZ: p.lightDirZ,112
u_normalEps: p.normalEps,113
u_foamStrength: p.foamStrength,114
u_shoreClip: p.shoreClip115
};116
}117
118
export function setWaterDebugParams (next)119
{120
params = { ...DEFAULT_WATER_DEBUG, ...params, ...next };121
syncInputs();122
}123
124
function syncInputs ()125
{126
if (!panelEl)127
{ return; }128
for (const { key } of SLIDERS)129
{130
const input = panelEl.querySelector(`input[data-water-key="${key}"]`);131
const valueEl = panelEl.querySelector(`[data-water-value="${key}"]`);132
if (input)133
{ input.value = String(params[key]); }134
if (valueEl)135
{ valueEl.textContent = Number(params[key]).toFixed(3); }136
}137
}138
139
function exportJson ()140
{141
const text = JSON.stringify(getWaterDebugParams(), null, 2);142
void navigator.clipboard?.writeText(text).catch(() => {});143
const blob = new Blob([text], { type: "application/json" });144
const url = URL.createObjectURL(blob);145
const a = document.createElement("a");146
a.href = url;147
a.download = "water-debug.json";148
a.click();149
URL.revokeObjectURL(url);150
const status = panelEl?.querySelector("[data-water-export-status]");151
if (status)152
{153
status.textContent = "Exported (+ copied if allowed)";154
setTimeout(() =>155
{156
if (status.textContent.startsWith("Exported"))157
{ status.textContent = ""; }158
}, 2000);159
}160
}161
162
/**163
* Always-visible temporary debug dock (pointer-events on panel only).164
*/165
export function initWaterDebugPanel ()166
{167
if (panelEl)168
{ return panelEl; }169
170
panelEl = document.createElement("aside");171
panelEl.id = "water-debug-panel";172
panelEl.innerHTML = `173
<header>174
<strong>Water debug</strong>175
<span data-water-export-status></span>176
</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>181
</footer>182
`;183
Object.assign(panelEl.style, {184
position: "fixed",185
top: "8px",186
right: "8px",187
width: "280px",188
maxHeight: "calc(100vh - 16px)",189
zIndex: "9999",190
display: "flex",191
flexDirection: "column",192
gap: "6px",193
padding: "8px",194
background: "rgba(12, 16, 22, 0.92)",195
color: "#e8eef5",196
font: "12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",197
border: "1px solid rgba(255,255,255,0.18)",198
borderRadius: "6px",199
boxShadow: "0 8px 24px rgba(0,0,0,0.45)",200
pointerEvents: "auto"201
});202
203
const scroll = panelEl.querySelector(".water-debug-scroll");204
Object.assign(scroll.style, {205
overflowY: "auto",206
flex: "1 1 auto",207
display: "flex",208
flexDirection: "column",209
gap: "4px",210
paddingRight: "2px"211
});212
213
for (const spec of SLIDERS)214
{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", () =>224
{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); }229
});230
scroll.appendChild(row);231
}232
233
panelEl.querySelector("[data-water-reset]").addEventListener("click", (event) =>234
{235
event.preventDefault();236
event.stopPropagation();237
params = { ...DEFAULT_WATER_DEBUG };238
syncInputs();239
});240
panelEl.querySelector("[data-water-export]").addEventListener("click", (event) =>241
{242
event.preventDefault();243
event.stopPropagation();244
exportJson();245
});246
247
for (const type of ["mousedown", "mouseup", "click", "wheel", "contextmenu", "pointerdown"])248
{249
panelEl.addEventListener(type, (event) =>250
{251
event.stopPropagation();252
});253
}254
255
document.body.appendChild(panelEl);256
return panelEl;257
}@@ -27,6 +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
31
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";
31
32
import
32
33
{
@@ -137,6 +138,36 @@ const WATER_GROUND_FRAG = [
137
138
"uniform float u_shoreEdgeSE;",
138
139
"uniform float u_shoreEdgeSW;",
139
140
"uniform vec4 u_shoreUvRect;",
141
"uniform float u_flowX;",
142
"uniform float u_flowY;",
143
"uniform float u_flowZ;",
144
"uniform float u_waveScale;",
145
"uniform float u_fbmAmp;",
146
"uniform float u_texAmp;",
147
"uniform float u_distort;",
148
"uniform float u_normalZ;",
149
"uniform float u_waveGain;",
150
"uniform float u_crestLo;",
151
"uniform float u_crestHi;",
152
"uniform float u_crestPow;",
153
"uniform float u_glitterPow;",
154
"uniform float u_crestGlitter;",
155
"uniform float u_glitterCap;",
156
"uniform float u_glitterMix;",
157
"uniform float u_shadeLo;",
158
"uniform float u_shadeHi;",
159
"uniform float u_bodyLo;",
160
"uniform float u_bodyHi;",
161
"uniform float u_litLo;",
162
"uniform float u_litHi;",
163
"uniform float u_litMix;",
164
"uniform float u_edgeDark;",
165
"uniform float u_lightDirX;",
166
"uniform float u_lightDirY;",
167
"uniform float u_lightDirZ;",
168
"uniform float u_normalEps;",
169
"uniform float u_foamStrength;",
170
"uniform float u_shoreClip;",
140
171
// 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).
141
172
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
142
173
"vec4 mod289(vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",
@@ -214,25 +245,23 @@ const WATER_GROUND_FRAG = [
214
245
" vec2 puv = px / 16.0;",
215
246
" vec2 world = vec2(u_tileX, u_tileY) + puv;",
216
247
" float t = u_time;",
217
// Midpoint between prior slow scroll and the 2× pass.
218
" vec2 flow = vec2(t * 0.33, t * 0.21);",
219
" float eps = 0.10;",
220
" vec3 base = vec3(world * 0.85 + flow, t * 0.52);",
248
" vec2 flow = vec2(t * u_flowX, t * u_flowY);",
249
" float eps = max(u_normalEps, 0.001);",
250
" vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",
221
251
" float nC = fbm(base);",
222
252
" float nL = fbm(base + vec3(-eps, 0.0, 0.0));",
223
253
" float nR = fbm(base + vec3(eps, 0.0, 0.0));",
224
254
" float nD = fbm(base + vec3(0.0, -eps, 0.0));",
225
255
" float nU = fbm(base + vec3(0.0, eps, 0.0));",
226
" vec2 distort = vec2(nL - nR, nD - nU) * 0.14;",
256
" vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",
227
257
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",
228
" float h = nC * 0.75 + (texN - 0.5) * 0.18;",
229
" vec3 normal = normalize(vec3(nL - nR, nD - nU, 0.9));",
230
" float ndotl = clamp(dot(normal, normalize(vec3(-0.55, -0.5, 0.75))), 0.0, 1.0);",
231
" float wave = clamp(h * 0.42 + 0.5, 0.0, 1.0);",
232
// Narrow tip sparkles — avoid wide white plateaus.
233
" float crest = pow(smoothstep(0.72, 0.96, wave), 2.2);",
234
" float glitter = pow(max(0.0, ndotl), 7.5) * crest;",
235
" glitter = max(glitter, pow(crest, 2.5) * 0.55);",
258
" float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",
259
" vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",
260
" float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",
261
" float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",
262
" float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",
263
" float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",
264
" glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",
236
265
" float edgeProx = 0.0;",
237
266
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",
238
267
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",
@@ -259,13 +288,12 @@ const WATER_GROUND_FRAG = [
259
288
" vec3 litCol = mix(vec3(0.52, 0.78, 0.90), vec3(0.30, 0.52, 0.72), deepMix);",
260
289
" vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), vec3(0.78, 0.92, 1.0), deepMix);",
261
290
" vec3 foamCol = vec3(0.94, 0.99, 1.0);",
262
// Gentler body contrast so troughs/crests don't form flat dark/white blobs.
263
" float shade = mix(0.90, 1.06, ndotl);",
264
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.12, 0.72, waveBody));",
265
" rgb = mix(rgb, litCol, smoothstep(0.52, 0.90, waveBody) * 0.40);",
291
" 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));",
293
" rgb = mix(rgb, litCol, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix);",
266
294
" rgb *= shade;",
267
" rgb = mix(rgb, sparkCol, min(glitter, 0.72) * 0.80 * (1.0 - edgeProx * 0.7));",
268
" rgb = mix(rgb, deepCol, edgeProx * 0.40);",
295
" rgb = mix(rgb, sparkCol, min(glitter, u_glitterCap) * u_glitterMix * (1.0 - edgeProx * 0.7));",
296
" rgb = mix(rgb, deepCol, edgeProx * u_edgeDark);",
269
297
" float shoreW = 0.0;",
270
298
" vec3 shoreRgb = rgb;",
271
299
" if (u_edgeN > 0.5) {",
@@ -280,7 +308,6 @@ const WATER_GROUND_FRAG = [
280
308
" if (u_edgeE > 0.5) {",
281
309
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
282
310
" }",
283
// Land-point diagonals must also bind the neighbor ground (not only water-point cases).
284
311
" if (u_edgeNE > 0.5) {",
285
312
" sampleShore(1.0, max(u_shoreEdgeNE, u_hasShore), vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",
286
313
" }",
@@ -295,11 +322,11 @@ const WATER_GROUND_FRAG = [
295
322
" }",
296
323
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",
297
324
" float retreat = edgeProx * (0.35 + 0.65 * darkAmt);",
298
" float shoreClip = 0.42;",
325
" float shoreClip = u_shoreClip;",
299
326
" float shoreMask = step(shoreClip, retreat) * shoreW;",
300
327
" float foamAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.24, shoreClip - 0.08, retreat)",
301
328
" * (1.0 - smoothstep(shoreClip - 0.08, shoreClip, retreat));",
302
" rgb = mix(rgb, foamCol, foamAmt * 0.95);",
329
" rgb = mix(rgb, foamCol, foamAmt * u_foamStrength);",
303
330
" rgb = mix(rgb, shoreRgb, shoreMask);",
304
331
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",
305
332
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",
@@ -3552,7 +3579,8 @@ export class WorldView
3552
3579
u_shoreEdgeNW: shore?.edgeNW ?? 0,
3553
3580
u_shoreEdgeSE: shore?.edgeSE ?? 0,
3554
3581
u_shoreEdgeSW: shore?.edgeSW ?? 0,
3555
u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1]
3582
u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1],
3583
...waterDebugUniforms()
3556
3584
};
3557
3585
}
3558
3586
@@ -27,6 +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 { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";31
import { SeasonId, seasonIdAt, resolveSeasonalVisualState } from "/shared/world/season.js";31
import32
import32
{33
{@@ -137,6 +138,36 @@ const WATER_GROUND_FRAG = [137
"uniform float u_shoreEdgeSE;",138
"uniform float u_shoreEdgeSE;",138
"uniform float u_shoreEdgeSW;",139
"uniform float u_shoreEdgeSW;",139
"uniform vec4 u_shoreUvRect;",140
"uniform vec4 u_shoreUvRect;",141
"uniform float u_flowX;",142
"uniform float u_flowY;",143
"uniform float u_flowZ;",144
"uniform float u_waveScale;",145
"uniform float u_fbmAmp;",146
"uniform float u_texAmp;",147
"uniform float u_distort;",148
"uniform float u_normalZ;",149
"uniform float u_waveGain;",150
"uniform float u_crestLo;",151
"uniform float u_crestHi;",152
"uniform float u_crestPow;",153
"uniform float u_glitterPow;",154
"uniform float u_crestGlitter;",155
"uniform float u_glitterCap;",156
"uniform float u_glitterMix;",157
"uniform float u_shadeLo;",158
"uniform float u_shadeHi;",159
"uniform float u_bodyLo;",160
"uniform float u_bodyHi;",161
"uniform float u_litLo;",162
"uniform float u_litHi;",163
"uniform float u_litMix;",164
"uniform float u_edgeDark;",165
"uniform float u_lightDirX;",166
"uniform float u_lightDirY;",167
"uniform float u_lightDirZ;",168
"uniform float u_normalEps;",169
"uniform float u_foamStrength;",170
"uniform float u_shoreClip;",140
// 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).171
// 3D simplex (Ashima / Gustavson style — OpenSimplex-class continuous field).141
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",172
"vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }",142
"vec4 mod289(vec4 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; }",@@ -214,25 +245,23 @@ const WATER_GROUND_FRAG = [214
" vec2 puv = px / 16.0;",245
" vec2 puv = px / 16.0;",215
" vec2 world = vec2(u_tileX, u_tileY) + puv;",246
" vec2 world = vec2(u_tileX, u_tileY) + puv;",216
" float t = u_time;",247
" float t = u_time;",217
// Midpoint between prior slow scroll and the 2× pass.248
" vec2 flow = vec2(t * u_flowX, t * u_flowY);",218
" vec2 flow = vec2(t * 0.33, t * 0.21);",249
" float eps = max(u_normalEps, 0.001);",219
" float eps = 0.10;",250
" vec3 base = vec3(world * u_waveScale + flow, t * u_flowZ);",220
" vec3 base = vec3(world * 0.85 + flow, t * 0.52);",221
" float nC = fbm(base);",251
" float nC = fbm(base);",222
" float nL = fbm(base + vec3(-eps, 0.0, 0.0));",252
" float nL = fbm(base + vec3(-eps, 0.0, 0.0));",223
" float nR = fbm(base + vec3(eps, 0.0, 0.0));",253
" float nR = fbm(base + vec3(eps, 0.0, 0.0));",224
" float nD = fbm(base + vec3(0.0, -eps, 0.0));",254
" float nD = fbm(base + vec3(0.0, -eps, 0.0));",225
" float nU = fbm(base + vec3(0.0, eps, 0.0));",255
" float nU = fbm(base + vec3(0.0, eps, 0.0));",226
" vec2 distort = vec2(nL - nR, nD - nU) * 0.14;",256
" vec2 distort = vec2(nL - nR, nD - nU) * u_distort;",227
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",257
" float texN = texture2D(u_texture, wrapUv(world * 0.28 + flow * 0.6 + distort)).r;",228
" float h = nC * 0.75 + (texN - 0.5) * 0.18;",258
" float h = nC * u_fbmAmp + (texN - 0.5) * u_texAmp;",229
" vec3 normal = normalize(vec3(nL - nR, nD - nU, 0.9));",259
" vec3 normal = normalize(vec3(nL - nR, nD - nU, max(u_normalZ, 0.05)));",230
" float ndotl = clamp(dot(normal, normalize(vec3(-0.55, -0.5, 0.75))), 0.0, 1.0);",260
" float ndotl = clamp(dot(normal, normalize(vec3(u_lightDirX, u_lightDirY, u_lightDirZ))), 0.0, 1.0);",231
" float wave = clamp(h * 0.42 + 0.5, 0.0, 1.0);",261
" float wave = clamp(h * u_waveGain + 0.5, 0.0, 1.0);",232
// Narrow tip sparkles — avoid wide white plateaus.262
" float crest = pow(smoothstep(u_crestLo, max(u_crestHi, u_crestLo + 0.01), wave), max(u_crestPow, 0.01));",233
" float crest = pow(smoothstep(0.72, 0.96, wave), 2.2);",263
" float glitter = pow(max(0.0, ndotl), max(u_glitterPow, 0.01)) * crest;",234
" float glitter = pow(max(0.0, ndotl), 7.5) * crest;",264
" glitter = max(glitter, pow(crest, 2.5) * u_crestGlitter);",235
" glitter = max(glitter, pow(crest, 2.5) * 0.55);",236
" float edgeProx = 0.0;",265
" float edgeProx = 0.0;",237
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",266
" if (u_edgeN > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, puv.y)); }",238
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",267
" if (u_edgeS > 0.5) { edgeProx = max(edgeProx, smoothstep(0.55, 0.0, 1.0 - puv.y)); }",@@ -259,13 +288,12 @@ const WATER_GROUND_FRAG = [259
" vec3 litCol = mix(vec3(0.52, 0.78, 0.90), vec3(0.30, 0.52, 0.72), deepMix);",288
" vec3 litCol = mix(vec3(0.52, 0.78, 0.90), vec3(0.30, 0.52, 0.72), deepMix);",260
" vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), vec3(0.78, 0.92, 1.0), deepMix);",289
" vec3 sparkCol = mix(vec3(0.98, 1.0, 1.0), vec3(0.78, 0.92, 1.0), deepMix);",261
" vec3 foamCol = vec3(0.94, 0.99, 1.0);",290
" vec3 foamCol = vec3(0.94, 0.99, 1.0);",262
// Gentler body contrast so troughs/crests don't form flat dark/white blobs.291
" float shade = mix(u_shadeLo, u_shadeHi, ndotl);",263
" float shade = mix(0.90, 1.06, ndotl);",292
" vec3 rgb = mix(deepCol, midCol, smoothstep(u_bodyLo, max(u_bodyHi, u_bodyLo + 0.01), waveBody));",264
" vec3 rgb = mix(deepCol, midCol, smoothstep(0.12, 0.72, waveBody));",293
" rgb = mix(rgb, litCol, smoothstep(u_litLo, max(u_litHi, u_litLo + 0.01), waveBody) * u_litMix);",265
" rgb = mix(rgb, litCol, smoothstep(0.52, 0.90, waveBody) * 0.40);",266
" rgb *= shade;",294
" rgb *= shade;",267
" rgb = mix(rgb, sparkCol, min(glitter, 0.72) * 0.80 * (1.0 - edgeProx * 0.7));",295
" rgb = mix(rgb, sparkCol, min(glitter, u_glitterCap) * u_glitterMix * (1.0 - edgeProx * 0.7));",268
" rgb = mix(rgb, deepCol, edgeProx * 0.40);",296
" rgb = mix(rgb, deepCol, edgeProx * u_edgeDark);",269
" float shoreW = 0.0;",297
" float shoreW = 0.0;",270
" vec3 shoreRgb = rgb;",298
" vec3 shoreRgb = rgb;",271
" if (u_edgeN > 0.5) {",299
" if (u_edgeN > 0.5) {",@@ -280,7 +308,6 @@ const WATER_GROUND_FRAG = [280
" if (u_edgeE > 0.5) {",308
" if (u_edgeE > 0.5) {",281
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",309
" sampleShore(1.0, u_shoreEdgeE, vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",282
" }",310
" }",283
// Land-point diagonals must also bind the neighbor ground (not only water-point cases).284
" if (u_edgeNE > 0.5) {",311
" if (u_edgeNE > 0.5) {",285
" sampleShore(1.0, max(u_shoreEdgeNE, u_hasShore), vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",312
" sampleShore(1.0, max(u_shoreEdgeNE, u_hasShore), vec2(1.0 - puv.x, puv.y), shoreRgb, shoreW);",286
" }",313
" }",@@ -295,11 +322,11 @@ const WATER_GROUND_FRAG = [295
" }",322
" }",296
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",323
" float darkAmt = 1.0 - smoothstep(0.18, 0.52, waveBody);",297
" float retreat = edgeProx * (0.35 + 0.65 * darkAmt);",324
" float retreat = edgeProx * (0.35 + 0.65 * darkAmt);",298
" float shoreClip = 0.42;",325
" float shoreClip = u_shoreClip;",299
" float shoreMask = step(shoreClip, retreat) * shoreW;",326
" float shoreMask = step(shoreClip, retreat) * shoreW;",300
" float foamAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.24, shoreClip - 0.08, retreat)",327
" float foamAmt = (1.0 - shoreMask) * smoothstep(shoreClip - 0.24, shoreClip - 0.08, retreat)",301
" * (1.0 - smoothstep(shoreClip - 0.08, shoreClip, retreat));",328
" * (1.0 - smoothstep(shoreClip - 0.08, shoreClip, retreat));",302
" rgb = mix(rgb, foamCol, foamAmt * 0.95);",329
" rgb = mix(rgb, foamCol, foamAmt * u_foamStrength);",303
" rgb = mix(rgb, shoreRgb, shoreMask);",330
" rgb = mix(rgb, shoreRgb, shoreMask);",304
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",331
" float litTop = mix(u_litNW, u_litNE, v_texCoord.x);",305
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",332
" float litBottom = mix(u_litSW, u_litSE, v_texCoord.x);",@@ -3552,7 +3579,8 @@ export class WorldView3552
u_shoreEdgeNW: shore?.edgeNW ?? 0,3579
u_shoreEdgeNW: shore?.edgeNW ?? 0,3553
u_shoreEdgeSE: shore?.edgeSE ?? 0,3580
u_shoreEdgeSE: shore?.edgeSE ?? 0,3554
u_shoreEdgeSW: shore?.edgeSW ?? 0,3581
u_shoreEdgeSW: shore?.edgeSW ?? 0,3555
u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1]3582
u_shoreUvRect: [shoreUv.u0, shoreUv.v0, shoreUv.u1, shoreUv.v1],3583
...waterDebugUniforms()3556
};3584
};3557
}3585
}3558
3586