diff options
Diffstat (limited to 'intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h')
-rw-r--r-- | intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h b/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h index 9ab374d1fba..2f44f249c5f 100644 --- a/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h +++ b/intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h @@ -14,6 +14,11 @@ * limitations under the License. */ +#ifdef WITH_NANOVDB +# include "nanovdb/CNanoVDB.h" +# include "nanovdb/util/CSampleFromVoxels.h" +#endif + /* For OpenCL we do manual lookup and interpolation. */ ccl_device_inline ccl_global TextureInfo *kernel_tex_info(KernelGlobals *kg, uint id) @@ -223,6 +228,67 @@ ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals *kg, int id, float3 P uint interpolation = (interp == INTERPOLATION_NONE) ? info->interpolation : interp; +#ifdef WITH_NANOVDB + if (info->data_type == IMAGE_DATA_TYPE_NANOVDB_FLOAT) { + ccl_global cnanovdb_griddata *grid = + (ccl_global cnanovdb_griddata *)(kg->buffers[info->cl_buffer] + info->data); + const ccl_global cnanovdb_rootdataF *root = cnanovdb_treedata_rootF( + cnanovdb_griddata_tree(grid)); + + cnanovdb_Vec3F xyz; + xyz.mVec[0] = root->mBBox_min.mVec[0] + + x * (root->mBBox_max.mVec[0] - root->mBBox_min.mVec[0]); + xyz.mVec[1] = root->mBBox_min.mVec[1] + + y * (root->mBBox_max.mVec[1] - root->mBBox_min.mVec[1]); + xyz.mVec[2] = root->mBBox_min.mVec[2] + + z * (root->mBBox_max.mVec[2] - root->mBBox_min.mVec[2]); + + cnanovdb_readaccessor acc; + cnanovdb_readaccessor_init(&acc, root); + + float value; + switch (interpolation) { + default: + case INTERPOLATION_LINEAR: + value = cnanovdb_sampleF_trilinear(&acc, &xyz); + break; + case INTERPOLATION_CLOSEST: + value = cnanovdb_sampleF_nearest(&acc, &xyz); + break; + } + return make_float4(value, value, value, 1.0f); + } + if (info->data_type == IMAGE_DATA_TYPE_NANOVDB_FLOAT3) { + ccl_global cnanovdb_griddata *grid = + (ccl_global cnanovdb_griddata *)(kg->buffers[info->cl_buffer] + info->data); + const ccl_global cnanovdb_rootdataF3 *root = cnanovdb_treedata_rootF3( + cnanovdb_griddata_tree(grid)); + + cnanovdb_Vec3F xyz; + xyz.mVec[0] = root->mBBox_min.mVec[0] + + x * (root->mBBox_max.mVec[0] - root->mBBox_min.mVec[0]); + xyz.mVec[1] = root->mBBox_min.mVec[1] + + y * (root->mBBox_max.mVec[1] - root->mBBox_min.mVec[1]); + xyz.mVec[2] = root->mBBox_min.mVec[2] + + z * (root->mBBox_max.mVec[2] - root->mBBox_min.mVec[2]); + + cnanovdb_readaccessor acc; + cnanovdb_readaccessor_init(&acc, root); + + cnanovdb_Vec3F value; + switch (interpolation) { + default: + case INTERPOLATION_LINEAR: + value = cnanovdb_sampleF3_trilinear(&acc, &xyz); + break; + case INTERPOLATION_CLOSEST: + value = cnanovdb_sampleF3_nearest(&acc, &xyz); + break; + } + return make_float4(value.mVec[0], value.mVec[1], value.mVec[2], 1.0f); + } +#endif + if (interpolation == INTERPOLATION_CLOSEST) { /* Closest interpolation. */ int ix, iy, iz; |