/**
* Temporary always-on fluid shader debug panel (water + lava tabs).
* Export JSON when you land on values you like.
*/
export const DEFAULT_WATER_DEBUG = Object.freeze({
flowX: 0.17,
flowY: 0.05,
flowZ: 0.91,
waveScale: 2.07,
fbmAmp: 0.15,
texAmp: 0.43,
distort: 0.09,
normalZ: 0.88,
waveGain: 0.62,
crestLo: 0.54,
crestHi: 0.67,
crestPow: 2.05,
glitterPow: 13.1,
crestGlitter: 1.3,
glitterCap: 1,
glitterMix: 1.24,
shadeLo: 1.06,
shadeHi: 1,
bodyLo: 0.41,
bodyHi: 0.85,
litLo: 0.5,
litHi: 0.86,
litMix: 0.46,
edgeDark: 0.37,
lightDirX: -0.48,
lightDirY: -0.63,
lightDirZ: 0.78,
normalEps: 0.21,
foamStrength: 1,
shoreClip: 0.55,
/** 0 = baseline deep end; 1 = much darker deep water. */
deepDark: 0.4,
/** <1 = more abrupt darkening toward deep (pow curve). */
deepAbrupt: 0.72
});
export const DEFAULT_LAVA_DEBUG = Object.freeze({
flowX: 0.08,
flowY: 0.04,
flowZ: 0.27,
waveScale: 1.83,
fbmAmp: 0.43,
texAmp: 0.3,
distort: 0.3,
normalZ: 1.07,
waveGain: 0.52,
crestLo: 0.57,
crestHi: 0.71,
crestPow: 1.15,
glitterPow: 7.5,
crestGlitter: 1.19,
glitterCap: 0.31,
glitterMix: 0.51,
shadeLo: 0.88,
shadeHi: 1.07,
bodyLo: 0.05,
bodyHi: 1,
litLo: 0.59,
litHi: 0.74,
litMix: 1,
edgeDark: 0.55,
lightDirX: -0.48,
lightDirY: -0.63,
lightDirZ: 0.78,
normalEps: 0.09,
bloomStrength: 0.9,
shoreClip: 0.55
});
const WATER_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", 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: "glitterPow", label: "Glitter pow", min: 1, max: 16, step: 0.1 },
{ key: "glitterMix", label: "Glitter mix", min: 0, max: 1.5, 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: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },
{ key: "deepDark", label: "Deep darker", min: 0, max: 1, step: 0.01 },
{ key: "deepAbrupt", label: "Deep abrupt", min: 0.35, max: 1.4, step: 0.01 },
{ key: "foamStrength", label: "Foam", min: 0, max: 1, step: 0.01 },
{ key: "shoreClip", label: "Shore clip", min: 0.1, max: 0.9, step: 0.01 },
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }
];
const LAVA_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", 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: "distort", label: "Distort", min: 0, max: 0.5, step: 0.01 },
{ key: "glitterPow", label: "Heat pow", min: 1, max: 16, step: 0.1 },
{ key: "glitterMix", label: "Heat mix", min: 0, max: 1.5, step: 0.01 },
{ key: "glitterCap", label: "Heat cap", min: 0.1, max: 1, 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: "litMix", label: "Lit mix", min: 0, max: 1, step: 0.01 },
{ key: "bloomStrength", label: "Bloom", min: 0, max: 2, step: 0.01 },
{ key: "shoreClip", label: "Shore clip", min: 0.1, max: 0.9, step: 0.01 },
{ key: "edgeDark", label: "Edge dark", min: 0, max: 1, step: 0.01 }
];
let waterParams = { ...DEFAULT_WATER_DEBUG };
let lavaParams = { ...DEFAULT_LAVA_DEBUG };
let activeTab = "water";
let panelEl = null;
export function getWaterDebugParams ()
{
return { ...waterParams };
}
export function getLavaDebugParams ()
{
return { ...lavaParams };
}
function uniformBagFrom (p, extras = {})
{
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,
...extras
};
}
/** Uniform bag for the water ground fragment shader. */
export function waterDebugUniforms ()
{
const p = waterParams;
return uniformBagFrom(p, {
u_foamStrength: p.foamStrength,
u_shoreClip: p.shoreClip,
u_deepDark: p.deepDark,
u_deepAbrupt: p.deepAbrupt
});
}
/** Uniform bag for lava ground / bloom shaders. */
export function lavaDebugUniforms ()
{
const p = lavaParams;
return uniformBagFrom(p, {
u_bloomStrength: p.bloomStrength,
u_shoreClip: p.shoreClip
});
}
export function setWaterDebugParams (next)
{
waterParams = { ...DEFAULT_WATER_DEBUG, ...waterParams, ...next };
syncInputs();
}
export function setLavaDebugParams (next)
{
lavaParams = { ...DEFAULT_LAVA_DEBUG, ...lavaParams, ...next };
syncInputs();
}
function activeParams ()
{
return activeTab === "lava" ? lavaParams : waterParams;
}
function activeSliders ()
{
return activeTab === "lava" ? LAVA_SLIDERS : WATER_SLIDERS;
}
function syncInputs ()
{
if (!panelEl)
{ return; }
for (const { key } of activeSliders())
{
const input = panelEl.querySelector(`input[data-fluid-key="${key}"]`);
const valueEl = panelEl.querySelector(`[data-fluid-value="${key}"]`);
const params = activeParams();
if (input)
{ input.value = String(params[key]); }
if (valueEl)
{ valueEl.textContent = Number(params[key]).toFixed(3); }
}
for (const btn of panelEl.querySelectorAll("[data-fluid-tab]"))
{
const on = btn.getAttribute("data-fluid-tab") === activeTab;
btn.style.opacity = on ? "1" : "0.55";
btn.style.borderBottom = on ? "2px solid #9ec5ff" : "2px solid transparent";
}
}
function exportJson ()
{
const isLava = activeTab === "lava";
const text = JSON.stringify(isLava ? getLavaDebugParams() : 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 = isLava ? "lava-debug.json" : "water-debug.json";
a.click();
URL.revokeObjectURL(url);
const status = panelEl?.querySelector("[data-fluid-export-status]");
if (status)
{
status.textContent = "Exported";
setTimeout(() =>
{
if (status.textContent === "Exported")
{ status.textContent = ""; }
}, 2000);
}
}
function rebuildSliderRows ()
{
const scroll = panelEl?.querySelector(".fluid-debug-scroll");
if (!scroll)
{ return; }
scroll.replaceChildren();
const params = activeParams();
for (const spec of activeSliders())
{
const row = document.createElement("label");
row.style.cssText = "display:grid;grid-template-columns:1fr 48px;gap:2px 6px;align-items:center;";
row.innerHTML = `
${spec.label}
${Number(params[spec.key]).toFixed(3)}
`;
const input = row.querySelector("input");
input.addEventListener("input", () =>
{
const bag = activeTab === "lava" ? lavaParams : waterParams;
bag[spec.key] = Number(input.value);
const valueEl = row.querySelector(`[data-fluid-value="${spec.key}"]`);
if (valueEl)
{ valueEl.textContent = Number(bag[spec.key]).toFixed(3); }
});
scroll.appendChild(row);
}
}
function setTab (tab)
{
activeTab = tab === "lava" ? "lava" : "water";
rebuildSliderRows();
syncInputs();
}
/**
* Always-visible temporary debug dock (pointer-events on panel only).
*/
export function initWaterDebugPanel ()
{
if (panelEl)
{ return panelEl; }
panelEl = document.createElement("aside");
panelEl.id = "fluid-debug-panel";
panelEl.innerHTML = `