Skip to content

Use AABB to better differentiate instances#67

Closed
xoxor4d wants to merge 1 commit intoNVIDIAGameWorks:mainfrom
xoxor4d:feature/aabb_inst_pr
Closed

Use AABB to better differentiate instances#67
xoxor4d wants to merge 1 commit intoNVIDIAGameWorks:mainfrom
xoxor4d:feature/aabb_inst_pr

Conversation

@xoxor4d
Copy link
Contributor

@xoxor4d xoxor4d commented Apr 1, 2024

The changes in this PR try to improve instance matching by using its AABB instead of just its world position.
This leads to more stable instances and thus in less visual artifacting -> motionblur smearing.
I think these changes can also help with switching LOD's.

The changes in action (on/off and tweaked Unique Object Search Distance - Call of Duty 4 SP):
https://drive.google.com/file/d/1MtYsdSmAw1HzKZhbvBP7VUlRBRjkEte2

I've started working on this because of the issue I've opened here: NVIDIAGameWorks/rtx-remix#450
Thanks to Alex for all the guidance (and previously Mark on discord)!

Changes

  • add Vector3 getCentroid() to AxisAlignedBoundingBox
  • use transformed bounding-box-centroid instead of world position of the instance in InstanceManager::findSimilarInstance
  • ^ in RtInstance::onTransformChanged
  • ^ in RtInstance::teleport
  • ^ in DrawCallCache::get
  • add AABB's For Instance Differentiation setting to the Heuristics tab
  • add setting check to RtxOptions::needsMeshBoundingBox to enable boundingbox calculations

The initial branch with the individual commits leading up to this squished commit is still available:
https://github.com/xoxor4d/dxvk-remix/commits/feature/aabb_inst


Vector3 newWorldPosition = Vector3(newTransform[3][0], newTransform[3][1], newTransform[3][2]);
if (RtxOptions::Get()->instanceUseBoundingBox()) {
newWorldPosition = (newTransform * Vector4(drawCall.getGeometryData().boundingBox.getCentroid(), 1.0f)).xyz();
Copy link
Collaborator

Choose a reason for hiding this comment

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

You follow the pattern of "get position, check RtxOption, replace position with transform * centroid" several times.

You could move all of this logic into the AABB class, and just depend on the whether the AABB is valid for the draw call instead of checking the RtxOption over and over:

Vector3 getTransformedCentroid(const Matrix4& transform) {
  if (isValid()) {
    return (transform * Vector4(getCentroid(), 1.f)).xyz();
  } else {
    return transform[3].xyz();
  }
}

That way we just default to using the more accurate measurement when it's available. If calculating the AABB ever shows up as a perf bottleneck in the future, we could easily swap to only calculating AABB's that are in a specific texture list or something, instead of doing it for every draw call.

Copy link
Contributor Author

@xoxor4d xoxor4d Apr 1, 2024

Choose a reason for hiding this comment

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

Fair point! I've included a toggle so that the feature can be tested / validated more easily.
Should I squash again or keep it a separate commit?

@MarkEHenderson
Copy link
Collaborator

The build failures look like they may be related to a change that went in last week. Could you make sure you're up to date with the latest code? You may need to change how you construct the vectors in some spots.

@xoxor4d
Copy link
Contributor Author

xoxor4d commented Apr 1, 2024

Hey Mark! My branch is up to date and the build is failing with the same issues that made the build fail after anon-apple pushed said changes: 7e24a52

@MarkEHenderson
Copy link
Collaborator

Oh, sorry, hadn't realized the build was already failing. I'll check if that's being looked into yet.

- add `getCentroid` to `AxisAlignedBoundingBox`
- add `getTransformedCentroid` to `AxisAlignedBoundingBox`
- use transformed bounding-box-centroid (when AABB is valid) instead of just the world transform of the instance in `InstanceManager::findSimilarInstance`
- ^ in `RtInstance::onTransformChanged`
- ^ in `RtInstance::teleport`
- ^ in `DrawCallCache::get`
- add `AABB's For Instance Differentiation` setting to the Heuristics tab
- add setting check to `RtxOptions::needsMeshBoundingBox`
@xoxor4d xoxor4d force-pushed the feature/aabb_inst_pr branch from 838f52e to fd16e7c Compare April 2, 2024 08:50
@xoxor4d
Copy link
Contributor Author

xoxor4d commented Apr 2, 2024

Okay I've now added getTransformedCentroid(). I've kept the setting to enable bounding box calculations as I was unsure what to do about RtxOptions::needsMeshBoundingBox (Should I keep the setting or just always return true here?)

@MarkEHenderson
Copy link
Collaborator

Using the setting in needsMeshBoundingBox is fine for now - by centralizing the use of your new setting in one place, it makes it easier to change the behavior later if it winds up causing a perf bottleneck somewhere.

This looks good to me, so I'll go ahead and get this merged in.

@MarkEHenderson
Copy link
Collaborator

MarkEHenderson commented Apr 8, 2024

I've just merged this internally (with a couple of edits - mostly changing the name of the option to rtx.enableAlwaysCalculateAABB).

The commit is here: 92f5637
my edits are in a separate commit

Please remember to close this PR when you have a chance.

@xoxor4d
Copy link
Contributor Author

xoxor4d commented Apr 8, 2024

Thanks Mark!

@xoxor4d xoxor4d closed this Apr 8, 2024
@xoxor4d xoxor4d deleted the feature/aabb_inst_pr branch November 1, 2024 18:25
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.

2 participants