9#include <embree4/rtcore_geometry.h>
10#include <embree4/rtcore_ray.h>
11#include <embree4/rtcore_scene.h>
13#ifdef __KERNEL_ONEAPI__
30#ifdef __KERNEL_ONEAPI__
39#if RTC_VERSION < 40400
40# define RTCTraversable RTCScene
41# define rtcGetGeometryUserDataFromTraversable rtcGetGeometryUserDataFromScene
42# define rtcTraversableIntersect1 rtcIntersect1
43# define rtcTraversableOccluded1 rtcOccluded1
46#ifdef __KERNEL_ONEAPI__
47# define CYCLES_EMBREE_USED_FEATURES \
48 (kernel_handler.get_specialization_constant<oneapi_embree_features>())
50# define CYCLES_EMBREE_USED_FEATURES \
51 (RTCFeatureFlags)(RTC_FEATURE_FLAG_TRIANGLE | RTC_FEATURE_FLAG_INSTANCE | \
52 RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS | RTC_FEATURE_FLAG_POINT | \
53 RTC_FEATURE_FLAG_MOTION_BLUR | RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE | \
54 RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE)
57#define EMBREE_IS_HAIR(x) (x & 1)
92#ifdef __VOLUME_RECORD_ALL__
103 const uint visibility)
105 rtc_ray.org_x = ray.
P.
x;
106 rtc_ray.org_y = ray.
P.
y;
107 rtc_ray.org_z = ray.
P.
z;
108 rtc_ray.dir_x = ray.
D.
x;
109 rtc_ray.dir_y = ray.
D.
y;
110 rtc_ray.dir_z = ray.
D.
z;
111 rtc_ray.tnear = ray.
tmin;
112 rtc_ray.tfar = ray.
tmax;
113 rtc_ray.time = ray.
time;
114 rtc_ray.mask = visibility;
119 const uint visibility)
122 rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID;
123 rayhit.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
128 return (hit->instID[0] != RTC_INVALID_GEOMETRY_ID ? hit->instID[0] : hit->geomID) / 2;
134 const intptr_t prim_offset)
140 prim = hit->primID + prim_offset;
146 const bool is_hair = hit->geomID & 1;
158 const intptr_t prim_offset)
160 isect->
t = ray->tfar;
161 isect->
prim = hit->primID + prim_offset;
164 const bool is_hair = hit->geomID & 1;
167 isect->
type = segment.type;
168 isect->
prim = segment.prim;
184 intptr_t prim_offset;
185 if (hit->instID[0] != RTC_INVALID_GEOMETRY_ID) {
191 prim_offset = intptr_t(
202 const intptr_t prim_offset)
206 isect->
t = ray->tfar;
207 isect->
prim = hit->primID + prim_offset;
219 const RTCFilterFunctionNArguments *args)
224 RTCHit *hit = (RTCHit *)args->hit;
226#ifdef __KERNEL_ONEAPI__
231 const Ray *cray = ctx->
ray;
234 kg, hit, cray,
reinterpret_cast<intptr_t
>(args->geometryUserPtr)))
240#ifdef __SHADOW_LINKING__
254 const RTCFilterFunctionNArguments *args)
259 const RTCRay *ray = (RTCRay *)args->ray;
260 RTCHit *hit = (RTCHit *)args->hit;
262#ifdef __KERNEL_ONEAPI__
267 const Ray *cray = ctx->
ray;
271 kg, ray, hit, ¤t_isect,
reinterpret_cast<intptr_t
>(args->geometryUserPtr));
277#ifdef __SHADOW_LINKING__
307 kg, current_isect.
object, current_isect.
prim, current_isect.
type, current_isect.
u);
334 if (isect_index >= max_record_hits) {
337 if (current_isect.
t >= ctx->
max_t) {
343 float second_largest_t = 0.0f;
347 if (isect_t > max_t) {
348 second_largest_t = max_t;
349 max_recorded_hit =
i;
352 else if (isect_t > second_largest_t) {
353 second_largest_t = isect_t;
357 if (isect_index == max_record_hits && current_isect.
t >= max_t) {
364 isect_index = max_recorded_hit;
368 ctx->
max_t =
max(second_largest_t, current_isect.
t);
375 const RTCFilterFunctionNArguments *args)
380 const RTCRay *ray = (RTCRay *)args->ray;
381 RTCHit *hit = (RTCHit *)args->hit;
383#ifdef __KERNEL_ONEAPI__
388 const Ray *cray = ctx->
ray;
398 reinterpret_cast<intptr_t
>(args->geometryUserPtr));
402 kg, ray, hit, ¤t_isect,
reinterpret_cast<intptr_t
>(args->geometryUserPtr));
432 if (local_isect->
hits[
i].
t == ray->tfar) {
442 hit_idx = local_isect->
num_hits - 1;
458 if (local_isect->
num_hits && current_isect.
t > local_isect->
hits[0].
t) {
467 local_isect->
hits[hit_idx] = current_isect;
474 const RTCFilterFunctionNArguments *args)
479 const RTCRay *ray = (RTCRay *)args->ray;
480 RTCHit *hit = (RTCHit *)args->hit;
482#ifdef __KERNEL_ONEAPI__
487 const Ray *cray = ctx->
ray;
489#ifdef __VOLUME_RECORD_ALL__
491 if (ctx->
num_hits < ctx->max_hits) {
495 kg, ray, hit, ¤t_isect,
reinterpret_cast<intptr_t
>(args->geometryUserPtr));
503 *isect = current_isect;
509#ifndef __VOLUME_RECORD_ALL__
515#ifdef __VOLUME_RECORD_ALL__
522#ifdef __KERNEL_ONEAPI__
525kernel_embree_filter_intersection_func_static(
const RTCFilterFunctionNArguments *args)
527 RTCHit *hit = (RTCHit *)args->hit;
529 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
530 context->kernel_embree_filter_intersection_func_impl(args);
534kernel_embree_filter_occluded_shadow_all_func_static(
const RTCFilterFunctionNArguments *args)
536 RTCHit *hit = (RTCHit *)args->hit;
538 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
539 context->kernel_embree_filter_occluded_shadow_all_func_impl(args);
543kernel_embree_filter_occluded_local_func_static(
const RTCFilterFunctionNArguments *args)
545 RTCHit *hit = (RTCHit *)args->hit;
547 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
548 context->kernel_embree_filter_occluded_local_func_impl(args);
552kernel_embree_filter_occluded_volume_all_func_static(
const RTCFilterFunctionNArguments *args)
554 RTCHit *hit = (RTCHit *)args->hit;
556 ONEAPIKernelContext *
context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
557 context->kernel_embree_filter_occluded_volume_all_func_impl(args);
560# define kernel_embree_filter_intersection_func \
561 ONEAPIKernelContext::kernel_embree_filter_intersection_func_static
562# define kernel_embree_filter_occluded_shadow_all_func \
563 ONEAPIKernelContext::kernel_embree_filter_occluded_shadow_all_func_static
564# define kernel_embree_filter_occluded_local_func \
565 ONEAPIKernelContext::kernel_embree_filter_occluded_local_func_static
566# define kernel_embree_filter_occluded_volume_all_func \
567 ONEAPIKernelContext::kernel_embree_filter_occluded_volume_all_func_static
569# define kernel_embree_filter_intersection_func kernel_embree_filter_intersection_func_impl
570# define kernel_embree_filter_occluded_shadow_all_func \
571 kernel_embree_filter_occluded_shadow_all_func_impl
572# define kernel_embree_filter_occluded_local_func kernel_embree_filter_occluded_local_func_impl
573# define kernel_embree_filter_occluded_volume_all_func \
574 kernel_embree_filter_occluded_volume_all_func_impl
581 const uint visibility,
584 isect->t = ray->tmax;
586 rtcInitRayQueryContext(&ctx);
587#ifdef __KERNEL_ONEAPI__
601 RTCIntersectArguments args;
602 rtcInitIntersectArguments(&args);
607 if (ray_hit.hit.geomID == RTC_INVALID_GEOMETRY_ID ||
608 ray_hit.hit.primID == RTC_INVALID_GEOMETRY_ID)
621 const int local_object,
628 rtcInitRayQueryContext(&ctx);
629# ifdef __KERNEL_ONEAPI__
644 local_isect->num_hits = 0;
650 RTCOccludedArguments args;
651 rtcInitOccludedArguments(&args);
661# ifdef __OBJECT_MOTION__
662 bvh_instance_motion_push(kg, local_object, ray, &
P, &dir, &idir);
670 rtc_ray.dir_x = dir.
x;
671 rtc_ray.dir_y = dir.
y;
672 rtc_ray.dir_z = dir.
z;
673 rtc_ray.tnear = ray->tmin;
674 rtc_ray.tfar = ray->tmax;
687 return (local_isect && local_isect->num_hits > 0) || (rtc_ray.tfar < 0);
691#ifdef __SHADOW_RECORD_ALL__
695 const uint visibility,
701 rtcInitRayQueryContext(&ctx);
702# ifdef __KERNEL_ONEAPI__
716 ctx.
max_t = ray->tmax;
720 RTCOccludedArguments args;
721 rtcInitOccludedArguments(&args);
722 args.filter =
reinterpret_cast<RTCFilterFunctionN
>(
741 const uint visibility)
744 rtcInitRayQueryContext(&ctx);
745# ifdef __KERNEL_ONEAPI__
755# ifdef __VOLUME_RECORD_ALL__
762 RTCOccludedArguments args;
763 rtcInitOccludedArguments(&args);
764 args.filter =
reinterpret_cast<RTCFilterFunctionN
>(
ccl_device_forceinline int intersection_get_shader_flags(KernelGlobals kg, const int prim, const int type)
ccl_device_inline bool intersection_skip_shadow_link(KernelGlobals kg, const ccl_ray_data RaySelfPrimitives &self, const int isect_object)
ccl_device_inline bool intersection_skip_self_shadow(const ccl_ray_data RaySelfPrimitives &self, const int object, const int prim)
ccl_device_inline bool intersection_skip_self(const ccl_ray_data RaySelfPrimitives &self, const int object, const int prim)
#define CURVE_SHADOW_TRANSPARENCY_CUTOFF
ccl_device_inline float intersection_curve_shadow_transparency(KernelGlobals kg, const int object, const int prim, const int type, const float u)
ccl_device_forceinline bool intersection_skip_shadow_already_recoded(KernelGlobals kg, IntegratorShadowState state, const int object, const int prim, const int num_hits)
ccl_device_inline bool intersection_skip_self_local(const ccl_ray_data RaySelfPrimitives &self, const int prim)
#define kernel_assert(cond)
#define ccl_device_forceinline
#define kernel_data_fetch(name, index)
#define ccl_always_inline
#define INTEGRATOR_SHADOW_ISECT_SIZE
#define __VOLUME_RECORD_ALL__
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_inline
#define CCL_NAMESPACE_END
VecBase< float, D > normalize(VecOp< float, D >) RET
#define assert(assertion)
#define ccl_device_intersect
#define rtcTraversableOccluded1
ccl_device_inline void kernel_embree_convert_hit(KernelGlobals kg, const RTCRay *ray, const RTCHit *hit, Intersection *isect, const intptr_t prim_offset)
ccl_device_forceinline void kernel_embree_filter_occluded_local_func_impl(const RTCFilterFunctionNArguments *args)
#define CYCLES_EMBREE_USED_FEATURES
ccl_device_inline void kernel_embree_convert_sss_hit(KernelGlobals kg, const RTCRay *ray, const RTCHit *hit, Intersection *isect, const int object, const intptr_t prim_offset)
ccl_device_forceinline void kernel_embree_filter_occluded_volume_all_func_impl(const RTCFilterFunctionNArguments *args)
ccl_device_forceinline void kernel_embree_filter_occluded_shadow_all_func_impl(const RTCFilterFunctionNArguments *args)
ccl_device_intersect bool kernel_embree_intersect(KernelGlobals kg, const ccl_private Ray *ray, const uint visibility, ccl_private Intersection *isect)
ccl_device_inline void kernel_embree_setup_rayhit(const Ray &ray, RTCRayHit &rayhit, const uint visibility)
#define kernel_embree_filter_occluded_volume_all_func
#define kernel_embree_filter_intersection_func
#define rtcGetGeometryUserDataFromTraversable
ccl_device_inline int kernel_embree_get_hit_object(const RTCHit *hit)
ccl_device_inline bool kernel_embree_is_self_intersection(const KernelGlobals kg, const RTCHit *hit, const Ray *ray, const intptr_t prim_offset)
#define EMBREE_IS_HAIR(x)
#define rtcTraversableIntersect1
#define kernel_embree_filter_occluded_local_func
ccl_device_forceinline void kernel_embree_filter_intersection_func_impl(const RTCFilterFunctionNArguments *args)
#define kernel_embree_filter_occluded_shadow_all_func
ccl_device_inline void kernel_embree_setup_ray(const Ray &ray, RTCRay &rtc_ray, const uint visibility)
ccl_device_inline void bvh_instance_push(KernelGlobals kg, const int object, const ccl_private Ray *ray, ccl_private float3 *P, ccl_private float3 *dir, ccl_private float3 *idir)
@ SD_HAS_TRANSPARENT_SHADOW
@ PATH_RAY_ALL_VISIBILITY
@ SD_OBJECT_TRANSFORM_APPLIED
CCL_NAMESPACE_BEGIN ccl_device uint lcg_step_uint(T rng)
int context(const bContext *C, const char *member, bContextDataResult *result)
IntegratorShadowStateCPU * IntegratorShadowState
#define INTEGRATOR_STATE_ARRAY(state, nested_struct, array_index, member)
ccl_device_forceinline void integrator_state_write_shadow_isect(IntegratorShadowState state, const ccl_private Intersection *ccl_restrict isect, const int index)
LocalIntersection * local_isect
numhit_t num_recorded_hits
IntegratorShadowState isect_s
struct Intersection hits[LOCAL_MAX_HITS]
float3 Ng[LOCAL_MAX_HITS]