diff --git a/src/lib/controls/MapControls.ts b/src/lib/controls/MapControls.ts index 1f4fe1b..27f72f0 100644 --- a/src/lib/controls/MapControls.ts +++ b/src/lib/controls/MapControls.ts @@ -1,7 +1,7 @@ import * as THREE from 'three'; import BaseOrbitControls from './BaseOrbitControls.js'; -const TARGET_OFFSET = 100.0; +const TARGET_OFFSET = 30.0; class MapControls extends BaseOrbitControls { #raycaster = new THREE.Raycaster(); diff --git a/src/lib/light/SceneLight.ts b/src/lib/light/SceneLight.ts index 754aab3..7f24795 100644 --- a/src/lib/light/SceneLight.ts +++ b/src/lib/light/SceneLight.ts @@ -46,6 +46,14 @@ class SceneLight { return this.#params[this.#location].fogParams; } + get fogStart() { + return this.#params[this.#location].fogParams.x; + } + + get fogEnd() { + return this.#params[this.#location].fogParams.y; + } + get fogColor() { return this.#params[this.#location].fogColor; } diff --git a/src/lib/map/MapManager.ts b/src/lib/map/MapManager.ts index 38da49a..95081ad 100644 --- a/src/lib/map/MapManager.ts +++ b/src/lib/map/MapManager.ts @@ -10,6 +10,7 @@ import MapLight from './light/MapLight.js'; import DbManager from '../db/DbManager.js'; const DEFAULT_VIEW_DISTANCE = 1277.0; +const EFFECTIVE_VIEW_DISTANCE_EXTENSION = 100.0; type MapManagerOptions = { host: AssetHost; @@ -45,6 +46,7 @@ class MapManager { #targetChunkY: number; #viewDistance = DEFAULT_VIEW_DISTANCE; + #effectiveViewDistance = this.#viewDistance; #projScreenMatrix = new THREE.Matrix4(); #cameraFrustum = new THREE.Frustum(); @@ -125,6 +127,13 @@ class MapManager { update(deltaTime: number, camera: THREE.Camera) { this.#mapLight.update(camera); + // If fog end is closer than the configured view distance, use the fog end plus extension as + // the effective view distance + this.#effectiveViewDistance = Math.min( + this.#mapLight.fogEnd + EFFECTIVE_VIEW_DISTANCE_EXTENSION, + this.#viewDistance, + ); + this.#projScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse); this.#cameraFrustum.setFromProjectionMatrix(this.#projScreenMatrix); @@ -228,7 +237,7 @@ class MapManager { } #getChunkRadius() { - return this.#viewDistance / MAP_CHUNK_HEIGHT; + return this.#effectiveViewDistance / MAP_CHUNK_HEIGHT; } #getAreaId(areaX: number, areaY: number) {