Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/bvh/bvh_embree.h
| /* | /* | ||||
| * Copyright 2018, Blender Foundation. | * Copyright 2018, Blender Foundation. | ||||
| * | * | ||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
| * You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
| * | * | ||||
| * http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | * | ||||
| * Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
| * distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #pragma once | |||||
| #include <embree3/rtcore_ray.h> | #include <embree3/rtcore_ray.h> | ||||
| #include <embree3/rtcore_scene.h> | #include <embree3/rtcore_scene.h> | ||||
| // clang-format off | #include "kernel/device/cpu/compat.h" | ||||
| #include "kernel/kernel_compat_cpu.h" | #include "kernel/device/cpu/globals.h" | ||||
| #include "kernel/split/kernel_split_data_types.h" | |||||
| #include "kernel/kernel_globals.h" | |||||
| // clang-format on | |||||
| #include "util/util_vector.h" | #include "util/util_vector.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| struct CCLIntersectContext { | struct CCLIntersectContext { | ||||
| typedef enum { | typedef enum { | ||||
| RAY_REGULAR = 0, | RAY_REGULAR = 0, | ||||
| RAY_SHADOW_ALL = 1, | RAY_SHADOW_ALL = 1, | ||||
| RAY_LOCAL = 2, | RAY_LOCAL = 2, | ||||
| RAY_SSS = 3, | RAY_SSS = 3, | ||||
| RAY_VOLUME_ALL = 4, | RAY_VOLUME_ALL = 4, | ||||
| } RayType; | } RayType; | ||||
| KernelGlobals *kg; | const KernelGlobals *kg; | ||||
| RayType type; | RayType type; | ||||
| /* for shadow rays */ | /* for shadow rays */ | ||||
| Intersection *isect_s; | Intersection *isect_s; | ||||
| int max_hits; | int max_hits; | ||||
| int num_hits; | int num_hits; | ||||
| float max_t; | |||||
| bool opaque_hit; | |||||
| /* for SSS Rays: */ | /* for SSS Rays: */ | ||||
| LocalIntersection *local_isect; | LocalIntersection *local_isect; | ||||
| int local_object_id; | int local_object_id; | ||||
| uint *lcg_state; | uint *lcg_state; | ||||
| CCLIntersectContext(KernelGlobals *kg_, RayType type_) | CCLIntersectContext(const KernelGlobals *kg_, RayType type_) | ||||
| { | { | ||||
| kg = kg_; | kg = kg_; | ||||
| type = type_; | type = type_; | ||||
| max_hits = 1; | max_hits = 1; | ||||
| num_hits = 0; | num_hits = 0; | ||||
| max_t = FLT_MAX; | |||||
| opaque_hit = false; | |||||
| isect_s = NULL; | isect_s = NULL; | ||||
| local_isect = NULL; | local_isect = NULL; | ||||
| local_object_id = -1; | local_object_id = -1; | ||||
| lcg_state = NULL; | lcg_state = NULL; | ||||
| } | } | ||||
| }; | }; | ||||
| class IntersectContext { | class IntersectContext { | ||||
| Show All 27 Lines | ccl_device_inline void kernel_embree_setup_rayhit(const Ray &ray, | ||||
| RTCRayHit &rayhit, | RTCRayHit &rayhit, | ||||
| const uint visibility) | const uint visibility) | ||||
| { | { | ||||
| kernel_embree_setup_ray(ray, rayhit.ray, visibility); | kernel_embree_setup_ray(ray, rayhit.ray, visibility); | ||||
| rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID; | rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID; | ||||
| rayhit.hit.primID = RTC_INVALID_GEOMETRY_ID; | rayhit.hit.primID = RTC_INVALID_GEOMETRY_ID; | ||||
| } | } | ||||
| ccl_device_inline void kernel_embree_convert_hit(KernelGlobals *kg, | ccl_device_inline void kernel_embree_convert_hit(const KernelGlobals *kg, | ||||
| const RTCRay *ray, | const RTCRay *ray, | ||||
| const RTCHit *hit, | const RTCHit *hit, | ||||
| Intersection *isect) | Intersection *isect) | ||||
| { | { | ||||
| bool is_hair = hit->geomID & 1; | bool is_hair = hit->geomID & 1; | ||||
| isect->u = is_hair ? hit->u : 1.0f - hit->v - hit->u; | isect->u = is_hair ? hit->u : 1.0f - hit->v - hit->u; | ||||
| isect->v = is_hair ? hit->v : hit->u; | isect->v = is_hair ? hit->v : hit->u; | ||||
| isect->t = ray->tfar; | isect->t = ray->tfar; | ||||
| isect->Ng = make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z); | isect->Ng = make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z); | ||||
| if (hit->instID[0] != RTC_INVALID_GEOMETRY_ID) { | if (hit->instID[0] != RTC_INVALID_GEOMETRY_ID) { | ||||
| RTCScene inst_scene = (RTCScene)rtcGetGeometryUserData( | RTCScene inst_scene = (RTCScene)rtcGetGeometryUserData( | ||||
| rtcGetGeometry(kernel_data.bvh.scene, hit->instID[0])); | rtcGetGeometry(kernel_data.bvh.scene, hit->instID[0])); | ||||
| isect->prim = hit->primID + | isect->prim = hit->primID + | ||||
| (intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID)); | (intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID)); | ||||
| isect->object = hit->instID[0] / 2; | isect->object = hit->instID[0] / 2; | ||||
| } | } | ||||
| else { | else { | ||||
| isect->prim = hit->primID + (intptr_t)rtcGetGeometryUserData( | isect->prim = hit->primID + (intptr_t)rtcGetGeometryUserData( | ||||
| rtcGetGeometry(kernel_data.bvh.scene, hit->geomID)); | rtcGetGeometry(kernel_data.bvh.scene, hit->geomID)); | ||||
| isect->object = OBJECT_NONE; | isect->object = OBJECT_NONE; | ||||
| } | } | ||||
| isect->type = kernel_tex_fetch(__prim_type, isect->prim); | isect->type = kernel_tex_fetch(__prim_type, isect->prim); | ||||
| } | } | ||||
| ccl_device_inline void kernel_embree_convert_sss_hit(KernelGlobals *kg, | ccl_device_inline void kernel_embree_convert_sss_hit(const KernelGlobals *kg, | ||||
| const RTCRay *ray, | const RTCRay *ray, | ||||
| const RTCHit *hit, | const RTCHit *hit, | ||||
| Intersection *isect, | Intersection *isect, | ||||
| int local_object_id) | int local_object_id) | ||||
| { | { | ||||
| isect->u = 1.0f - hit->v - hit->u; | isect->u = 1.0f - hit->v - hit->u; | ||||
| isect->v = hit->u; | isect->v = hit->u; | ||||
| isect->t = ray->tfar; | isect->t = ray->tfar; | ||||
| Show All 10 Lines | |||||