clouds: lower deck and fade near-camera cloud clipping

This commit is contained in:
Richard Zink committed 2026-10-13 08:47:56 +02:00
1 parent 6f19b34900
commit 33d89683ef
2 files changed
+17 -2

No files matched your search

+6 -1
View File
@@ -321,8 +321,12 @@ window.CONFIG = {
// altitude so aircraft fly above the deck.
clouds: {
enabled: true, // false removes the volumetric cloud deck
top: 1.0, // ~12.9 km
top: 0.78, // ~10.1 km, lower deck keeps camera clearance
bottom: -0.2, // ~-2.6 km (deck base slightly below terrain)
nearFade: {
start: 0.35, // world units: clouds fade out very close to camera
end: 2.5 // full density from this distance onward
},
// Coverage per weather level, 0 = clear, 1 = overcast. Only the
// levels listed here override the built-in defaults
// (sunny 0.20, cloudy 0.70, stormy 0.80, night 0.45). Live weather
@@ -344,6 +348,7 @@ window.CONFIG = {
// wind: { speedScale: 140, maxSpeed: 0.12 } // very visible motion
}
// density: { sunny: 0.05, cloudy: 0.9, rain: 0.95, snow: 0.85, stormy: 1.0 }
// top: 0.65, nearFade: { start: 0.5, end: 3.5 }
},
// ------------------------------------------------------------------
+11 -1
View File
@@ -77,6 +77,8 @@ var FRAG_SRC = [
'uniform float uSunAlt;',
'uniform float uCloudTop;', // cloud deck upper edge (world Y)
'uniform float uCloudBot;', // cloud deck lower edge (world Y)
'uniform float uCloudNearFadeStart;',
'uniform float uCloudNearFadeEnd;',
'uniform sampler2D uElev;', // terrarium RGB height grid, same UV as uGround
'uniform float uElevOn;', // terrain enabled (0/1)
'uniform float uElevScale;', // metres -> world units (incl. exaggeration)
@@ -722,7 +724,8 @@ var FRAG_SRC = [
'vec3 ambC = albC * max(vec3(uSkyAmb), uStarAmb * vec3(0.7, 0.85, 1.0)) * 1.7;',
'vec3 moonC = albC * uMoonColor * (0.35 + 0.65 * max(0.0, dot(rd, uMoonDir))) * uMoonInt * 3.0;',
'vec3 cloudCol = direct + ambC + moonC;',
'float alpha = clamp(d * stepSize * 3.50 * densityGain, 0.0, 1.0);',
'float nearFade = smoothstep(uCloudNearFadeStart, uCloudNearFadeEnd, t);',
'float alpha = clamp(d * stepSize * 3.50 * densityGain * nearFade, 0.0, 1.0);',
'cloudSum += cloudCol * alpha * trans;',
'trans *= (1.0 - alpha);',
'if (trans < 0.04) break;',
@@ -1296,6 +1299,8 @@ function init(canvas) {
uSpeed: uSpeed, uDensity: uDensity, uDayProgress: uDayProgress,
uSunAlt: uSunAlt,
uCloudTop: uCloudTop, uCloudBot: uCloudBot,
uCloudNearFadeStart: gl.getUniformLocation(prog, 'uCloudNearFadeStart'),
uCloudNearFadeEnd: gl.getUniformLocation(prog, 'uCloudNearFadeEnd'),
uElev: uElev, uElevOn: uElevOn, uElevScale: uElevScale, uTerrainExag: uTerrainExag,
uSunDir: uSunDir, uMoonDir: uMoonDir, uMode: uMode,
uAtmoModelOn: uAtmoModelOn, uAtmoHeightUnits: uAtmoHeightUnits,
@@ -1487,6 +1492,9 @@ if (window.CONFIG && window.CONFIG.clouds) {
}
CLOUD_TOP = Math.max(0.2, Math.min(CLOUD_TOP, 2.0));
CLOUD_BOT = Math.min(CLOUD_BOT, CLOUD_TOP - 0.4);
var CLOUD_NEAR_FADE_CFG = (window.CONFIG && window.CONFIG.clouds && window.CONFIG.clouds.nearFade) || {};
var CLOUD_NEAR_FADE_START = (typeof CLOUD_NEAR_FADE_CFG.start === 'number') ? Math.max(0, CLOUD_NEAR_FADE_CFG.start) : 0.35;
var CLOUD_NEAR_FADE_END = Math.max(CLOUD_NEAR_FADE_START + 0.1, (typeof CLOUD_NEAR_FADE_CFG.end === 'number') ? CLOUD_NEAR_FADE_CFG.end : 2.5);
var CLOUDS_ON = !(window.CONFIG && window.CONFIG.clouds && window.CONFIG.clouds.enabled === false);
var CLOUD_WIND_CFG = (window.CONFIG && window.CONFIG.clouds && window.CONFIG.clouds.wind) || {};
var CLOUD_WIND_SCALE = (typeof CLOUD_WIND_CFG.speedScale === 'number') ? Math.max(0, CLOUD_WIND_CFG.speedScale) : 80;
@@ -7355,6 +7363,8 @@ window.clouds3dRender = function(target) {
gl.uniform1f(s.uSpeed, speed);
gl.uniform1f(s.uCloudTop, CLOUD_TOP);
gl.uniform1f(s.uCloudBot, CLOUD_BOT);
gl.uniform1f(s.uCloudNearFadeStart, CLOUD_NEAR_FADE_START);
gl.uniform1f(s.uCloudNearFadeEnd, CLOUD_NEAR_FADE_END);
// Ground mosaic uniforms + periodic re-fetch trigger.
// uGroundCenter is the world position (X, Z) of the centre tile's