Skip to content

Viewer: Improve near/far clipping plane calculation #13744

@magnesj

Description

@magnesj

Summary

The current clipping plane calculation uses the scene-wide bounding box, which causes distant off-screen objects to inflate the far plane. This degrades depth buffer precision and leads to z-fighting.

Proposed Improvements

  • Frustum culling per model: Iterate per-model bounding boxes and skip models that are entirely outside the camera frustum. Fall back to the scene-wide bounding box if no model contributes.
  • Max far/near ratio: Enforce a maximum far/near ratio of 3000.0 by pushing the near plane forward if necessary. A 24-bit depth buffer has ~16 M discrete depth values; capping the ratio ensures sufficient depth resolution near the camera.
  • Near plane refinement when zooming: When the camera is inside or past the bounding box, adjust the near plane based on the point-of-interest distance to prevent geometry clipping when zooming into details.

Motivation

  • Reduces z-fighting caused by a degraded far plane from off-screen geometry
  • Improves depth buffer precision for large reservoir models where objects can span very large coordinate ranges
  • Prevents near-plane clipping when zooming into details

Further improvements

To further reduce z-fighting the depth buffer can use logarithmic binning of depth. Testing has so far indicated that improvements to the clipping planes fixes most of the issues seen in current test cases. Logarithmic binning is tested, and involves changing several shaders here magnesj#751

Metadata

Metadata

Assignees

Labels

BugInReleaseBug in an official release

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions