Skip to content

Conversation

@mjkkirschner
Copy link
Member

@mjkkirschner mjkkirschner commented Jan 12, 2021

Purpose

This PR removes vertex nudging in the vertex shader - this nudging was done for vertex colored geometry and selected geometry.

It never worked well for vertex colors because for some unknown reason all geometry has vertex colors.
It kind of wokrked for selected geometry, but for small geometry the nudging could actually make the geometry appear exploded when selected.

This PR instead uses depthBias https://docs.microsoft.com/en-us/windows/win32/direct3d11/d3d10-graphics-programming-guide-output-merger-stage-depth-bias which is for controlling which of two coplanar polygons will appear in front by nudging not the verts, but their positions in the depth buffer. We don't lose early z or other perf tricks with this like we would with writing to the depth buffer ourselves.

logic is as follows:
when a mesh is created we assign a depth bias depending on if the render package marks the mesh for vertex colors or not.

Later when the mesh is selected, we set the depth bias to 0, so it renders in front of everything else, then when unselected we set the values back to the defaults which were used at construction time.

In my manual tests it seems to work pretty well, vertex color geometry is still hit or miss because of the long standing issue that all geometry has vertex colors, but selection highlight seems robust.

TODO

  • add image comparison tests.

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

set depth bias high for non selected geometry
set depth bias for meshes on selection and deselection
do not push verts along normals
Copy link
Contributor

@sm6srw sm6srw left a comment

Choose a reason for hiding this comment

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

Great, looks like a simplification to me. One small thing then LGTM!

internal const double DefaultFarClipDistance = 100000;
private const int DepthBiasVertexColors = 10;
private const int DepthBiasNormalMesh = 100;
private const int DepthBiasSelectedMesh = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious how you ended up with these numbers? Maybe worth a comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

Are they the same as the old shader implementation?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't reference the old shader, but I can look - I vaguely remember both depth bias and nudging were used.

The docs for depth-bias describe that the numbers can be interpreted multiple ways depending on the format of the depth buffer - I tried to find values that would work in either case. See the link above.

Copy link
Member Author

@mjkkirschner mjkkirschner Jan 12, 2021

Choose a reason for hiding this comment

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

to me - it looks like helix uses a 32bit depth buffer (and 8 bit stencil buffer) -

DXGI_FORMAT_D32_FLOAT_S8X24_UINT A 32-bit floating-point component, and two unsigned-integer components (with an additional 32 bits). This format supports 32-bit depth, 8-bit stencil, and 24 bits are unused.⁵

which means the value is scaled by 1/(2^32), something like:
Example: DepthBias = 100 ==> Actual DepthBias = 100/2^32 = .0000003

very small changes in depth.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you explain the difference between VertexColors and NormalMesh and why they require different depth biases?

Copy link
Member Author

@mjkkirschner mjkkirschner Jan 12, 2021

Choose a reason for hiding this comment

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

@aparajit-pratap - imagine the case where you have two spheres at the same position, with the same radius. One was created by the ByGeometryColor node - IMO the preferred behavior is that the colored sphere appears on top of the non colored sphere.

Today this doesn't work because most DynamoModelGeometry3d objects have vertex colors (white ones, contributing no color) - I'm not sure why. When we address that this will ensure that objects with vertex colors are drawn on top of geometry without colors)

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