[Bf-blender-cvs] [ec26830] openvdb: Initial work to perform volume ray intersection next to the bvh intersection
Kévin Dietrich
noreply at git.blender.org
Sun Nov 13 21:43:46 CET 2016
Commit: ec26830776a90965193dff48b1ddf581ce27f685
Author: Kévin Dietrich
Date: Fri Sep 18 01:20:36 2015 +0200
Branches: openvdb
https://developer.blender.org/rBec26830776a90965193dff48b1ddf581ce27f685
Initial work to perform volume ray intersection next to the bvh intersection
===================================================================
M intern/cycles/kernel/geom/geom_bvh_volume.h
M intern/cycles/kernel/geom/geom_bvh_volume_all.h
M intern/cycles/kernel/geom/geom_qbvh_volume.h
M intern/cycles/kernel/geom/geom_qbvh_volume_all.h
M intern/cycles/kernel/kernel_volume.h
M intern/cycles/render/volume.cpp
M intern/cycles/util/util_volume.h
===================================================================
diff --git a/intern/cycles/kernel/geom/geom_bvh_volume.h b/intern/cycles/kernel/geom/geom_bvh_volume.h
index 41c7848..b94b8d4 100644
--- a/intern/cycles/kernel/geom/geom_bvh_volume.h
+++ b/intern/cycles/kernel/geom/geom_bvh_volume.h
@@ -88,6 +88,18 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
IsectPrecalc isect_precalc;
triangle_intersect_precalc(dir, &isect_precalc);
+#if 1
+ /* try to intersect with VDB volumes */
+ int num_volumes = kernel_data.tables.num_volumes;
+
+ for (int i = 0; i < num_volumes; i++) {
+ if (kg->float_volumes[i]->intersect(ray, isect)) {
+ kernel_data.tables.density_index = i;
+ return true;
+ }
+ }
+#endif
+
/* traversal loop */
do {
do {
diff --git a/intern/cycles/kernel/geom/geom_bvh_volume_all.h b/intern/cycles/kernel/geom/geom_bvh_volume_all.h
index b6db36f..dc82c41 100644
--- a/intern/cycles/kernel/geom/geom_bvh_volume_all.h
+++ b/intern/cycles/kernel/geom/geom_bvh_volume_all.h
@@ -89,6 +89,27 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
gen_idirsplat_swap(pn, shuf_identity, shuf_swap, idir, idirsplat, shufflexyz);
#endif
+#if 1
+ /* try to intersect with VDB volumes */
+ int num_volumes = kernel_data.tables.num_volumes;
+
+ for(int i = 0; i < num_volumes; i++) {
+ if(kg->float_volumes[i]->intersect(ray, isect_array)) {
+ kernel_data.tables.density_index = i;
+ isect_array++;
+ num_hits++;
+
+ if(num_hits == max_hits) {
+ return num_hits;
+ }
+ }
+ }
+
+ if(num_hits > 0) {
+ return num_hits;
+ }
+#endif
+
IsectPrecalc isect_precalc;
triangle_intersect_precalc(dir, &isect_precalc);
diff --git a/intern/cycles/kernel/geom/geom_qbvh_volume.h b/intern/cycles/kernel/geom/geom_qbvh_volume.h
index d8cfa3a..e981248 100644
--- a/intern/cycles/kernel/geom/geom_qbvh_volume.h
+++ b/intern/cycles/kernel/geom/geom_qbvh_volume.h
@@ -90,6 +90,18 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
IsectPrecalc isect_precalc;
triangle_intersect_precalc(dir, &isect_precalc);
+#if 1
+ /* try to intersect with VDB volumes */
+ int num_volumes = kernel_data.tables.num_volumes;
+
+ for (int i = 0; i < num_volumes; i++) {
+ if (kg->float_volumes[i]->intersect(ray, isect)) {
+ kernel_data.tables.density_index = i;
+ return true;
+ }
+ }
+#endif
+
/* Traversal loop. */
do {
do {
diff --git a/intern/cycles/kernel/geom/geom_qbvh_volume_all.h b/intern/cycles/kernel/geom/geom_qbvh_volume_all.h
index 056ca9a..84f34c9 100644
--- a/intern/cycles/kernel/geom/geom_qbvh_volume_all.h
+++ b/intern/cycles/kernel/geom/geom_qbvh_volume_all.h
@@ -94,6 +94,27 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
IsectPrecalc isect_precalc;
triangle_intersect_precalc(dir, &isect_precalc);
+#if 1
+ /* try to intersect with VDB volumes */
+ int num_volumes = kernel_data.tables.num_volumes;
+
+ for (int i = 0; i < num_volumes; i++) {
+ if (kg->float_volumes[i]->intersect(ray, isect_array)) {
+ kernel_data.tables.density_index = i;
+ isect_array++;
+ num_hits++;
+
+ if(num_hits == max_hits) {
+ return num_hits;
+ }
+ }
+ }
+
+ if(num_hits > 0) {
+ return num_hits;
+ }
+#endif
+
/* Traversal loop. */
do {
do {
diff --git a/intern/cycles/kernel/kernel_volume.h b/intern/cycles/kernel/kernel_volume.h
index 269088c..7a8c769 100644
--- a/intern/cycles/kernel/kernel_volume.h
+++ b/intern/cycles/kernel/kernel_volume.h
@@ -212,24 +212,34 @@ ccl_device void kernel_volume_shadow_heterogeneous(KernelGlobals *kg, PathState
float3 sum = make_float3(0.0f, 0.0f, 0.0f);
#ifdef __OPENVDB__
- int vdb_index = kernel_data.tables.density_index;
- bool has_vdb_volume = kernel_data.tables.num_volumes > 0;
+ //int vdb_index = kernel_data.tables.density_index;
+ int num_volumes = kernel_data.tables.num_volumes;
+ bool has_vdb_volume = num_volumes > 0;
float t1 = 0.0f;
+ int v = 0;
+ float_volume *volume = kg->float_volumes[0];
- if(has_vdb_volume && vdb_index >= 0 && kg->float_volumes[vdb_index]->has_uniform_voxels()) {
+ for(; v < num_volumes; v++) {
+ if(volume->intersect(ray, NULL)) {
+ break;
+ }
+ volume++;
+ }
+
+ if(has_vdb_volume && /*v < num_volumes &&*/ volume->has_uniform_voxels()) {
/* TODO(kevin): this call should be moved out of here, all it does is
* checking if we have an intersection with the boundbox of the volumue
* which in most cases corresponds to the boundbox of the object that has
* this volume. Also it initializes the rays for the ray marching. */
- if(!kg->float_volumes[vdb_index]->intersect(ray, NULL)) {
- return;
- }
+ //if(!kg->float_volumes[vdb_index]->intersect(ray, NULL)) {
+ // return;
+ //}
/* t and t1 represent the entry and exit points for each leaf node or tile
* containing active voxels. If we don't have any active node in the current
* ray path (i.e. empty space) the ray march loop is not executed,
* otherwise we loop through all leaves until the end of the volume. */
- while(kg->float_volumes[vdb_index]->march(&t, &t1)) {
+ while(volume->march(&t, &t1)) {
int i = 0;
/* Perform small steps through the current leaf or tile. */
@@ -612,24 +622,32 @@ ccl_device VolumeIntegrateResult kernel_volume_integrate_heterogeneous_distance(
bool path_missed = true;
#ifdef __OPENVDB__
+// int vdb_index = kernel_data.tables.density_index;
+ int num_volumes = kernel_data.tables.num_volumes;
+ bool has_vdb_volume = num_volumes > 0;
float t1 = 0.0f;
- int vdb_index = kernel_data.tables.density_index;
- bool has_vdb_volume = kernel_data.tables.num_volumes > 0;
+ int i;
- if(has_vdb_volume && vdb_index >= 0 && kg->float_volumes[vdb_index]->has_uniform_voxels()) {
+ for(i = 0; i < num_volumes; i++) {
+ if(kg->float_volumes[i]->intersect(ray, NULL)) {
+ break;
+ }
+ }
+
+ if(has_vdb_volume /*&& vdb_index >= 0*/ && kg->float_volumes[i]->has_uniform_voxels()) {
/* TODO(kevin): this call should be moved out of here, all it does is
* checking if we have an intersection with the boundbox of the volumue
* which in most cases corresponds to the boundbox of the object that has
* this volume. Also it initializes the rays for the ray marching. */
- if(!kg->float_volumes[vdb_index]->intersect(ray, NULL)) {
- return VOLUME_PATH_MISSED;
- }
+ //if(!kg->float_volumes[vdb_index]->intersect(ray, NULL)) {
+ // return VOLUME_PATH_MISSED;
+ //}
/* t and t1 represent the entry and exit points for each leaf node or tile
* containing active voxels. If we don't have any active node in the current
* ray path (i.e. empty space) the ray march loop is not executed,
* otherwise we loop through all leaves until the end of the volume. */
- while(kg->float_volumes[vdb_index]->march(&t, &t1)) {
+ while(kg->float_volumes[i]->march(&t, &t1)) {
path_missed = false;
/* Perform small steps through the current leaf or tile. */
diff --git a/intern/cycles/render/volume.cpp b/intern/cycles/render/volume.cpp
index 3c907e7..327a644 100644
--- a/intern/cycles/render/volume.cpp
+++ b/intern/cycles/render/volume.cpp
@@ -251,8 +251,8 @@ void VolumeManager::device_update(Device *device, DeviceScene *dscene, Scene *sc
return;
}
- dscene->data.tables.num_volumes = float_volumes.size() + float3_volumes.size();
- dscene->data.tables.density_index = find_density_slot();
+ dscene->data.tables.num_volumes = float_volumes.size()/* + float3_volumes.size()*/;
+// dscene->data.tables.density_index = find_density_slot();
VLOG(1) << "Volume samplers allocate: __float_volume, " << float_volumes.size() * sizeof(float_volume) << " bytes";
VLOG(1) << "Volume samplers allocate: __float3_volume, " << float3_volumes.size() * sizeof(float3_volume) << " bytes";
diff --git a/intern/cycles/util/util_volume.h b/intern/cycles/util/util_volume.h
index 4faae74..a6cb628 100644
--- a/intern/cycles/util/util_volume.h
+++ b/intern/cycles/util/util_volume.h
@@ -174,7 +174,7 @@ public:
}
}
- ccl_always_inline bool intersect(const Ray *ray, Intersection */*isect*/)
+ ccl_always_inline bool intersect(const Ray *ray, Intersection *isect)
{
pthread_t thread = pthread_self();
isect_map::iterator iter = isectors.find(thread);
@@ -197,7 +197,7 @@ public:
if(vdb_isect->setWorldRay(vdb_ray)) {
// TODO
-// isect->t = vdb_ray.t1(); // (kevin) is this correct?
+// isect->t = (float)vdb_ray.t1(); // (kevin) is this correct?
// isect->u = isect->v = 1.0f;
// isect->type = ;
// isect->shad = shader;
More information about the Bf-blender-cvs
mailing list