@@ -652,17 +652,24 @@ namespace dxvk {
652
652
653
653
// Search the BLAS for an instance matching ours
654
654
{
655
- const auto adjacentCells = blas.getSpatialMap ().getDataNearPos (worldPosition);
656
- for (const std::vector<const RtInstance*>* cellPtr : adjacentCells){
657
- for (const RtInstance* instance : *cellPtr) {
658
- if (instance->m_frameLastUpdated == currentFrameIdx) {
659
- // If the transform is an exact match and the instance has already been touched this frame,
660
- // then this is a second draw call on a single mesh.
655
+ // Search for an exact match
656
+ const std::vector<const RtInstance*>* matchingCell = blas.getSpatialMap ().getDataAtPos (worldPosition);
657
+ if (matchingCell != nullptr ) {
658
+ for (const RtInstance* instance : *matchingCell) {
661
659
const Matrix4 instanceTransform = instance->getTransform ();
660
+ // Note: this may be the second call this frame targetting the same instance.
662
661
if (memcmp (&transform, &instanceTransform, sizeof (instanceTransform)) == 0 ) {
663
662
return const_cast <RtInstance*>(instance);
664
663
}
665
- } else if (instance->m_materialHash == material.getHash ()) {
664
+ }
665
+ }
666
+
667
+ // No exact match, so find the closest match in the region
668
+ // (need to check a 2x2x2 patch of cells to account for positions close to a border)
669
+ const auto adjacentCells = blas.getSpatialMap ().getDataNearPos (worldPosition);
670
+ for (const std::vector<const RtInstance*>* cellPtr : adjacentCells){
671
+ for (const RtInstance* instance : *cellPtr) {
672
+ if (instance->m_frameLastUpdated != currentFrameIdx && instance->m_materialHash == material.getHash ()) {
666
673
// Instance hasn't been touched yet this frame.
667
674
668
675
const Vector3& prevInstanceWorldPosition = instance->getSpatialCachePosition ();
0 commit comments