From dcf6778423487c3756a1f48ed8511871882fdf84 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 3 May 2026 13:35:13 +0200 Subject: [PATCH] Improve hysteresis distance calculation and add view frustum checks for foliage culling --- src/foliage/foliage-render-batches.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/foliage/foliage-render-batches.ts b/src/foliage/foliage-render-batches.ts index 8fa2d2a7..9a180c4a 100644 --- a/src/foliage/foliage-render-batches.ts +++ b/src/foliage/foliage-render-batches.ts @@ -126,9 +126,15 @@ function distanceFromPointToCachedChunkCenter( } function getHysteresisDistance(distance: number, ratio: number): number { + const normalizedRatio = Math.max(0, ratio); + + if (normalizedRatio <= 0) { + return 0; + } + return Math.max( MIN_FOLIAGE_LOD_HYSTERESIS_DISTANCE, - Math.max(0, distance) * Math.max(0, ratio) + Math.max(0, distance) * normalizedRatio ); } @@ -569,6 +575,8 @@ export function resolveFoliageRenderChunkLod(options: { } if ( + options.view.frustum !== null && + options.view.frustum !== undefined && shouldCullCachedFoliageRenderChunkByFrustum({ chunk: options.chunk, frustum: options.view.frustum,