Skip to content

Commit

Permalink
Trilinear filtering for NanoVDB fields
Browse files Browse the repository at this point in the history
  • Loading branch information
szellmann committed Dec 10, 2024
1 parent adcdf11 commit f168376
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions DeviceCopyableObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ using hip_index_bvh = index_bvh_t<hip::device_vector<P>, hip::device_vector<

#ifdef WITH_NANOVDB
#include <nanovdb/NanoVDB.h>
#include <nanovdb/math/SampleFromVoxels.h>
#endif

namespace visionaray {
Expand Down Expand Up @@ -445,6 +446,7 @@ struct SpatialField
#ifdef WITH_NANOVDB
struct {
nanovdb::NanoGrid<float> *grid;
tex_filter_mode filterMode;
} asNanoVDB;
#endif
};
Expand Down Expand Up @@ -498,8 +500,15 @@ inline bool sampleField(const SpatialField &sf, vec3 P, float &value) {
#ifdef WITH_NANOVDB
else if (sf.type == SpatialField::NanoVDB) {
auto acc = sf.asNanoVDB.grid->getAccessor();
value = acc.getValue(nanovdb::Coord(P.x,P.y,P.z));
return true;
if (sf.asNanoVDB.filterMode == Nearest) {
auto smp = nanovdb::math::createSampler<0>(acc);
value = smp(nanovdb::math::Vec3<float>(P.x,P.y,P.z));
return true;
} else if (sf.asNanoVDB.filterMode == Linear) {
auto smp = nanovdb::math::createSampler<1>(acc);
value = smp(nanovdb::math::Vec3<float>(P.x,P.y,P.z));
return true;
}
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions scene/volume/spatial_field/NanoVDBField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void NanoVDBField::commit()
vfield.asNanoVDB.grid = m_gridHandle.grid<float>();
#endif

vfield.asNanoVDB.filterMode = Linear;

vfield.voxelSpaceTransform = mat4x3(mat3::identity(),float3{0.f,0.f,0.f});

buildGrid();
Expand Down

0 comments on commit f168376

Please sign in to comment.