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

Conversation

mjkkirschner
Copy link
Member

@mjkkirschner mjkkirschner commented Sep 24, 2022

Purpose

An issue stemming from this change:
#12607
reported here:
https://forum.dynamobim.com/t/edges-preview-issue-why-do-the-edges-look-like-this-in-the-new-version-of-dynamo/81229

The artifact that is shown is that edges of the surfaces which should be hidden are being drawn as if they are on top of the surfaces in front of them.

While testing this I noticed that the effect was worse the further the geometry was from the camera (as we zoomed out).
My guess is that the depth buffer is not as precise far from the near plane, especially as our near and far plane are calculated dynamically as the camera moves.

As we introduce depth bias, those changes, while small near the near plane, become larger as precision decreases at the far plane.

I believe this article confirms my hypothesis:
https://developer.nvidia.com/content/depth-precision-visualized
Screen Shot 2022-09-23 at 10 29 27 PM

okay so - some options:

  1. implement this reversed depth buffer approach mentioned in the article - I don't believe helix supports this so we'd need to do a bunch of work there, and likely in our shaders as well.
  2. this PR - simply moves the near plane further out (by a factor of 10) - we get a bit more precision, but we still keep the near plane in front of any geometry.
  3. reduce our depth buffer biases - this will yield more z-fighting in general, but can probably still be made to work for selected geometry.

This PR goes with 2.

It seems to work for current issue at hand reducing most of the artifacting lines, and it also still works for the TSplines example we fixed in the previous PR that introduced this issue.

some before and after images:

Screen Shot 2022-09-23 at 10 56 49 PM

Screen Shot 2022-09-23 at 10 55 25 PM

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Release Notes

Attempted to improve rendering of curves that should be hidden by meshes when geometry is far from camera.

Reviewers

(FILL ME IN) Reviewer 1 (If possible, assign the Reviewer for the PR)

(FILL ME IN, optional) Any additional notes to reviewers or testers.

FYIs

(FILL ME IN, Optional) Names of anyone else you wish to be notified of

Copy link
Contributor

@pinzart90 pinzart90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I guess adding a test for this is way too hard (unless we do image analysis/comparison)
Maybe we can add a separate jira task to analyze solutions for the most common z fighting/depth buffer issues that users might come across .

@mjkkirschner
Copy link
Member Author

LGTM, I guess adding a test for this is way too hard (unless we do image analysis) Maybe we can add a separate jira task to analyze solutions for the most common z fighting/depth buffer issues that users might come across .

We actually have image comparison tests! Unfortunately to keep them stable between graphics cards and different machines we needed to add quite a big fuzz factor :( - we could revisit that at some point as well.

@pinzart90
Copy link
Contributor

@mjkkirschner do you think there might be any performance implications for this change ?

@mjkkirschner
Copy link
Member Author

mjkkirschner commented Sep 26, 2022

@mjkkirschner do you think there might be any performance implications for this change ?

I think the GPU in modern graphics libraries (dx11 > etc) will not render multiple pixels at the same location if the depth of the new pixel is greater than something already in the depth buffer - but I cannot remember exactly. If thats true, than performance should be the same...

@aparajit-pratap
Copy link
Contributor

Are these near plane and far plane constants that you're playing with in this PR the a and b values in that depth bias equation?

@mjkkirschner
Copy link
Member Author

mjkkirschner commented Sep 26, 2022

Are these near plane and far plane constants that you're playing with in this PR the a and b values in that depth bias equation?

The equation in the article that includes a and b is not a depth bias equation - but the depth equation from the world z... so yes and no, the a and b are definitely related to the near and far plane in that equation, but d is not depth bias, but depth. (the value in the buffer)

depth bias has its own horrible equation depending on what format the buffer is in - Helix appears to use a 32bit float depth buffer.

@aparajit-pratap
Copy link
Contributor

I'm not sure I understand - you say that the near and far plane distances are calculated dynamically depending on the camera position. If that's the case, then what is this constant value?
nearPlaneDistanceFactor

In any case, don't let my questions prevent you from merging this PR.

@mjkkirschner
Copy link
Member Author

mjkkirschner commented Sep 26, 2022

@aparajit-pratap as one moves the camera, or zooms we do this:
near = closest.AlmostEqualTo(0, EqualityTolerance) ? DefaultNearClipDistance : Math.Max(DefaultNearClipDistance, closest * nearPlaneDistanceFactor);

in most cases this boils down to:
distance to closest model object * nearPlaneDistanceFactor: the smaller the factor is the nearer to zero the near plane will be, and the less precision we will have in the depth buffer.

@mjkkirschner mjkkirschner merged commit f6253a5 into DynamoDS:master Sep 26, 2022
@mjkkirschner mjkkirschner deleted the dyn5289 branch September 26, 2022 19:51
pinzart90 added a commit that referenced this pull request Sep 27, 2022
* add nunit test adapter for 2022 (#13313)

* add nunit test adapter for 2022

* update

* Update Setup.cs

* update

* Update DynamoCore.csproj

* Create System.Net.Http.dll

* update

* update

Co-authored-by: pinzart <[email protected]>

* Filter Mouse Pressed Removed (#13319)

- removed flashing white color on mouse pressed for the filter ui element

* Fixing horizontal center (#13312)

* Update Node AutoComplete Dialog Visuals (#13329)

* Update Node AutoComplete Visuals

* Reuse style from central location

* Add editorconfig (#13233)

* Dyn5272 (#13334)

tests pass - merging this then will send cherry pick

* Dyn 5159 import export preferences (#13301)

* Import Export Settings

* Info Icons

* Indentation

* Using Dynamo View Model reference

* Moving the methods to the proper places according to their accessibility

* Handling Generic Exceptions

* updating the RaisePropertyChanged

* Extracting the import extension file as a variable

* Unique file name

* Changing the access level

* Various revisions

* Cleaning vars

* Adding Unit Test

* Adding Comments and cleaning vars

* Removing unnecessary methods

* Refactoring to get the static fields automatically

* Updating the Unit Test

* checking new settings file

* Adding validation info

* Getting First Property with the same value

* Updating valid TrustedLocations entries

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

passed here:
merging.

* Keep Node AutoComplete popup hidden when window deactivated (#13337)

* Keep Node AutoComplete popup hidden when window deactivated

* Add condition and null checks

* comments

Co-authored-by: pinzart90 <[email protected]>
Co-authored-by: pinzart <[email protected]>
Co-authored-by: Deyan Nenov <[email protected]>
Co-authored-by: jesusalvino <[email protected]>
Co-authored-by: Aaron (Qilong) <[email protected]>
Co-authored-by: Aabishkar KC <[email protected]>
mjkkirschner added a commit that referenced this pull request Sep 28, 2022
…3343)

* add nunit test adapter for 2022 (#13313)

* add nunit test adapter for 2022

* update

* Update Setup.cs

* update

* Update DynamoCore.csproj

* Create System.Net.Http.dll

* update

* update

Co-authored-by: pinzart <[email protected]>

* Filter Mouse Pressed Removed (#13319)

- removed flashing white color on mouse pressed for the filter ui element

* Fixing horizontal center (#13312)

* Update Node AutoComplete Dialog Visuals (#13329)

* Update Node AutoComplete Visuals

* Reuse style from central location

* Add editorconfig (#13233)

* Dyn5272 (#13334)

tests pass - merging this then will send cherry pick

* Dyn 5159 import export preferences (#13301)

* Import Export Settings

* Info Icons

* Indentation

* Using Dynamo View Model reference

* Moving the methods to the proper places according to their accessibility

* Handling Generic Exceptions

* updating the RaisePropertyChanged

* Extracting the import extension file as a variable

* Unique file name

* Changing the access level

* Various revisions

* Cleaning vars

* Adding Unit Test

* Adding Comments and cleaning vars

* Removing unnecessary methods

* Refactoring to get the static fields automatically

* Updating the Unit Test

* checking new settings file

* Adding validation info

* Getting First Property with the same value

* Updating valid TrustedLocations entries

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

passed here:
merging.

* add more failing tests

* implement case 2 of replication

* Update ReplicationTests.cs

* add failing test

* add some more failing tests

* add some lacing tests that use arb rank params

* fix tests

1. Missing replication Longest/Shortest attribute
2. Fix result - wrap in list (like old VM)

Co-authored-by: pinzart90 <[email protected]>
Co-authored-by: pinzart <[email protected]>
Co-authored-by: Deyan Nenov <[email protected]>
Co-authored-by: jesusalvino <[email protected]>
Co-authored-by: Aaron (Qilong) <[email protected]>
Co-authored-by: Aabishkar KC <[email protected]>
Co-authored-by: kirschm <[email protected]>
aparajit-pratap added a commit that referenced this pull request Sep 28, 2022
* add nunit test adapter for 2022 (#13313)

* add nunit test adapter for 2022

* update

* Update Setup.cs

* update

* Update DynamoCore.csproj

* Create System.Net.Http.dll

* update

* update

Co-authored-by: pinzart <[email protected]>

* Filter Mouse Pressed Removed (#13319)

- removed flashing white color on mouse pressed for the filter ui element

* Fixing horizontal center (#13312)

* Update Node AutoComplete Dialog Visuals (#13329)

* Update Node AutoComplete Visuals

* Reuse style from central location

* Add editorconfig (#13233)

* Dyn5272 (#13334)

tests pass - merging this then will send cherry pick

* Dyn 5159 import export preferences (#13301)

* Import Export Settings

* Info Icons

* Indentation

* Using Dynamo View Model reference

* Moving the methods to the proper places according to their accessibility

* Handling Generic Exceptions

* updating the RaisePropertyChanged

* Extracting the import extension file as a variable

* Unique file name

* Changing the access level

* Various revisions

* Cleaning vars

* Adding Unit Test

* Adding Comments and cleaning vars

* Removing unnecessary methods

* Refactoring to get the static fields automatically

* Updating the Unit Test

* checking new settings file

* Adding validation info

* Getting First Property with the same value

* Updating valid TrustedLocations entries

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

passed here:
merging.

* add more failing tests

* implement case 2 of replication

* Update ReplicationTests.cs

* add failing test

* add some more failing tests

* add replication test

* fix merge conflict

* fix merge conflict

Co-authored-by: pinzart90 <[email protected]>
Co-authored-by: pinzart <[email protected]>
Co-authored-by: Deyan Nenov <[email protected]>
Co-authored-by: jesusalvino <[email protected]>
Co-authored-by: Aaron (Qilong) <[email protected]>
Co-authored-by: Aabishkar KC <[email protected]>
Co-authored-by: Michael Kirschner <[email protected]>
Co-authored-by: kirschm <[email protected]>
aparajit-pratap added a commit that referenced this pull request Sep 28, 2022
* add nunit test adapter for 2022 (#13313)

* add nunit test adapter for 2022

* update

* Update Setup.cs

* update

* Update DynamoCore.csproj

* Create System.Net.Http.dll

* update

* update

Co-authored-by: pinzart <[email protected]>

* Filter Mouse Pressed Removed (#13319)

- removed flashing white color on mouse pressed for the filter ui element

* Fixing horizontal center (#13312)

* Update Node AutoComplete Dialog Visuals (#13329)

* Update Node AutoComplete Visuals

* Reuse style from central location

* Add editorconfig (#13233)

* Dyn5272 (#13334)

tests pass - merging this then will send cherry pick

* Dyn 5159 import export preferences (#13301)

* Import Export Settings

* Info Icons

* Indentation

* Using Dynamo View Model reference

* Moving the methods to the proper places according to their accessibility

* Handling Generic Exceptions

* updating the RaisePropertyChanged

* Extracting the import extension file as a variable

* Unique file name

* Changing the access level

* Various revisions

* Cleaning vars

* Adding Unit Test

* Adding Comments and cleaning vars

* Removing unnecessary methods

* Refactoring to get the static fields automatically

* Updating the Unit Test

* checking new settings file

* Adding validation info

* Getting First Property with the same value

* Updating valid TrustedLocations entries

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

passed here:
merging.

* add more failing tests

* implement case 2 of replication

* Update ReplicationTests.cs

* add failing test

* add some more failing tests

* add replication test

* fix merge conflict

* fix merge conflict

* update replication test

Co-authored-by: pinzart90 <[email protected]>
Co-authored-by: pinzart <[email protected]>
Co-authored-by: Deyan Nenov <[email protected]>
Co-authored-by: jesusalvino <[email protected]>
Co-authored-by: Aaron (Qilong) <[email protected]>
Co-authored-by: Aabishkar KC <[email protected]>
Co-authored-by: Michael Kirschner <[email protected]>
Co-authored-by: kirschm <[email protected]>
sm6srw pushed a commit to sm6srw/Dynamo that referenced this pull request Jan 20, 2023
…namoDS#13343)

* add nunit test adapter for 2022 (DynamoDS#13313)

* add nunit test adapter for 2022

* update

* Update Setup.cs

* update

* Update DynamoCore.csproj

* Create System.Net.Http.dll

* update

* update

Co-authored-by: pinzart <[email protected]>

* Filter Mouse Pressed Removed (DynamoDS#13319)

- removed flashing white color on mouse pressed for the filter ui element

* Fixing horizontal center (DynamoDS#13312)

* Update Node AutoComplete Dialog Visuals (DynamoDS#13329)

* Update Node AutoComplete Visuals

* Reuse style from central location

* Add editorconfig (DynamoDS#13233)

* Dyn5272 (DynamoDS#13334)

tests pass - merging this then will send cherry pick

* Dyn 5159 import export preferences (DynamoDS#13301)

* Import Export Settings

* Info Icons

* Indentation

* Using Dynamo View Model reference

* Moving the methods to the proper places according to their accessibility

* Handling Generic Exceptions

* updating the RaisePropertyChanged

* Extracting the import extension file as a variable

* Unique file name

* Changing the access level

* Various revisions

* Cleaning vars

* Adding Unit Test

* Adding Comments and cleaning vars

* Removing unnecessary methods

* Refactoring to get the static fields automatically

* Updating the Unit Test

* checking new settings file

* Adding validation info

* Getting First Property with the same value

* Updating valid TrustedLocations entries

* move near clipping plane further away for more depth buffer precision. (DynamoDS#13338)

passed here:
merging.

* add more failing tests

* implement case 2 of replication

* Update ReplicationTests.cs

* add failing test

* add some more failing tests

* add some lacing tests that use arb rank params

* fix tests

1. Missing replication Longest/Shortest attribute
2. Fix result - wrap in list (like old VM)

Co-authored-by: pinzart90 <[email protected]>
Co-authored-by: pinzart <[email protected]>
Co-authored-by: Deyan Nenov <[email protected]>
Co-authored-by: jesusalvino <[email protected]>
Co-authored-by: Aaron (Qilong) <[email protected]>
Co-authored-by: Aabishkar KC <[email protected]>
Co-authored-by: kirschm <[email protected]>
sm6srw pushed a commit to sm6srw/Dynamo that referenced this pull request Jan 20, 2023
* add nunit test adapter for 2022 (DynamoDS#13313)

* add nunit test adapter for 2022

* update

* Update Setup.cs

* update

* Update DynamoCore.csproj

* Create System.Net.Http.dll

* update

* update

Co-authored-by: pinzart <[email protected]>

* Filter Mouse Pressed Removed (DynamoDS#13319)

- removed flashing white color on mouse pressed for the filter ui element

* Fixing horizontal center (DynamoDS#13312)

* Update Node AutoComplete Dialog Visuals (DynamoDS#13329)

* Update Node AutoComplete Visuals

* Reuse style from central location

* Add editorconfig (DynamoDS#13233)

* Dyn5272 (DynamoDS#13334)

tests pass - merging this then will send cherry pick

* Dyn 5159 import export preferences (DynamoDS#13301)

* Import Export Settings

* Info Icons

* Indentation

* Using Dynamo View Model reference

* Moving the methods to the proper places according to their accessibility

* Handling Generic Exceptions

* updating the RaisePropertyChanged

* Extracting the import extension file as a variable

* Unique file name

* Changing the access level

* Various revisions

* Cleaning vars

* Adding Unit Test

* Adding Comments and cleaning vars

* Removing unnecessary methods

* Refactoring to get the static fields automatically

* Updating the Unit Test

* checking new settings file

* Adding validation info

* Getting First Property with the same value

* Updating valid TrustedLocations entries

* move near clipping plane further away for more depth buffer precision. (DynamoDS#13338)

passed here:
merging.

* add more failing tests

* implement case 2 of replication

* Update ReplicationTests.cs

* add failing test

* add some more failing tests

* add replication test

* fix merge conflict

* fix merge conflict

Co-authored-by: pinzart90 <[email protected]>
Co-authored-by: pinzart <[email protected]>
Co-authored-by: Deyan Nenov <[email protected]>
Co-authored-by: jesusalvino <[email protected]>
Co-authored-by: Aaron (Qilong) <[email protected]>
Co-authored-by: Aabishkar KC <[email protected]>
Co-authored-by: Michael Kirschner <[email protected]>
Co-authored-by: kirschm <[email protected]>
sm6srw pushed a commit to sm6srw/Dynamo that referenced this pull request Jan 20, 2023
* add nunit test adapter for 2022 (DynamoDS#13313)

* add nunit test adapter for 2022

* update

* Update Setup.cs

* update

* Update DynamoCore.csproj

* Create System.Net.Http.dll

* update

* update

Co-authored-by: pinzart <[email protected]>

* Filter Mouse Pressed Removed (DynamoDS#13319)

- removed flashing white color on mouse pressed for the filter ui element

* Fixing horizontal center (DynamoDS#13312)

* Update Node AutoComplete Dialog Visuals (DynamoDS#13329)

* Update Node AutoComplete Visuals

* Reuse style from central location

* Add editorconfig (DynamoDS#13233)

* Dyn5272 (DynamoDS#13334)

tests pass - merging this then will send cherry pick

* Dyn 5159 import export preferences (DynamoDS#13301)

* Import Export Settings

* Info Icons

* Indentation

* Using Dynamo View Model reference

* Moving the methods to the proper places according to their accessibility

* Handling Generic Exceptions

* updating the RaisePropertyChanged

* Extracting the import extension file as a variable

* Unique file name

* Changing the access level

* Various revisions

* Cleaning vars

* Adding Unit Test

* Adding Comments and cleaning vars

* Removing unnecessary methods

* Refactoring to get the static fields automatically

* Updating the Unit Test

* checking new settings file

* Adding validation info

* Getting First Property with the same value

* Updating valid TrustedLocations entries

* move near clipping plane further away for more depth buffer precision. (DynamoDS#13338)

passed here:
merging.

* add more failing tests

* implement case 2 of replication

* Update ReplicationTests.cs

* add failing test

* add some more failing tests

* add replication test

* fix merge conflict

* fix merge conflict

* update replication test

Co-authored-by: pinzart90 <[email protected]>
Co-authored-by: pinzart <[email protected]>
Co-authored-by: Deyan Nenov <[email protected]>
Co-authored-by: jesusalvino <[email protected]>
Co-authored-by: Aaron (Qilong) <[email protected]>
Co-authored-by: Aabishkar KC <[email protected]>
Co-authored-by: Michael Kirschner <[email protected]>
Co-authored-by: kirschm <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants