Refactor OceanLOD and constants for improved LOD management and grid size adjustments

This commit is contained in:
2026-01-31 22:52:30 +01:00
parent c19854aefc
commit 109eafa90a
3 changed files with 19 additions and 21 deletions

View File

@@ -9,13 +9,14 @@ export class OceanLOD {
centerY: number;
size: number;
lodLevel: number;
visible: boolean;
}> = [];
private readonly LOD_LEVELS = [
{ distance: 2.0, gridSize: 256 }, // Closest - highest detail
{ distance: 5.0, gridSize: 128 }, // Medium distance
{ distance: 10.0, gridSize: 64 }, // Far distance
{ distance: 20.0, gridSize: 32 }, // Very far - lowest detail
{ 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
];
private readonly PATCH_SIZE = 2.0; // World size of each patch
@@ -47,7 +48,8 @@ export class OceanLOD {
centerX,
centerY,
size: this.PATCH_SIZE,
lodLevel: 3
lodLevel: 3,
visible: true
});
}
}
@@ -77,14 +79,17 @@ export class OceanLOD {
const dotProduct = vec3.dot(viewDir, toPatchDir);
// Determine if patch is in front of camera and within view cone
const isInFront = dotProduct > -0.2; // Slightly behind is ok for edge cases
const isInFront = dotProduct > -0.3; // Slightly behind is ok for edge cases
const isInViewCone = dotProduct > this.VIEW_CONE_COS;
// Frustum culling - don't draw patches behind camera
patch.visible = isInFront;
// Calculate LOD level
let newLodLevel = 3; // Default to lowest detail
if (!isInFront) {
// Behind camera - always lowest detail
// Behind camera - skip (will not be drawn)
newLodLevel = 3;
} else if (isInViewCone) {
// In view cone - use distance-based LOD
@@ -125,8 +130,10 @@ export class OceanLOD {
}
draw(gl: WebGL2RenderingContext, wireframe: boolean = false): void {
for (const { grid } of this.grids) {
grid.draw(gl, wireframe);
for (const patch of this.grids) {
if (patch.visible) {
patch.grid.draw(gl, wireframe);
}
}
}