Skip to content

Commit

Permalink
Merge pull request #1626 from benemer/master
Browse files Browse the repository at this point in the history
Fix prime number in voxel hashing
  • Loading branch information
Idclip authored Jul 4, 2023
2 parents f4cdcd6 + d57bca5 commit 19710c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion nanovdb/nanovdb/NanoVDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,10 @@ class Coord

/// @brief Return a hash key derived from the existing coordinates.
/// @details For details on this hash function please see the VDB paper.
/// The prime numbers are modified based on the ACM Transactions on Graphics paper:
/// "Real-time 3D reconstruction at scale using voxel hashing"
template<int Log2N = 3 + 4 + 5>
__hostdev__ uint32_t hash() const { return ((1 << Log2N) - 1) & (mVec[0] * 73856093 ^ mVec[1] * 19349663 ^ mVec[2] * 83492791); }
__hostdev__ uint32_t hash() const { return ((1 << Log2N) - 1) & (mVec[0] * 73856093 ^ mVec[1] * 19349669 ^ mVec[2] * 83492791); }

/// @brief Return the octant of this Coord
//__hostdev__ size_t octant() const { return (uint32_t(mVec[0])>>31) | ((uint32_t(mVec[1])>>31)<<1) | ((uint32_t(mVec[2])>>31)<<2); }
Expand Down
6 changes: 4 additions & 2 deletions openvdb/openvdb/math/Coord.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,15 @@ class Coord

/// @brief Return a hash value for this coordinate
/// @note Log2N is the binary logarithm of the hash table size.
/// @details The hash function is taken from the SIGGRAPH paper:
/// @details The hash function is originally taken from the SIGGRAPH paper:
/// "VDB: High-resolution sparse volumes with dynamic topology"
/// and the prime numbers are modified based on the ACM Transactions on Graphics paper:
/// "Real-time 3D reconstruction at scale using voxel hashing"
template<int Log2N = 20>
size_t hash() const
{
const uint32_t* vec = reinterpret_cast<const uint32_t*>(mVec.data());
return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349663 ^ vec[2]*83492791);
return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349669 ^ vec[2]*83492791);
}

private:
Expand Down

0 comments on commit 19710c1

Please sign in to comment.