/**
* Temporary always-on water shader debug panel (simplex FBM tune).
* Export JSON when you land on values you like.
*/
export const DEFAULT_WATER_DEBUG = Object.freeze({
flowX: 0.33,
flowY: 0.21,
flowZ: 0.52,
waveScale: 0.85,
fbmAmp: 0.75,
texAmp: 0.18,
distort: 0.14,
normalZ: 0.9,
waveGain: 0.42,
crestLo: 0.72,
crestHi: 0.96,
crestPow: 2.2,
glitterPow: 7.5,
crestGlitter: 0.55,
glitterCap: 0.72,
glitterMix: 0.8,
shadeLo: 0.9,
shadeHi: 1.06,
bodyLo: 0.12,
bodyHi: 0.72,
litLo: 0.52,
litHi: 0.9,
litMix: 0.4,
edgeDark: 0.4,
lightDirX: -0.55,
lightDirY: -0.5,
lightDirZ: 0.75,
normalEps: 0.1,
foamStrength: 0.95,
shoreClip: 0.42
});
const SLIDERS = [
{ key: "flowX", label: "Flow X", min: 0, max: 1, step: 0.01 },
{ key: "flowY", label: "Flow Y", min: 0, max: 1, step: 0.01 },
{ key: "flowZ", label: "Flow Z (time)", min: 0, max: 1.5, step: 0.01 },
{ key: "waveScale", label: "Wave scale", min: 0.2, max: 2.5, step: 0.01 },
{ key: "fbmAmp", label: "FBM amp", min: 0.1, max: 1.5, step: 0.01 },
{ key: "texAmp", label: "Tex amp", min: 0, max: 0.6, step: 0.01 },
{ key: "distort", label: "Distort", min: 0, max: 0.5, step: 0.01 },
{ key: "normalEps", label: "Normal ε", min: 0.02, max: 0.3, step: 0.01 },
{ key: "normalZ", label: "Normal Z", min: 0.3, max: 1.5, step: 0.01 },
{ key: "waveGain", label: "Wave gain", min: 0.1, max: 1, step: 0.01 },
{ key: "crestLo", label: "Crest lo", min: 0.3, max: 0.95, step: 0.01 },
{ key: "crestHi", label: "Crest hi", min: 0.5, max: 1, step: 0.01 },
{ key: "crestPow", label: "Crest pow", min: 0.5, max: 5, step: 0.05 },
{ key: "glitterPow", label: "Glitter pow", min: 1, max: 16, step: 0.1 },
{ key: "crestGlitter", label: "Crest glitter", min: 0, max: 1.5, step: 0.01 },
{ key: "glitterCap", label: "Glitter cap", min: 0.1, max: 1, step: 0.01 },
{ key: "glitterMix", label: "Glitter mix", min: 0, max: 1.5, step: 0.01 },
{ key: "shadeLo", label: "Shade lo", min: 0.5, max: 1.1, step: 0.01 },
{ key: "shadeHi", label: "Shade hi", min: 0.9, max: 1.4, step: 0.01 },
{ key: "bodyLo", label: "Body lo", min: 0, max: 0.5, step: 0.01 },
{ key: "bodyHi", label: "Body hi", min: 0.3, max: 1, step: 0.01 },
{ key: "litLo", label: "Lit lo", min: 0.2, max: 0.8, step: 0.01 },
{ key: "litHi", label: "Lit hi", min: 0.5, max: 1, step: 0.01 },
{ key: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 },
{ key: "lightDirX", label: "Light dir X", min: -1, max: 1, step: 0.01 },
{ key: "lightDirY", label: "Light dir Y", min: -1, max: 1, step: 0.01 },
{ key: "lightDirZ", label: "Light dir Z", min: 0.1, max: 1.5, step: 0.01 },
{ key: "foamStrength", label: "Foam strength", min: 0, max: 1, step: 0.01 },
{ key: "shoreClip", label: "Shore clip", min: 0.1, max: 0.9, step: 0.01 }
];
let params = { ...DEFAULT_WATER_DEBUG };
let panelEl = null;
export function getWaterDebugParams ()
{
return { ...params };
}
/** Uniform bag for the water ground fragment shader. */
export function waterDebugUniforms ()
{
const p = params;
return {
u_flowX: p.flowX,
u_flowY: p.flowY,
u_flowZ: p.flowZ,
u_waveScale: p.waveScale,
u_fbmAmp: p.fbmAmp,
u_texAmp: p.texAmp,
u_distort: p.distort,
u_normalZ: p.normalZ,
u_waveGain: p.waveGain,
u_crestLo: p.crestLo,
u_crestHi: p.crestHi,
u_crestPow: p.crestPow,
u_glitterPow: p.glitterPow,
u_crestGlitter: p.crestGlitter,
u_glitterCap: p.glitterCap,
u_glitterMix: p.glitterMix,
u_shadeLo: p.shadeLo,
u_shadeHi: p.shadeHi,
u_bodyLo: p.bodyLo,
u_bodyHi: p.bodyHi,
u_litLo: p.litLo,
u_litHi: p.litHi,
u_litMix: p.litMix,
u_edgeDark: p.edgeDark,
u_lightDirX: p.lightDirX,
u_lightDirY: p.lightDirY,
u_lightDirZ: p.lightDirZ,
u_normalEps: p.normalEps,
u_foamStrength: p.foamStrength,
u_shoreClip: p.shoreClip
};
}
export function setWaterDebugParams (next)
{
params = { ...DEFAULT_WATER_DEBUG, ...params, ...next };
syncInputs();
}
function syncInputs ()
{
if (!panelEl)
{ return; }
for (const { key } of SLIDERS)
{
const input = panelEl.querySelector(`input[data-water-key="${key}"]`);
const valueEl = panelEl.querySelector(`[data-water-value="${key}"]`);
if (input)
{ input.value = String(params[key]); }
if (valueEl)
{ valueEl.textContent = Number(params[key]).toFixed(3); }
}
}
function exportJson ()
{
const text = JSON.stringify(getWaterDebugParams(), null, 2);
void navigator.clipboard?.writeText(text).catch(() => {});
const blob = new Blob([text], { type: "application/json" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "water-debug.json";
a.click();
URL.revokeObjectURL(url);
const status = panelEl?.querySelector("[data-water-export-status]");
if (status)
{
status.textContent = "Exported (+ copied if allowed)";
setTimeout(() =>
{
if (status.textContent.startsWith("Exported"))
{ status.textContent = ""; }
}, 2000);
}
}
/**
* Always-visible temporary debug dock (pointer-events on panel only).
*/
export function initWaterDebugPanel ()
{
if (panelEl)
{ return panelEl; }
panelEl = document.createElement("aside");
panelEl.id = "water-debug-panel";
panelEl.innerHTML = `