Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move near clipping plane further away for more depth buffer precision. #13338

Merged
merged 2 commits into from
Sep 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Watch3D/HelixWatch3DViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down Expand Up @@ -183,7 +183,9 @@ public class HelixWatch3DViewModel : DefaultWatch3DViewModel
private int currentFrameSkipCount;

private const double EqualityTolerance = 0.000001;
private double nearPlaneDistanceFactor = 0.001;
//near plane distance also affects depth precision.
//https://developer.nvidia.com/content/depth-precision-visualized
private double nearPlaneDistanceFactor = 0.01;
mjkkirschner marked this conversation as resolved.
Show resolved Hide resolved
internal const double DefaultNearClipDistance = 0.1f;
internal const double DefaultFarClipDistance = 100000;

Expand Down Expand Up @@ -2483,6 +2485,10 @@ internal static void ComputeClipPlaneDistances(Vector3 cameraPosition, Vector3 c
// Set the near clip plane to some fraction of the
// of the distance to the first point.
var closest = distances.First(d => d >= 0);

//near plane distance disproportionately affects depth (zbuffer) precision.
//keep it as far away as possible.
//https://developer.nvidia.com/content/depth-precision-visualized
near = closest.AlmostEqualTo(0, EqualityTolerance) ? DefaultNearClipDistance : Math.Max(DefaultNearClipDistance, closest * nearPlaneDistanceFactor);
far = distances.Last() * 2;

Expand Down