From e17076a273a45c7bc42f8b06b87af3189287b626 Mon Sep 17 00:00:00 2001 From: Richard Zink Date: Thu, 8 Oct 2026 06:18:56 +0200 Subject: [PATCH] Fix shader: pass uFlightDir as uniform instead of window access The shader had the JS code 'window.__flightDir.dx' baked into the GLSL string, which GLSL can't parse. Added a uFlightDir uniform (vec2) and pass the dx/dz from JS via gl.uniform2f. Shader reads uFlightDir.x and uFlightDir.y. --- vendor/clouds3d.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vendor/clouds3d.js b/vendor/clouds3d.js index a57cb5a..1bf4926 100644 --- a/vendor/clouds3d.js +++ b/vendor/clouds3d.js @@ -56,6 +56,7 @@ var FRAG_SRC = [ 'uniform sampler2D uGround;', 'uniform vec2 uGroundCenter;', // current mosaic centre (world units) 'uniform vec2 uGroundSize;', // mosaic side extents in X and Z (world units) + 'uniform vec2 uFlightDir;', // camera motion direction (dx, dz) 'uniform vec3 uSky;', 'uniform vec3 uCloud;', 'uniform vec3 uCloudShadow;', @@ -143,7 +144,7 @@ var FRAG_SRC = [ // Default: drift along +Z (north). For east: drift along +X. For south: -Z, etc. 'float fdx = (window.__flightDir ? window.__flightDir.dx : 0.0);', 'float fdz = (window.__flightDir ? window.__flightDir.dz : 1.0);', - 'vec3 ro = vec3(drift * fdx, camY, drift * fdz);', + 'vec3 ro = vec3(drift * uFlightDir.x, camY, drift * uFlightDir.y);', // Ray direction: tilt more downward so the visible ground fits // within the mosaic. At uv.y = 0 the ray goes ~26° below // horizontal, putting the visible ground at tGround < 5 @@ -251,6 +252,7 @@ function init(canvas) { var uGround = gl.getUniformLocation(prog, 'uGround'); var uGroundCenter = gl.getUniformLocation(prog, 'uGroundCenter'); var uGroundSize = gl.getUniformLocation(prog, 'uGroundSize'); + var uFlightDir = gl.getUniformLocation(prog, 'uFlightDir'); var uSky = gl.getUniformLocation(prog, 'uSky'); var uCloud = gl.getUniformLocation(prog, 'uCloud'); var uCloudShadow = gl.getUniformLocation(prog, 'uCloudShadow'); @@ -265,6 +267,7 @@ function init(canvas) { gl: gl, prog: prog, buf: buf, aPos: aPos, uRes: uRes, uTime: uTime, uGround: uGround, uGroundCenter: uGroundCenter, uGroundSize: uGroundSize, + uFlightDir: uFlightDir, uSky: uSky, uCloud: uCloud, uCloudShadow: uCloudShadow, uLight: uLight, uBg: uBg, uSpeed: uSpeed, uDensity: uDensity, uDayProgress: uDayProgress, @@ -542,6 +545,9 @@ window.clouds3dRender = function(target) { }; gl.uniform2f(s.uGroundCenter, centerWorld.x, centerWorld.y); gl.uniform2f(s.uGroundSize, GROUND_CORRIDOR_PERP, GROUND_CORRIDOR_LONG); + var flightDir = (window.__flightDir && (window.__flightDir.dx !== undefined)) + ? window.__flightDir : { dx: 0, dz: 1 }; + gl.uniform2f(s.uFlightDir, flightDir.dx, flightDir.dz); var drift = now * speed * 0.12; if (performance.now() - groundLastCheck > 1500) {