Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/bvh/bvh.h
| Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | do { \ | ||||
| ++isect->num_traversed_instances; \ | ++isect->num_traversed_instances; \ | ||||
| } while(0) | } while(0) | ||||
| #else /* __KERNEL_DEBUG__ */ | #else /* __KERNEL_DEBUG__ */ | ||||
| # define BVH_DEBUG_INIT() | # define BVH_DEBUG_INIT() | ||||
| # define BVH_DEBUG_NEXT_STEP() | # define BVH_DEBUG_NEXT_STEP() | ||||
| # define BVH_DEBUG_NEXT_INSTANCE() | # define BVH_DEBUG_NEXT_INSTANCE() | ||||
| #endif /* __KERNEL_DEBUG__ */ | #endif /* __KERNEL_DEBUG__ */ | ||||
| /* Common BVH functions. */ | |||||
| #include "bvh_nodes.h" | |||||
| /* Common QBVH functions. */ | /* Common QBVH functions. */ | ||||
| #ifdef __QBVH__ | #ifdef __QBVH__ | ||||
| # include "qbvh_nodes.h" | # include "qbvh_nodes.h" | ||||
| #endif | #endif | ||||
| /* Regular BVH traversal */ | #ifdef __BVH_RECORD_CALLBACK__ | ||||
| /* Callback which is used by callback-based BVH traversal. | |||||
| * | |||||
| * It is called on every hair/triangle intersection from | |||||
| * BVH traversal. | |||||
| * | |||||
| * If callback returns false traversal aborts. | |||||
| */ | |||||
| typedef bool (*BVHIntersectionCallback) (KernelGlobals *kg, | |||||
| const Ray *ray, | |||||
| Intersection *isect, | |||||
| int object, | |||||
| void *user_data); | |||||
| #endif | |||||
| #include "bvh_nodes.h" | /* Regular BVH traversal */ | ||||
| #define BVH_FUNCTION_NAME bvh_intersect | #define BVH_FUNCTION_NAME bvh_intersect | ||||
| #define BVH_FUNCTION_FEATURES 0 | #define BVH_FUNCTION_FEATURES 0 | ||||
| #include "bvh_traversal.h" | #include "bvh_traversal.h" | ||||
| #if defined(__INSTANCING__) | #if defined(__INSTANCING__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_instancing | # define BVH_FUNCTION_NAME bvh_intersect_instancing | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING | # define BVH_FUNCTION_FEATURES BVH_INSTANCING | ||||
| Show All 13 Lines | |||||
| #endif | #endif | ||||
| #if defined(__HAIR__) && defined(__OBJECT_MOTION__) | #if defined(__HAIR__) && defined(__OBJECT_MOTION__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_hair_motion | # define BVH_FUNCTION_NAME bvh_intersect_hair_motion | ||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR|BVH_HAIR_MINIMUM_WIDTH|BVH_MOTION | # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR|BVH_HAIR_MINIMUM_WIDTH|BVH_MOTION | ||||
| # include "bvh_traversal.h" | # include "bvh_traversal.h" | ||||
| #endif | #endif | ||||
| /* Regular BVH traversal with callback function */ | |||||
| #ifdef __BVH_RECORD_CALLBACK__ | |||||
| # define BVH_FUNCTION_NAME bvh_intersect_callback | |||||
| # define BVH_FUNCTION_FEATURES 0 | |||||
| # include "bvh_traversal_callback.h" | |||||
| # if defined(__INSTANCING__) | |||||
| # define BVH_FUNCTION_NAME bvh_intersect_callback_instancing | |||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING | |||||
| # include "bvh_traversal_callback.h" | |||||
| # endif | |||||
| # if defined(__HAIR__) | |||||
| # define BVH_FUNCTION_NAME bvh_intersect_callback_hair | |||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR|BVH_HAIR_MINIMUM_WIDTH | |||||
| # include "bvh_traversal_callback.h" | |||||
| # endif | |||||
| # if defined(__OBJECT_MOTION__) | |||||
| # define BVH_FUNCTION_NAME bvh_intersect_callback_motion | |||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_MOTION | |||||
| # include "bvh_traversal_callback.h" | |||||
| # endif | |||||
| # if defined(__HAIR__) && defined(__OBJECT_MOTION__) | |||||
| # define BVH_FUNCTION_NAME bvh_intersect_callback_hair_motion | |||||
| # define BVH_FUNCTION_FEATURES BVH_INSTANCING|BVH_HAIR|BVH_HAIR_MINIMUM_WIDTH|BVH_MOTION | |||||
| # include "bvh_traversal_callback.h" | |||||
| # endif | |||||
| #endif /* __BVH_RECORD_CALLBACK__ */ | |||||
| /* Subsurface scattering BVH traversal */ | /* Subsurface scattering BVH traversal */ | ||||
| #if defined(__SUBSURFACE__) | #if defined(__SUBSURFACE__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_subsurface | # define BVH_FUNCTION_NAME bvh_intersect_subsurface | ||||
| # define BVH_FUNCTION_FEATURES BVH_HAIR | # define BVH_FUNCTION_FEATURES BVH_HAIR | ||||
| # include "bvh_subsurface.h" | # include "bvh_subsurface.h" | ||||
| #endif | #endif | ||||
| Show All 20 Lines | |||||
| #if defined(__VOLUME__) && defined(__OBJECT_MOTION__) | #if defined(__VOLUME__) && defined(__OBJECT_MOTION__) | ||||
| # define BVH_FUNCTION_NAME bvh_intersect_volume_motion | # define BVH_FUNCTION_NAME bvh_intersect_volume_motion | ||||
| # 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 | ||||
| /* Record all intersections - Shadow BVH traversal */ | /* Record all intersections - Shadow BVH traversal */ | ||||
| #if defined(__SHADOW_RECORD_ALL__) | #if defined(__SHADOW_RECORD_ALL__) || defined(__SHADOW_RECORD_ALL_STATIC__) | ||||
| # 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_shadow_all.h" | ||||
| #endif | #endif | ||||
| #if defined(__SHADOW_RECORD_ALL__) && defined(__INSTANCING__) | #if (defined(__SHADOW_RECORD_ALL__) || defined(__SHADOW_RECORD_ALL_STATIC__)) && 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_shadow_all.h" | ||||
| #endif | #endif | ||||
| #if defined(__SHADOW_RECORD_ALL__) && defined(__HAIR__) | #if (defined(__SHADOW_RECORD_ALL__) || defined(__SHADOW_RECORD_ALL_STATIC__)) && 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_shadow_all.h" | ||||
| #endif | #endif | ||||
| #if defined(__SHADOW_RECORD_ALL__) && defined(__OBJECT_MOTION__) | #if (defined(__SHADOW_RECORD_ALL__) || defined(__SHADOW_RECORD_ALL_STATIC__)) && 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_shadow_all.h" | ||||
| #endif | #endif | ||||
| #if defined(__SHADOW_RECORD_ALL__) && defined(__HAIR__) && defined(__OBJECT_MOTION__) | #if (defined(__SHADOW_RECORD_ALL__) || defined(__SHADOW_RECORD_ALL_STATIC__)) && 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_shadow_all.h" | ||||
| #endif | #endif | ||||
| /* Record all intersections - Volume BVH traversal */ | /* Record all intersections - Volume BVH traversal */ | ||||
| #if defined(__VOLUME_RECORD_ALL__) | #if defined(__VOLUME_RECORD_ALL__) | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | # ifdef __INSTANCING__ | ||||
| return bvh_intersect_instancing(kg, ray, isect, visibility); | return bvh_intersect_instancing(kg, ray, isect, visibility); | ||||
| # else | # else | ||||
| return bvh_intersect(kg, ray, isect, visibility); | return bvh_intersect(kg, ray, isect, visibility); | ||||
| # endif /* __INSTANCING__ */ | # endif /* __INSTANCING__ */ | ||||
| #endif /* __KERNEL_CPU__ */ | #endif /* __KERNEL_CPU__ */ | ||||
| } | } | ||||
| #ifdef __BVH_RECORD_CALLBACK__ | |||||
| ccl_device_intersect bool scene_intersect_callback( | |||||
| KernelGlobals *kg, | |||||
| const Ray *ray, | |||||
| const uint visibility, | |||||
| Intersection *isect, | |||||
| uint *lcg_state, | |||||
| float difl, | |||||
| float extmax, | |||||
| BVHIntersectionCallback callback, | |||||
| void *user_data | |||||
| ) | |||||
| { | |||||
| # ifdef __OBJECT_MOTION__ | |||||
| if(kernel_data.bvh.have_motion) { | |||||
| # ifdef __HAIR__ | |||||
| if(kernel_data.bvh.have_curves) { | |||||
| return bvh_intersect_callback_hair_motion(kg, | |||||
| ray, | |||||
| isect, | |||||
| visibility, | |||||
| lcg_state, | |||||
| difl, | |||||
| extmax, | |||||
| callback, | |||||
| user_data); | |||||
| } | |||||
| # endif /* __HAIR__ */ | |||||
| return bvh_intersect_callback_motion(kg, | |||||
| ray, | |||||
| isect, | |||||
| visibility, | |||||
| callback, | |||||
| user_data); | |||||
| } | |||||
| # endif /* __OBJECT_MOTION__ */ | |||||
| # ifdef __HAIR__ | |||||
| if(kernel_data.bvh.have_curves) { | |||||
| return bvh_intersect_callback_hair(kg, | |||||
| ray, | |||||
| isect, | |||||
| visibility, | |||||
| lcg_state, | |||||
| difl, | |||||
| extmax, | |||||
| callback, | |||||
| user_data); | |||||
| } | |||||
| # endif /* __HAIR__ */ | |||||
| # ifdef __KERNEL_CPU__ | |||||
| # ifdef __INSTANCING__ | |||||
| if(kernel_data.bvh.have_instancing) { | |||||
| return bvh_intersect_callback_instancing(kg, | |||||
| ray, | |||||
| isect, | |||||
| visibility, | |||||
| callback, | |||||
| user_data); | |||||
| } | |||||
| # endif /* __INSTANCING__ */ | |||||
| return bvh_intersect_callback(kg, | |||||
| ray, | |||||
| isect, | |||||
| visibility, | |||||
| callback, | |||||
| user_data); | |||||
| # else /* __KERNEL_CPU__ */ | |||||
| # ifdef __INSTANCING__ | |||||
| return bvh_intersect_callback_instancing(kg, | |||||
| ray, | |||||
| isect, | |||||
| visibility, | |||||
| callback, | |||||
| user_data); | |||||
| # else | |||||
| return bvh_intersect_callback(kg, | |||||
| ray, | |||||
| isect, | |||||
| visibility, | |||||
| callback, | |||||
| user_data); | |||||
| # endif /* __INSTANCING__ */ | |||||
| # endif /* __KERNEL_CPU__ */ | |||||
| } | |||||
| #endif /* __BVH_RECORD_CALLBACK__ */ | |||||
| #ifdef __SUBSURFACE__ | #ifdef __SUBSURFACE__ | ||||
| ccl_device_intersect void scene_intersect_subsurface(KernelGlobals *kg, | ccl_device_intersect void scene_intersect_subsurface(KernelGlobals *kg, | ||||
| const Ray *ray, | const Ray *ray, | ||||
| SubsurfaceIntersection *ss_isect, | SubsurfaceIntersection *ss_isect, | ||||
| int subsurface_object, | int subsurface_object, | ||||
| uint *lcg_state, | uint *lcg_state, | ||||
| int max_hits) | int max_hits) | ||||
| { | { | ||||
| Show All 11 Lines | return bvh_intersect_subsurface(kg, | ||||
| ray, | ray, | ||||
| ss_isect, | ss_isect, | ||||
| subsurface_object, | subsurface_object, | ||||
| lcg_state, | lcg_state, | ||||
| max_hits); | max_hits); | ||||
| } | } | ||||
| #endif | #endif | ||||
| #ifdef __SHADOW_RECORD_ALL__ | #if defined(__SHADOW_RECORD_ALL__) || defined(__SHADOW_RECORD_ALL_STATIC__) | ||||
| 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, 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, num_hits); | ||||
| # endif /* __HAIR__ */ | # endif /* __HAIR__ */ | ||||
| Show All 9 Lines | |||||
| # 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, num_hits); | ||||
| # endif /* __INSTANCING__ */ | # endif /* __INSTANCING__ */ | ||||
| return bvh_intersect_shadow_all(kg, ray, isect, max_hits, num_hits); | return bvh_intersect_shadow_all(kg, ray, isect, max_hits, num_hits); | ||||
| } | } | ||||
| #endif /* __SHADOW_RECORD_ALL__ */ | #endif /* __SHADOW_RECORD_ALL__ || __SHADOW_RECORD_ALL_STATIC__ */ | ||||
| #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) | ||||
| { | { | ||||
| # ifdef __OBJECT_MOTION__ | # ifdef __OBJECT_MOTION__ | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | #ifdef __INTERSECTION_REFINE__ | ||||
| return res; | return res; | ||||
| #else | #else | ||||
| const float epsilon_f = 1e-4f; | const float epsilon_f = 1e-4f; | ||||
| return P + epsilon_f*Ng; | return P + epsilon_f*Ng; | ||||
| #endif | #endif | ||||
| } | } | ||||
| #if defined(__SHADOW_RECORD_ALL__) || defined (__VOLUME_RECORD_ALL__) | #if defined(__SHADOW_RECORD_ALL__) || defined (__VOLUME_RECORD_ALL__) || defined(__SHADOW_RECORD_ALL_STATIC__) | ||||
| /* ToDo: Move to another file? */ | /* ToDo: Move to another file? */ | ||||
| ccl_device int intersections_compare(const void *a, const void *b) | ccl_device int intersections_compare(const void *a, const void *b) | ||||
| { | { | ||||
| const Intersection *isect_a = (const Intersection*)a; | const Intersection *isect_a = (const Intersection*)a; | ||||
| const Intersection *isect_b = (const Intersection*)b; | const Intersection *isect_b = (const Intersection*)b; | ||||
| if(isect_a->t < isect_b->t) | if(isect_a->t < isect_b->t) | ||||
| return -1; | return -1; | ||||
| Show All 9 Lines | |||||