From 468e66058edd3342d2d675b3dfe609d68baab4a0 Mon Sep 17 00:00:00 2001 From: Richard Zink Date: Wed, 7 Oct 2026 19:04:50 +0200 Subject: [PATCH] Fix clouds3d: move starField out of main() (GLSL syntax) GLSL does not allow nested function definitions; the starField() helper must live at top-level alongside hash3/noise3/fbm3. --- vendor/clouds3d.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/vendor/clouds3d.js b/vendor/clouds3d.js index 6232c38..be4f945 100644 --- a/vendor/clouds3d.js +++ b/vendor/clouds3d.js @@ -98,6 +98,20 @@ var FRAG_SRC = [ 'profile = max(profile, 0.0);', 'return smoothstep(baseThresh, baseThresh + 0.18, n) * profile;', '}', + // Star field: project ray onto a far sphere, hash-grid for + // positions. Visible above the horizon at night with a small + // twinkle. + 'float starField(vec3 r) {', + 'vec3 sp = r * 220.0;', + 'vec3 sf = floor(sp);', + 'vec3 sfp = fract(sp) - 0.5;', + 'float h = hash3(sf);', + 'float starD = length(sfp);', + 'float mask = step(0.985, h) * smoothstep(0.35, 0.0, starD);', + 'float twinkle = 0.55 + 0.45 * sin(uTime * 3.0 + h * 47.0);', + 'return mask * twinkle;', + '}', + '}', 'void main() {', 'vec2 uv = (gl_FragCoord.xy / uResolution.xy) * 2.0 - 1.0;', 'uv.x *= uResolution.x / uResolution.y;', @@ -115,20 +129,7 @@ var FRAG_SRC = [ // Sky gradient based on ray Y (background). 'float skyT = clamp(rd.y * 0.7 + 0.5, 0.0, 1.0);', 'vec3 col = mix(uBg, uSky, skyT);', - // Stars: project ray onto a far sphere, hash-grid for star - // positions. Only visible above the horizon and at night, - // with a small twinkle so they don't look like a static - // dither pattern. - 'float starField(vec3 r) {', - 'vec3 sp = r * 220.0;', - 'vec3 sf = floor(sp);', - 'vec3 sfp = fract(sp) - 0.5;', - 'float h = hash3(sf);', - 'float starD = length(sfp);', - 'float mask = step(0.985, h) * smoothstep(0.35, 0.0, starD);', - 'float twinkle = 0.55 + 0.45 * sin(uTime * 3.0 + h * 47.0);', - 'return mask * twinkle;', - '}', + // Stars: hash-grid sphere, above horizon, only at night. 'float stars = starField(rd) * smoothstep(0.05, 0.35, rd.y) * (1.0 - uDayProgress);', 'col = mix(col, uLight, clamp(stars, 0.0, 1.0) * 0.9);', // Density threshold: weather 'sunny' -> high (sparse clouds),