Blender  V2.93
kernel/bvh/bvh_embree.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018, Blender Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <embree3/rtcore_ray.h>
18 #include <embree3/rtcore_scene.h>
19 
20 // clang-format off
23 #include "kernel/kernel_globals.h"
24 // clang-format on
25 
26 #include "util/util_vector.h"
27 
29 
31  typedef enum {
34  RAY_LOCAL = 2,
35  RAY_SSS = 3,
37  } RayType;
38 
39  KernelGlobals *kg;
41 
42  /* for shadow rays */
44  int max_hits;
45  int num_hits;
46 
47  /* for SSS Rays: */
51 
52  CCLIntersectContext(KernelGlobals *kg_, RayType type_)
53  {
54  kg = kg_;
55  type = type_;
56  max_hits = 1;
57  num_hits = 0;
58  isect_s = NULL;
59  local_isect = NULL;
60  local_object_id = -1;
61  lcg_state = NULL;
62  }
63 };
64 
66  public:
68  {
69  rtcInitIntersectContext(&context);
70  userRayExt = ctx;
71  }
72  RTCIntersectContext context;
74 };
75 
77  RTCRay &rtc_ray,
78  const uint visibility)
79 {
80  rtc_ray.org_x = ray.P.x;
81  rtc_ray.org_y = ray.P.y;
82  rtc_ray.org_z = ray.P.z;
83  rtc_ray.dir_x = ray.D.x;
84  rtc_ray.dir_y = ray.D.y;
85  rtc_ray.dir_z = ray.D.z;
86  rtc_ray.tnear = 0.0f;
87  rtc_ray.tfar = ray.t;
88  rtc_ray.time = ray.time;
89  rtc_ray.mask = visibility;
90 }
91 
93  RTCRayHit &rayhit,
94  const uint visibility)
95 {
96  kernel_embree_setup_ray(ray, rayhit.ray, visibility);
97  rayhit.hit.geomID = RTC_INVALID_GEOMETRY_ID;
98  rayhit.hit.primID = RTC_INVALID_GEOMETRY_ID;
99 }
100 
102  const RTCRay *ray,
103  const RTCHit *hit,
104  Intersection *isect)
105 {
106  bool is_hair = hit->geomID & 1;
107  isect->u = is_hair ? hit->u : 1.0f - hit->v - hit->u;
108  isect->v = is_hair ? hit->v : hit->u;
109  isect->t = ray->tfar;
110  isect->Ng = make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z);
111  if (hit->instID[0] != RTC_INVALID_GEOMETRY_ID) {
112  RTCScene inst_scene = (RTCScene)rtcGetGeometryUserData(
113  rtcGetGeometry(kernel_data.bvh.scene, hit->instID[0]));
114  isect->prim = hit->primID +
115  (intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID));
116  isect->object = hit->instID[0] / 2;
117  }
118  else {
119  isect->prim = hit->primID + (intptr_t)rtcGetGeometryUserData(
120  rtcGetGeometry(kernel_data.bvh.scene, hit->geomID));
121  isect->object = OBJECT_NONE;
122  }
123  isect->type = kernel_tex_fetch(__prim_type, isect->prim);
124 }
125 
127  const RTCRay *ray,
128  const RTCHit *hit,
129  Intersection *isect,
130  int local_object_id)
131 {
132  isect->u = 1.0f - hit->v - hit->u;
133  isect->v = hit->u;
134  isect->t = ray->tfar;
135  isect->Ng = make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z);
136  RTCScene inst_scene = (RTCScene)rtcGetGeometryUserData(
137  rtcGetGeometry(kernel_data.bvh.scene, local_object_id * 2));
138  isect->prim = hit->primID +
139  (intptr_t)rtcGetGeometryUserData(rtcGetGeometry(inst_scene, hit->geomID));
140  isect->object = local_object_id;
141  isect->type = kernel_tex_fetch(__prim_type, isect->prim);
142 }
143 
unsigned int uint
Definition: BLI_sys_types.h:83
IntersectContext(CCLIntersectContext *ctx)
CCLIntersectContext * userRayExt
RTCIntersectContext context
ccl_device_inline void kernel_embree_convert_sss_hit(KernelGlobals *kg, const RTCRay *ray, const RTCHit *hit, Intersection *isect, int local_object_id)
ccl_device_inline void kernel_embree_setup_rayhit(const Ray &ray, RTCRayHit &rayhit, const uint visibility)
ccl_device_inline void kernel_embree_convert_hit(KernelGlobals *kg, const RTCRay *ray, const RTCHit *hit, Intersection *isect)
ccl_device_inline void kernel_embree_setup_ray(const Ray &ray, RTCRay &rtc_ray, const uint visibility)
#define kernel_data
#define kernel_tex_fetch(tex, index)
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
#define OBJECT_NONE
Definition: kernel_types.h:59
_W64 int intptr_t
Definition: stdint.h:121
LocalIntersection * local_isect
CCLIntersectContext(KernelGlobals *kg_, RayType type_)
float t
Definition: kernel_types.h:649
float3 P
Definition: kernel_types.h:647
float time
Definition: kernel_types.h:650
float3 D
Definition: kernel_types.h:648
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35