Refactor Camera and OceanLOD for improved movement and LOD management; enhance shader effects for better visual fidelity

This commit is contained in:
2026-01-31 23:16:31 +01:00
parent b576d6a8cf
commit 5677f03dc2
4 changed files with 190 additions and 87 deletions

View File

@@ -13,14 +13,16 @@ export class OceanLOD {
}> = [];
private readonly LOD_LEVELS = [
{ distance: 2.0, gridSize: 128 }, // Closest - highest detail
{ distance: 5.0, gridSize: 64 }, // Medium distance
{ distance: 10.0, gridSize: 32 }, // Far distance
{ distance: 20.0, gridSize: 16 }, // Very far - lowest detail
{ distance: 5.0, gridSize: 128 }, // Closest - highest detail
{ distance: 15.0, gridSize: 64 }, // Medium distance
{ distance: 40.0, gridSize: 32 }, // Far distance
{ distance: 80.0, gridSize: 16 }, // Very far
{ distance: 150.0, gridSize: 8 }, // Horizon - minimal detail
{ distance: Infinity, gridSize: 4 },// Beyond horizon - lowest detail
];
private readonly PATCH_SIZE = 2.0; // World size of each patch
private readonly PATCHES_PER_SIDE = 7; // 7x7 = 49 patches total
private readonly PATCH_SIZE = 8.0; // World size of each patch (larger for horizon coverage)
private readonly PATCHES_PER_SIDE = 51; // 51x51 = 2601 patches (covers ~200 units in each direction)
private readonly VIEW_CONE_COS = Math.cos(Math.PI * 0.45); // ~81 degree half-angle (wider than typical FOV)
constructor() {
@@ -37,7 +39,7 @@ export class OceanLOD {
// Start with lowest detail - will be updated based on camera
const grid = new Grid(
this.LOD_LEVELS[3].gridSize,
this.LOD_LEVELS[5].gridSize,
centerX,
centerY,
this.PATCH_SIZE
@@ -48,7 +50,7 @@ export class OceanLOD {
centerX,
centerY,
size: this.PATCH_SIZE,
lodLevel: 3,
lodLevel: 5,
visible: true
});
}
@@ -86,11 +88,11 @@ export class OceanLOD {
patch.visible = isInFront;
// Calculate LOD level
let newLodLevel = 3; // Default to lowest detail
let newLodLevel = 5; // Default to lowest detail
if (!isInFront) {
// Behind camera - skip (will not be drawn)
newLodLevel = 3;
newLodLevel = 5;
} else if (isInViewCone) {
// In view cone - use distance-based LOD
for (let i = 0; i < this.LOD_LEVELS.length; i++) {
@@ -103,7 +105,7 @@ export class OceanLOD {
// In front but outside view cone - reduce detail by 1-2 levels
for (let i = 0; i < this.LOD_LEVELS.length; i++) {
if (distance < this.LOD_LEVELS[i].distance) {
newLodLevel = Math.min(i + 2, 3); // Reduce detail
newLodLevel = Math.min(i + 2, 5); // Reduce detail
break;
}
}
@@ -151,7 +153,7 @@ export class OceanLOD {
/** Get statistics about current LOD distribution */
getLODStats(): { [key: number]: number } {
const stats: { [key: number]: number } = { 0: 0, 1: 0, 2: 0, 3: 0 };
const stats: { [key: number]: number } = { 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 };
for (const patch of this.grids) {
stats[patch.lodLevel]++;
}