Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/bvh/bvh.h
| Show All 23 Lines | |||||
| * | * | ||||
| * Originally based on "Understanding the Efficiency of Ray Traversal on GPUs", | * Originally based on "Understanding the Efficiency of Ray Traversal on GPUs", | ||||
| * the code has been extended and modified to support more primitives and work | * the code has been extended and modified to support more primitives and work | ||||
| * with CPU/CUDA/OpenCL. */ | * with CPU/CUDA/OpenCL. */ | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| #include "bvh_types.h" | #include "bvh_types.h" | ||||
| #include "bvh_special.h" | |||||
| /* Common QBVH functions. */ | /* Common QBVH functions. */ | ||||
| #ifdef __QBVH__ | #ifdef __QBVH__ | ||||
| # include "qbvh_nodes.h" | # include "qbvh_nodes.h" | ||||
| #endif | #endif | ||||
| /* Regular BVH traversal */ | /* Regular BVH traversal */ | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_MOTION|BVH_HAIR | # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_MOTION|BVH_HAIR | ||||
| # include "bvh_volume.h" | # include "bvh_volume.h" | ||||
| # endif | # endif | ||||
| #endif /* __VOLUME__ */ | #endif /* __VOLUME__ */ | ||||
| /* Record all intersections - Shadow BVH traversal */ | /* Record all intersections - Shadow BVH traversal */ | ||||
| #if defined(__SHADOW_RECORD_ALL__) | #if defined(__SHADOW_RECORD_ALL__) | ||||
| # define BVH_SKIP_PRIMITIVE_INTERSECTION false | |||||
| # define BVH_OBJECT_PUSH_CONDITION true | |||||
| # define BVH_EARLY_RAY_TERMINATION_CONDITION \ | |||||
| bvh_intersect_shadow_early_termination(kg, \ | |||||
| isect_array->prim, \ | |||||
| *num_hits, \ | |||||
| max_hits) | |||||
| # define BVH_FUNCTION_NAME bvh_intersect_shadow_all | # define BVH_FUNCTION_NAME bvh_intersect_shadow_all | ||||
| # define BVH_FUNCTION_FEATURES 0 | # define BVH_FUNCTION_FEATURES 0 | ||||
| # include "bvh_shadow_all.h" | # include "bvh_traversal_all.h" | ||||
| # if defined(__INSTANCING__) | # if defined(__INSTANCING__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_instancing | # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_instancing | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING | # define BVH_FUNCTION_FEATURES BVH_INSTANCING | ||||
| # include "bvh_shadow_all.h" | # include "bvh_traversal_all.h" | ||||
| # endif | # endif | ||||
| # if defined(__HAIR__) | # if defined(__HAIR__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair | # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR | # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR | ||||
| # include "bvh_shadow_all.h" | # include "bvh_traversal_all.h" | ||||
| # endif | # endif | ||||
| # if defined(__OBJECT_MOTION__) | # if defined(__OBJECT_MOTION__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_motion | # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_motion | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_MOTION | # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_MOTION | ||||
| # include "bvh_shadow_all.h" | # include "bvh_traversal_all.h" | ||||
| # endif | # endif | ||||
| # if defined(__HAIR__) && defined(__OBJECT_MOTION__) | # if defined(__HAIR__) && defined(__OBJECT_MOTION__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair_motion | # define BVH_FUNCTION_NAME bvh_intersect_shadow_all_hair_motion | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR|BVH_MOTION | # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR|BVH_MOTION | ||||
| # include "bvh_shadow_all.h" | # include "bvh_traversal_all.h" | ||||
| # endif | # endif | ||||
| # undef BVH_SKIP_PRIMITIVE_INTERSECTION | |||||
| # undef BVH_OBJECT_PUSH_CONDITION | |||||
| # undef BVH_EARLY_RAY_TERMINATION_CONDITION | |||||
| #endif /* __SHADOW_RECORD_ALL__ */ | #endif /* __SHADOW_RECORD_ALL__ */ | ||||
| /* Record all intersections - Volume BVH traversal */ | /* Record all intersections - Volume BVH traversal */ | ||||
| #if defined(__VOLUME_RECORD_ALL__) | #if defined(__VOLUME_RECORD_ALL__) | ||||
| # define BVH_SKIP_PRIMITIVE_INTERSECTION bvh_intersect_volume_skip_primitive(kg, prim_addr, object) | |||||
| # define BVH_EARLY_RAY_TERMINATION_CONDITION false | |||||
| # define BVH_OBJECT_PUSH_CONDITION (kernel_tex_fetch(__object_flag, object) & SD_OBJECT_HAS_VOLUME) | |||||
| # define BVH_FUNCTION_NAME bvh_intersect_volume_all | # define BVH_FUNCTION_NAME bvh_intersect_volume_all | ||||
| # define BVH_FUNCTION_FEATURES BVH_HAIR | # define BVH_FUNCTION_FEATURES BVH_HAIR|BVH_RESCALE_ON_OVERFLOW | ||||
| # include "bvh_volume_all.h" | # include "bvh_traversal_all.h" | ||||
| # if defined(__INSTANCING__) | # if defined(__INSTANCING__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_volume_all_instancing | # define BVH_FUNCTION_NAME bvh_intersect_volume_all_instancing | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR | # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR|BVH_RESCALE_ON_OVERFLOW | ||||
| # include "bvh_volume_all.h" | # include "bvh_traversal_all.h" | ||||
| # endif | # endif | ||||
| # if defined(__OBJECT_MOTION__) | # if defined(__OBJECT_MOTION__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_volume_all_motion | # define BVH_FUNCTION_NAME bvh_intersect_volume_all_motion | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_MOTION|BVH_HAIR | # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_MOTION|BVH_HAIR|BVH_RESCALE_ON_OVERFLOW | ||||
| # include "bvh_volume_all.h" | # include "bvh_traversal_all.h" | ||||
| # endif | # endif | ||||
| # undef BVH_SKIP_PRIMITIVE_INTERSECTION | |||||
| # undef BVH_OBJECT_PUSH_CONDITION | |||||
| # undef BVH_EARLY_RAY_TERMINATION_CONDITION | |||||
| #endif /* __VOLUME_RECORD_ALL__ */ | #endif /* __VOLUME_RECORD_ALL__ */ | ||||
| #undef BVH_FEATURE | #undef BVH_FEATURE | ||||
| #undef BVH_NAME_JOIN | #undef BVH_NAME_JOIN | ||||
| #undef BVH_NAME_EVAL | #undef BVH_NAME_EVAL | ||||
| #undef BVH_FUNCTION_FULL_NAME | #undef BVH_FUNCTION_FULL_NAME | ||||
| ccl_device_intersect bool scene_intersect(KernelGlobals *kg, | ccl_device_intersect bool scene_intersect(KernelGlobals *kg, | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | return bvh_intersect_subsurface(kg, | ||||
| ss_isect, | ss_isect, | ||||
| subsurface_object, | subsurface_object, | ||||
| lcg_state, | lcg_state, | ||||
| max_hits); | max_hits); | ||||
| } | } | ||||
| #endif | #endif | ||||
| #ifdef __SHADOW_RECORD_ALL__ | #ifdef __SHADOW_RECORD_ALL__ | ||||
| ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals *kg, const Ray *ray, Intersection *isect, uint max_hits, uint *num_hits) | ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals *kg, | ||||
| const Ray *ray, | |||||
| Intersection *isect, | |||||
| const uint max_hits, | |||||
| uint *num_hits) | |||||
| { | { | ||||
| # ifdef __OBJECT_MOTION__ | # ifdef __OBJECT_MOTION__ | ||||
| if(kernel_data.bvh.have_motion) { | if(kernel_data.bvh.have_motion) { | ||||
| # ifdef __HAIR__ | # ifdef __HAIR__ | ||||
| if(kernel_data.bvh.have_curves) | if(kernel_data.bvh.have_curves) { | ||||
| return bvh_intersect_shadow_all_hair_motion(kg, ray, isect, max_hits, num_hits); | return bvh_intersect_shadow_all_hair_motion(kg, | ||||
| ray, | |||||
| isect, | |||||
| max_hits, | |||||
| PATH_RAY_SHADOW, | |||||
| num_hits); | |||||
| } | |||||
| # endif /* __HAIR__ */ | # endif /* __HAIR__ */ | ||||
| return bvh_intersect_shadow_all_motion(kg, ray, isect, max_hits, num_hits); | return bvh_intersect_shadow_all_motion(kg, | ||||
| ray, | |||||
| isect, | |||||
| max_hits, | |||||
| PATH_RAY_SHADOW, | |||||
| num_hits); | |||||
| } | } | ||||
| # endif /* __OBJECT_MOTION__ */ | # endif /* __OBJECT_MOTION__ */ | ||||
| # ifdef __HAIR__ | # ifdef __HAIR__ | ||||
| if(kernel_data.bvh.have_curves) | if(kernel_data.bvh.have_curves) { | ||||
| return bvh_intersect_shadow_all_hair(kg, ray, isect, max_hits, num_hits); | return bvh_intersect_shadow_all_hair(kg, | ||||
| ray, | |||||
| isect, | |||||
| max_hits, | |||||
| PATH_RAY_SHADOW, | |||||
| num_hits); | |||||
| } | |||||
| # endif /* __HAIR__ */ | # endif /* __HAIR__ */ | ||||
| # ifdef __INSTANCING__ | # ifdef __INSTANCING__ | ||||
| if(kernel_data.bvh.have_instancing) | if(kernel_data.bvh.have_instancing) { | ||||
| return bvh_intersect_shadow_all_instancing(kg, ray, isect, max_hits, num_hits); | return bvh_intersect_shadow_all_instancing(kg, | ||||
| ray, | |||||
| isect, | |||||
| max_hits, | |||||
| PATH_RAY_SHADOW, | |||||
| num_hits); | |||||
| } | |||||
| # endif /* __INSTANCING__ */ | # endif /* __INSTANCING__ */ | ||||
| return bvh_intersect_shadow_all(kg, | |||||
| return bvh_intersect_shadow_all(kg, ray, isect, max_hits, num_hits); | ray, | ||||
| isect, | |||||
| max_hits, | |||||
| PATH_RAY_SHADOW, | |||||
| num_hits); | |||||
| } | } | ||||
| #endif /* __SHADOW_RECORD_ALL__ */ | #endif /* __SHADOW_RECORD_ALL__ */ | ||||
| #ifdef __VOLUME__ | #ifdef __VOLUME__ | ||||
| ccl_device_intersect bool scene_intersect_volume(KernelGlobals *kg, | ccl_device_intersect bool scene_intersect_volume(KernelGlobals *kg, | ||||
| const Ray *ray, | const Ray *ray, | ||||
| Intersection *isect, | Intersection *isect, | ||||
| const uint visibility) | const uint visibility) | ||||
| Show All 21 Lines | |||||
| #ifdef __VOLUME_RECORD_ALL__ | #ifdef __VOLUME_RECORD_ALL__ | ||||
| ccl_device_intersect uint scene_intersect_volume_all(KernelGlobals *kg, | ccl_device_intersect uint scene_intersect_volume_all(KernelGlobals *kg, | ||||
| const Ray *ray, | const Ray *ray, | ||||
| Intersection *isect, | Intersection *isect, | ||||
| const uint max_hits, | const uint max_hits, | ||||
| const uint visibility) | const uint visibility) | ||||
| { | { | ||||
| uint num_hits; | |||||
| # ifdef __OBJECT_MOTION__ | # ifdef __OBJECT_MOTION__ | ||||
| if(kernel_data.bvh.have_motion) { | if(kernel_data.bvh.have_motion) { | ||||
| return bvh_intersect_volume_all_motion(kg, ray, isect, max_hits, visibility); | bvh_intersect_volume_all_motion(kg, | ||||
| ray, | |||||
| isect, | |||||
| max_hits, | |||||
| visibility, | |||||
| &num_hits); | |||||
| return num_hits; | |||||
| } | } | ||||
| # endif /* __OBJECT_MOTION__ */ | # endif /* __OBJECT_MOTION__ */ | ||||
| # ifdef __INSTANCING__ | # ifdef __INSTANCING__ | ||||
| if(kernel_data.bvh.have_instancing) | if(kernel_data.bvh.have_instancing) { | ||||
| return bvh_intersect_volume_all_instancing(kg, ray, isect, max_hits, visibility); | bvh_intersect_volume_all_instancing(kg, | ||||
| ray, | |||||
| isect, | |||||
| max_hits, | |||||
| visibility, | |||||
| &num_hits); | |||||
| return num_hits; | |||||
| } | |||||
| # endif /* __INSTANCING__ */ | # endif /* __INSTANCING__ */ | ||||
| return bvh_intersect_volume_all(kg, ray, isect, max_hits, visibility); | bvh_intersect_volume_all(kg, ray, isect, max_hits, visibility, &num_hits); | ||||
| return num_hits; | |||||
| } | } | ||||
| #endif /* __VOLUME_RECORD_ALL__ */ | #endif /* __VOLUME_RECORD_ALL__ */ | ||||
| /* Ray offset to avoid self intersection. | /* Ray offset to avoid self intersection. | ||||
| * | * | ||||
| * This function should be used to compute a modified ray start position for | * This function should be used to compute a modified ray start position for | ||||
| * rays leaving from a surface. */ | * rays leaving from a surface. */ | ||||
| ▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines | |||||