Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck committed Dec 6, 2024
1 parent 97ea35e commit 93c5998
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,15 @@ class Camera extends Element {
vec.sub2(bound.center, cameraPosition);
const dist = vec.dot(forwardVec);

this.far = dist + boundRadius;
// if camera is placed inside the sphere bound calculate near based far
this.near = Math.max(1e-6, dist < boundRadius ? this.far / (1024 * 16) : dist - boundRadius);
if (dist > 0) {
this.far = dist + boundRadius;
// if camera is placed inside the sphere bound calculate near based far
this.near = Math.max(1e-6, dist < boundRadius ? this.far / (1024 * 16) : dist - boundRadius);
} else {
// if the scene is behind the camera
this.far = boundRadius * 2;
this.near = this.far / (1024 * 16);
}
}

onPreRender() {
Expand Down

0 comments on commit 93c5998

Please sign in to comment.