Fly mostly above the clouds with brief dips

Camera altitude is now driven by pow(sin,5) so the view stays at
y=2.6 most of the time and only briefly dips to y=0.9 to skim the
top of the cloud deck. Marching also skips the empty gap between
camera and cloud ceiling when looking down from above.
This commit is contained in:
Richard Zink committed 2026-10-07 18:57:55 +02:00
1 parent 433d743446
commit e80d255d58
1 file changed
+13 -14
+13 -14
View File
@@ -101,29 +101,28 @@ var FRAG_SRC = [
'void main() {',
'vec2 uv = (gl_FragCoord.xy / uResolution.xy) * 2.0 - 1.0;',
'uv.x *= uResolution.x / uResolution.y;',
// Camera path: slow drift in X, sinusoidal altitude.
// The altitude dip drives the "fly through cloud edges" effect.
// Camera path: slow drift in X, mostly above the cloud deck.
// pow(...,n) shapes the sin into short dips, so the view spends
// most of its time at cruising altitude and only briefly skims
// the top of the cloud layer.
'float drift = uTime * uSpeed * 0.45;',
'vec3 ro = vec3(',
'drift,',
// Altitude oscillates: above (1.5), at cloud-top (0.6), inside (0.1)
'1.5 - 1.4 * (0.5 + 0.5 * sin(uTime * 0.07)),',
'drift * 0.7',
');',
// Ray direction: gentle downward tilt so we see the cloud deck
// and the sky horizon at once.
'vec3 rd = normalize(vec3(uv.x * 0.55, -0.18 + uv.y * 0.25, 1.0));',
'float diveT = pow(0.5 + 0.5 * sin(uTime * 0.10), 5.0);',
'float camY = mix(2.6, 0.9, diveT);',
'vec3 ro = vec3(drift, camY, drift * 0.7);',
// Ray direction: tilt down a bit more so the cloud deck fills
// the lower frame when we're above it.
'vec3 rd = normalize(vec3(uv.x * 0.55, -0.35 + uv.y * 0.30, 1.0));',
// 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);',
// Density threshold: weather 'sunny' -> high (sparse clouds),
// 'stormy' -> low (overcast deck).
'float baseThresh = mix(0.72, 0.40, uDensity);',
// March the cloud layer (bounded in Y).
'float t = 0.0;',
// Skip the gap between camera and cloud top so we don't waste
// steps marching through clear sky. ray-Y = 2.0 = cloud ceiling.
'float t = (ro.y > 2.0 && rd.y < -0.001) ? (ro.y - 2.0) / -rd.y : 0.0;',
'float stepSize = 0.85;',
'float trans = 1.0;',
// Pre-compute ray entry/exit on cloud layer for early out
'for (int i = 0; i < 18; i++) {',
'vec3 p = ro + rd * t;',
'if (p.y > 2.0 || p.y < -0.4) break;',