perf: adaptive cloud march length

This commit is contained in:
Richard Zink committed 2026-10-13 20:27:38 +02:00
1 parent 30c5b4eb7c
commit b4d44079ea
2 files changed
+31 -1

No files matched your search

+12
View File
@@ -91,6 +91,18 @@ window.CONFIG = {
// GPU bound. Read once at context creation, so a reload is needed.
antialias: false, // false saves GPU fill rate
// ------------------------------------------------------------------
// Performance
// ------------------------------------------------------------------
// Adaptive cloud raymarch: shortens the cloud march when the debug FPS
// drops, and lengthens it again when the scene stays comfortably fast.
performance: {
adaptiveCloudMarch: true,
lowFps: 24, // reduce march below this FPS
highFps: 35, // restore march above this FPS
minCloudMarchUnits: 45 // never shorten below this raymarch length
},
// ------------------------------------------------------------------
// Location
// ------------------------------------------------------------------
+19 -1
View File
@@ -1537,6 +1537,24 @@ var CLOUD_HORIZON_SOFT = CLOUD_SOFT_EDGES && (typeof window.CONFIG.clouds.horizo
? Math.max(0.1, Math.min(40.0, window.CONFIG.clouds.horizonSoftness)) : (CLOUD_SOFT_EDGES ? 8.0 : 0.1);
var CLOUD_MAX_MARCH_UNITS = (window.CONFIG && typeof window.CONFIG.clouds.maxMarchUnits === 'number')
? Math.max(10.0, Math.min(300.0, window.CONFIG.clouds.maxMarchUnits)) : 30.0;
var PERF_CFG = (window.CONFIG && window.CONFIG.performance) || {};
var ADAPTIVE_CLOUD_MARCH = PERF_CFG.adaptiveCloudMarch !== false;
var ADAPTIVE_LOW_FPS = (typeof PERF_CFG.lowFps === 'number') ? Math.max(5, PERF_CFG.lowFps) : 24;
var ADAPTIVE_HIGH_FPS = (typeof PERF_CFG.highFps === 'number') ? Math.max(ADAPTIVE_LOW_FPS + 1, PERF_CFG.highFps) : 35;
var CLOUD_MARCH_MIN = (typeof PERF_CFG.minCloudMarchUnits === 'number')
? Math.max(10.0, Math.min(CLOUD_MAX_MARCH_UNITS, PERF_CFG.minCloudMarchUnits)) : Math.min(45.0, CLOUD_MAX_MARCH_UNITS);
var adaptiveCloudMarchUnits = CLOUD_MAX_MARCH_UNITS;
function updateAdaptiveCloudMarch() {
if (!ADAPTIVE_CLOUD_MARCH) return CLOUD_MAX_MARCH_UNITS;
var fps = Number(window.__fps || 0);
if (!fps || fps <= 0) return adaptiveCloudMarchUnits;
if (fps < ADAPTIVE_LOW_FPS) {
adaptiveCloudMarchUnits = Math.max(CLOUD_MARCH_MIN, adaptiveCloudMarchUnits - 10);
} else if (fps > ADAPTIVE_HIGH_FPS) {
adaptiveCloudMarchUnits = Math.min(CLOUD_MAX_MARCH_UNITS, adaptiveCloudMarchUnits + 5);
}
return adaptiveCloudMarchUnits;
}
var CLOUD_TERRAIN_OCCLUSION = !(window.CONFIG && window.CONFIG.clouds && window.CONFIG.clouds.terrainOcclusion === 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;
@@ -7418,7 +7436,7 @@ window.clouds3dRender = function(target) {
gl.uniform1f(s.uCloudBot, CLOUD_BOT);
gl.uniform1f(s.uCloudEdgeSoft, CLOUD_EDGE_SOFT);
gl.uniform1f(s.uCloudHorizonSoft, CLOUD_HORIZON_SOFT);
gl.uniform1f(s.uCloudMaxMarch, CLOUD_MAX_MARCH_UNITS);
gl.uniform1f(s.uCloudMaxMarch, updateAdaptiveCloudMarch());
gl.uniform1f(s.uCloudNearFadeStart, CLOUD_NEAR_FADE_START);
gl.uniform1f(s.uCloudNearFadeEnd, CLOUD_NEAR_FADE_END);