[claude] Procedural cloud layer below the floating island (#256) #339
Reference in New Issue
Block a user
Delete Branch "claude/issue-256"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #256
What was broken
The cloud layer shader had two bugs that prevented it from rendering at all:
1. GLSL undefined variable references
The fragment shader used
CLOUD_LAYER_Y,CLOUD_THICKNESS, andCLOUD_OPACITYas GLSL identifiers, but these are JavaScript variables. Inside a template literal they appear as plain text — GLSL does not know about them, causing shader compilation failure and no clouds rendered. Fixed by interpolating the values with${...}template expressions.2. Broken simplex noise implementation
The
snoise()function had three mistakes from the canonical Ian McEwan / Stefan Gustavson implementation:x_/y_raw cell indices were used directly forb0,b1, andhinstead of first rescaling them tox = x_ * ns.x + ns.yyyy/y = ...a0 = b0 - floor(b0)(fractional part) instead of the correct gradient coefficient formulaa0 = b0.xzyw + s0.xzyw * sh.xxyyp0–p3swizzle assignments were transposed (p1 used a1.xy, should use a0.zw, etc.)Replaced with the correct canonical implementation.
The cloud layer shader had two bugs preventing it from rendering: 1. GLSL fragment shader referenced JS variables (CLOUD_LAYER_Y, CLOUD_THICKNESS, CLOUD_OPACITY) as plain identifiers — these are undefined in GLSL scope and caused shader compilation failure. Fixed by interpolating their values into the template literal with ${...}. 2. Simplex noise implementation was incorrect: x_/y_ raw indices used directly instead of rescaled x/y for b0/b1/h; a0/a1 used fract() instead of the correct gradient coefficient formula; p0-p3 swizzles were transposed. Replaced with the canonical Ian McEwan / Stefan Gustavson snoise3. Fixes #256 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>