9#if EMBREE_MAJOR_VERSION >= 4
10# include <embree4/rtcore_ray.h>
11# include <embree4/rtcore_scene.h>
13# include <embree3/rtcore_ray.h>
14# include <embree3/rtcore_scene.h>
17#ifdef __KERNEL_ONEAPI__
36#ifdef __KERNEL_ONEAPI__
42#ifdef __KERNEL_ONEAPI__
43# define CYCLES_EMBREE_USED_FEATURES \
44 (kernel_handler.get_specialization_constant<oneapi_embree_features>())
46# define CYCLES_EMBREE_USED_FEATURES \
47 (RTCFeatureFlags)(RTC_FEATURE_FLAG_TRIANGLE | RTC_FEATURE_FLAG_INSTANCE | \
48 RTC_FEATURE_FLAG_FILTER_FUNCTION_IN_ARGUMENTS | RTC_FEATURE_FLAG_POINT | \
49 RTC_FEATURE_FLAG_MOTION_BLUR | RTC_FEATURE_FLAG_ROUND_CATMULL_ROM_CURVE | \
50 RTC_FEATURE_FLAG_FLAT_CATMULL_ROM_CURVE)
53#define EMBREE_IS_HAIR(x) (x & 1)
55#if EMBREE_MAJOR_VERSION < 4
56# define rtcGetGeometryUserDataFromScene(scene, id) \
57 (rtcGetGeometryUserData(rtcGetGeometry(scene, id)))
63#if EMBREE_MAJOR_VERSION >= 4
64 :
public RTCRayQueryContext
73#if EMBREE_MAJOR_VERSION >= 4
74 :
public RTCRayQueryContext
77#if EMBREE_MAJOR_VERSION >= 4
91#if EMBREE_MAJOR_VERSION >= 4
92 :
public RTCRayQueryContext
95#if EMBREE_MAJOR_VERSION >= 4
107#if EMBREE_MAJOR_VERSION >= 4
108 :
public RTCRayQueryContext
111#if EMBREE_MAJOR_VERSION >= 4
114# ifdef __VOLUME_RECORD_ALL__
122#if EMBREE_MAJOR_VERSION < 4
160 const uint visibility)
162 rtc_ray.org_x = ray.P.x;
163 rtc_ray.org_y = ray.P.y;
164 rtc_ray.org_z = ray.P.z;
165 rtc_ray.dir_x = ray.D.x;
166 rtc_ray.dir_y = ray.D.y;
167 rtc_ray.dir_z = ray.D.z;
168 rtc_ray.tnear = ray.tmin;
169 rtc_ray.tfar = ray.tmax;
170 rtc_ray.time = ray.time;
171 rtc_ray.mask = visibility;
176 const uint visibility)
179 rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID;
180 rayhit.hit.instID[0] = RTC_INVALID_GEOMETRY_ID;
185 return (hit->instID[0] != RTC_INVALID_GEOMETRY_ID ? hit->instID[0] : hit->geomID) / 2;
196 if ((ray->self.object ==
object) || (ray->self.light_object ==
object)) {
197 prim = hit->primID + prim_offset;
203 const bool is_hair = hit->geomID & 1;
217 isect->
t = ray->tfar;
218 isect->
prim = hit->primID + prim_offset;
221 const bool is_hair = hit->geomID & 1;
224 isect->
type = segment.type;
225 isect->
prim = segment.prim;
242 if (hit->instID[0] != RTC_INVALID_GEOMETRY_ID) {
262 isect->
t = ray->tfar;
263 isect->
prim = hit->primID + prim_offset;
275 const RTCFilterFunctionNArguments *args)
278 assert(args->N == 1);
280 RTCHit *hit = (RTCHit *)args->hit;
281#if EMBREE_MAJOR_VERSION >= 4
286#ifdef __KERNEL_ONEAPI__
291 const Ray *cray = ctx->
ray;
294 kg, hit, cray,
reinterpret_cast<intptr_t>(args->geometryUserPtr)))
300#ifdef __SHADOW_LINKING__
314 const RTCFilterFunctionNArguments *args)
317 assert(args->N == 1);
319 const RTCRay *ray = (RTCRay *)args->ray;
320 RTCHit *hit = (RTCHit *)args->hit;
321#if EMBREE_MAJOR_VERSION >= 4
326#ifdef __KERNEL_ONEAPI__
331 const Ray *cray = ctx->ray;
335 kg, ray, hit, ¤t_isect,
reinterpret_cast<intptr_t>(args->geometryUserPtr));
341#ifdef __SHADOW_LINKING__
360 kg, current_isect.
object, current_isect.
prim, current_isect.
type, current_isect.
u);
387 if (isect_index >= max_record_hits) {
390 if (current_isect.
t >= ctx->
max_t) {
396 float second_largest_t = 0.0f;
400 if (isect_t > max_t) {
401 second_largest_t = max_t;
402 max_recorded_hit = i;
405 else if (isect_t > second_largest_t) {
406 second_largest_t = isect_t;
410 if (isect_index == max_record_hits && current_isect.
t >= max_t) {
417 isect_index = max_recorded_hit;
421 ctx->
max_t =
max(second_largest_t, current_isect.
t);
428 const RTCFilterFunctionNArguments *args)
431 assert(args->N == 1);
433 const RTCRay *ray = (RTCRay *)args->ray;
434 RTCHit *hit = (RTCHit *)args->hit;
435#if EMBREE_MAJOR_VERSION >= 4
440#ifdef __KERNEL_ONEAPI__
445 const Ray *cray = ctx->ray;
455 reinterpret_cast<intptr_t>(args->geometryUserPtr));
459 kg, ray, hit, ¤t_isect,
reinterpret_cast<intptr_t>(args->geometryUserPtr));
472 if (ctx->max_hits == 0) {
488 for (
int i =
min((
int)ctx->max_hits, local_isect->
num_hits) - 1; i >= 0; --i) {
489 if (local_isect->
hits[i].
t == ray->tfar) {
498 if (local_isect->
num_hits <= ctx->max_hits) {
499 hit_idx = local_isect->
num_hits - 1;
506 if (hit_idx >= ctx->max_hits) {
515 if (local_isect->
num_hits && current_isect.
t > local_isect->
hits[0].
t) {
524 local_isect->
hits[hit_idx] = current_isect;
531 const RTCFilterFunctionNArguments *args)
534 assert(args->N == 1);
536 const RTCRay *ray = (RTCRay *)args->ray;
537 RTCHit *hit = (RTCHit *)args->hit;
538#if EMBREE_MAJOR_VERSION >= 4
543#ifdef __KERNEL_ONEAPI__
548 const Ray *cray = ctx->ray;
550#ifdef __VOLUME_RECORD_ALL__
552 if (ctx->num_hits < ctx->max_hits) {
556 kg, ray, hit, ¤t_isect,
reinterpret_cast<intptr_t>(args->geometryUserPtr));
564 *isect = current_isect;
570#ifndef __VOLUME_RECORD_ALL__
576#ifdef __VOLUME_RECORD_ALL__
583#if EMBREE_MAJOR_VERSION < 4
585 const RTCFilterFunctionNArguments *args)
588 assert(args->N == 1);
615 const RTCRay *ray = (RTCRay *)args->ray;
616 RTCHit *hit = (RTCHit *)args->hit;
620 make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)) > 0.0f)
628 const Ray *cray = ctx->
ray;
631 kg, hit, cray,
reinterpret_cast<intptr_t>(args->geometryUserPtr)))
638 const RTCFilterFunctionNArguments *args)
640 const RTCRay *ray = (RTCRay *)args->ray;
641 RTCHit *hit = (RTCHit *)args->hit;
645 make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)) > 0.0f)
655#ifdef __KERNEL_ONEAPI__
658kernel_embree_filter_intersection_func_static(
const RTCFilterFunctionNArguments *args)
660 RTCHit *hit = (RTCHit *)args->hit;
662 ONEAPIKernelContext *context =
static_cast<ONEAPIKernelContext *
>(ctx->
kg);
663 context->kernel_embree_filter_intersection_func_impl(args);
667kernel_embree_filter_occluded_shadow_all_func_static(
const RTCFilterFunctionNArguments *args)
669 RTCHit *hit = (RTCHit *)args->hit;
671 ONEAPIKernelContext *context =
static_cast<ONEAPIKernelContext *
>(ctx->kg);
672 context->kernel_embree_filter_occluded_shadow_all_func_impl(args);
676kernel_embree_filter_occluded_local_func_static(
const RTCFilterFunctionNArguments *args)
678 RTCHit *hit = (RTCHit *)args->hit;
680 ONEAPIKernelContext *context =
static_cast<ONEAPIKernelContext *
>(ctx->kg);
681 context->kernel_embree_filter_occluded_local_func_impl(args);
685kernel_embree_filter_occluded_volume_all_func_static(
const RTCFilterFunctionNArguments *args)
687 RTCHit *hit = (RTCHit *)args->hit;
689 ONEAPIKernelContext *context =
static_cast<ONEAPIKernelContext *
>(ctx->kg);
690 context->kernel_embree_filter_occluded_volume_all_func_impl(args);
693# define kernel_embree_filter_intersection_func \
694 ONEAPIKernelContext::kernel_embree_filter_intersection_func_static
695# define kernel_embree_filter_occluded_shadow_all_func \
696 ONEAPIKernelContext::kernel_embree_filter_occluded_shadow_all_func_static
697# define kernel_embree_filter_occluded_local_func \
698 ONEAPIKernelContext::kernel_embree_filter_occluded_local_func_static
699# define kernel_embree_filter_occluded_volume_all_func \
700 ONEAPIKernelContext::kernel_embree_filter_occluded_volume_all_func_static
702# define kernel_embree_filter_intersection_func kernel_embree_filter_intersection_func_impl
703# if EMBREE_MAJOR_VERSION >= 4
704# define kernel_embree_filter_occluded_shadow_all_func \
705 kernel_embree_filter_occluded_shadow_all_func_impl
706# define kernel_embree_filter_occluded_local_func kernel_embree_filter_occluded_local_func_impl
707# define kernel_embree_filter_occluded_volume_all_func \
708 kernel_embree_filter_occluded_volume_all_func_impl
716 const uint visibility,
719 isect->t = ray->tmax;
720#if EMBREE_MAJOR_VERSION >= 4
722 rtcInitRayQueryContext(&ctx);
723# ifdef __KERNEL_ONEAPI__
734 rtcInitIntersectContext(&ctx);
741#if EMBREE_MAJOR_VERSION >= 4
742 RTCIntersectArguments args;
743 rtcInitIntersectArguments(&args);
747 rtcIntersect1(
kernel_data.device_bvh, &ray_hit, &args);
749 rtcIntersect1(
kernel_data.device_bvh, &ctx, &ray_hit);
751 if (ray_hit.hit.geomID == RTC_INVALID_GEOMETRY_ID ||
752 ray_hit.hit.primID == RTC_INVALID_GEOMETRY_ID)
771# if EMBREE_MAJOR_VERSION >= 4
773 rtcInitRayQueryContext(&ctx);
774# ifdef __KERNEL_ONEAPI__
786 rtcInitIntersectContext(&ctx);
800# if EMBREE_MAJOR_VERSION >= 4
801 RTCOccludedArguments args;
802 rtcInitOccludedArguments(&args);
803 args.filter =
reinterpret_cast<RTCFilterFunctionN
>(kernel_embree_filter_occluded_local_func);
813# ifdef __OBJECT_MOTION__
814 bvh_instance_motion_push(kg, local_object, ray, &
P, &dir, &idir);
822 rtc_ray.dir_x = dir.
x;
823 rtc_ray.dir_y = dir.
y;
824 rtc_ray.dir_z = dir.
z;
825 rtc_ray.tnear = ray->tmin;
826 rtc_ray.tfar = ray->tmax;
831# if EMBREE_MAJOR_VERSION >= 4
832 rtcOccluded1(scene, &rtc_ray, &args);
834 rtcOccluded1(scene, &ctx, &rtc_ray);
839# if EMBREE_MAJOR_VERSION >= 4
840 rtcOccluded1(
kernel_data.device_bvh, &rtc_ray, &args);
842 rtcOccluded1(
kernel_data.device_bvh, &ctx, &rtc_ray);
847 return (local_isect && local_isect->num_hits > 0) || (rtc_ray.tfar < 0);
851#ifdef __SHADOW_RECORD_ALL__
860# if EMBREE_MAJOR_VERSION >= 4
862 rtcInitRayQueryContext(&ctx);
863# ifdef __KERNEL_ONEAPI__
874 rtcInitIntersectContext(&ctx);
881 ctx.
max_t = ray->tmax;
885# if EMBREE_MAJOR_VERSION >= 4
886 RTCOccludedArguments args;
887 rtcInitOccludedArguments(&args);
888 args.filter =
reinterpret_cast<RTCFilterFunctionN
>(
889 kernel_embree_filter_occluded_shadow_all_func);
892 rtcOccluded1(
kernel_data.device_bvh, &rtc_ray, &args);
894 rtcOccluded1(
kernel_data.device_bvh, &ctx, &rtc_ray);
910 const uint visibility)
912# if EMBREE_MAJOR_VERSION >= 4
914 rtcInitRayQueryContext(&ctx);
915# ifdef __KERNEL_ONEAPI__
926 rtcInitIntersectContext(&ctx);
929# ifdef __VOLUME_RECORD_ALL__
936# if EMBREE_MAJOR_VERSION >= 4
937 RTCOccludedArguments args;
938 rtcInitOccludedArguments(&args);
939 args.filter =
reinterpret_cast<RTCFilterFunctionN
>(
940 kernel_embree_filter_occluded_volume_all_func);
943 rtcOccluded1(
kernel_data.device_bvh, &rtc_ray, &args);
945 rtcOccluded1(
kernel_data.device_bvh, &ctx, &rtc_ray);
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
ccl_device_forceinline int intersection_get_shader_flags(KernelGlobals kg, const int prim, const int type)
ccl_device_inline bool intersection_skip_self_local(ccl_ray_data const RaySelfPrimitives &self, const int prim)
ccl_device_inline bool intersection_skip_self(ccl_ray_data const RaySelfPrimitives &self, const int object, const int prim)
ccl_device_inline bool intersection_skip_shadow_link(KernelGlobals kg, ccl_ray_data const RaySelfPrimitives &self, const int isect_object)
#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_inline bool intersection_skip_self_shadow(ccl_ray_data const RaySelfPrimitives &self, const int object, const int prim)
#define kernel_assert(cond)
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_device_forceinline
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define ccl_always_inline
#define ccl_device_intersect
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_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_inline void kernel_embree_convert_sss_hit(KernelGlobals kg, const RTCRay *ray, const RTCHit *hit, Intersection *isect, int object, const intptr_t prim_offset)
ccl_device_inline void kernel_embree_setup_rayhit(const Ray &ray, RTCRayHit &rayhit, const uint visibility)
ccl_device_forceinline void kernel_embree_filter_occluded_func(const RTCFilterFunctionNArguments *args)
ccl_device_intersect bool kernel_embree_intersect(KernelGlobals kg, ccl_private const Ray *ray, const uint visibility, ccl_private Intersection *isect)
#define kernel_embree_filter_intersection_func
ccl_device void kernel_embree_filter_occluded_func_backface_cull(const RTCFilterFunctionNArguments *args)
ccl_device_inline int kernel_embree_get_hit_object(const RTCHit *hit)
#define rtcGetGeometryUserDataFromScene(scene, id)
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)
ccl_device void kernel_embree_filter_func_backface_cull(const RTCFilterFunctionNArguments *args)
ccl_device_forceinline void kernel_embree_filter_intersection_func_impl(const RTCFilterFunctionNArguments *args)
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, int object, ccl_private const Ray *ray, ccl_private float3 *P, ccl_private float3 *dir, ccl_private float3 *idir)
@ SD_HAS_TRANSPARENT_SHADOW
@ PATH_RAY_ALL_VISIBILITY
#define INTEGRATOR_SHADOW_ISECT_SIZE
#define __VOLUME_RECORD_ALL__
@ SD_OBJECT_TRANSFORM_APPLIED
CCL_NAMESPACE_BEGIN ccl_device uint lcg_step_uint(T rng)
IntegratorShadowStateCPU *ccl_restrict IntegratorShadowState
#define INTEGRATOR_STATE_ARRAY(state, nested_struct, array_index, member)
ccl_device_forceinline void integrator_state_write_shadow_isect(IntegratorShadowState state, ccl_private const Intersection *ccl_restrict isect, const int index)
CCLIntersectContext(KernelGlobals kg_, RayType type_)
LocalIntersection * local_isect
numhit_t num_recorded_hits
IntegratorShadowState isect_s
struct Intersection hits[LOCAL_MAX_HITS]
float3 Ng[LOCAL_MAX_HITS]