Blender V4.3
kernel/device/hiprt/bvh.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
10
12{
13 return isfinite_safe(ray->P.x) && isfinite_safe(ray->D.x) && len_squared(ray->D) != 0.0f;
14}
15
17 ccl_private const Ray *ray,
18 const uint visibility,
20{
21 isect->t = ray->tmax;
22 isect->u = 0.0f;
23 isect->v = 0.0f;
24 isect->prim = PRIM_NONE;
25 isect->object = OBJECT_NONE;
26 isect->type = PRIMITIVE_NONE;
27 if (!scene_intersect_valid(ray)) {
28 isect->t = ray->tmax;
29 isect->type = PRIMITIVE_NONE;
30 return false;
31 }
32
33 hiprtRay ray_hip;
34
35 SET_HIPRT_RAY(ray_hip, ray)
36
37 RayPayload payload;
38 payload.self = ray->self;
39 payload.kg = kg;
40 payload.visibility = visibility;
41 payload.prim_type = PRIMITIVE_NONE;
42 payload.ray_time = ray->time;
43
44 hiprtHit hit = {};
45
46 GET_TRAVERSAL_STACK()
47
48 if (visibility & PATH_RAY_SHADOW_OPAQUE) {
49 GET_TRAVERSAL_ANY_HIT(table_closest_intersect, 0, ray->time)
50 hit = traversal.getNextHit();
51 }
52 else {
53 GET_TRAVERSAL_CLOSEST_HIT(table_closest_intersect, 0, ray->time)
54 hit = traversal.getNextHit();
55 }
56 if (hit.hasHit()) {
57 set_intersect_point(kg, hit, isect);
58 if (isect->type > 1) { // should be applied only for curves
59 isect->type = payload.prim_type;
60 isect->prim = hit.primID;
61 }
62 return true;
63 }
64 return false;
65}
66
68 ccl_private const Ray *ray,
69 const uint visibility)
70{
71 Intersection isect;
72 return scene_intersect(kg, ray, visibility, &isect);
73}
74
75#ifdef __BVH_LOCAL__
76template<bool single_hit = false>
77ccl_device_intersect bool scene_intersect_local(KernelGlobals kg,
78 ccl_private const Ray *ray,
79 ccl_private LocalIntersection *local_isect,
80 int local_object,
81 ccl_private uint *lcg_state,
82 int max_hits)
83{
84 if (!scene_intersect_valid(ray)) {
85 if (local_isect) {
86 local_isect->num_hits = 0;
87 }
88 return false;
89 }
90
91 float3 P = ray->P;
92 float3 dir = bvh_clamp_direction(ray->D);
93 float3 idir = bvh_inverse_direction(dir);
94
95 if (local_isect != NULL) {
96 local_isect->num_hits = 0;
97 }
98
99 const int object_flag = kernel_data_fetch(object_flag, local_object);
100 if (!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
101
102# if BVH_FEATURE(BVH_MOTION)
103 bvh_instance_motion_push(kg, local_object, ray, &P, &dir, &idir);
104# else
105 bvh_instance_push(kg, local_object, ray, &P, &dir, &idir);
106# endif
107 }
108
109 hiprtRay ray_hip;
110 ray_hip.origin = P;
111 ray_hip.direction = dir;
112 ray_hip.maxT = ray->tmax;
113 ray_hip.minT = ray->tmin;
114
115 LocalPayload payload = {0};
116 payload.kg = kg;
117 payload.self = ray->self;
118 payload.local_object = local_object;
119 payload.max_hits = max_hits;
120 payload.lcg_state = lcg_state;
121 payload.local_isect = local_isect;
122
123 GET_TRAVERSAL_STACK()
124
125 void *local_geom = (void *)(kernel_data_fetch(blas_ptr, local_object));
126 // we don't need custom intersection functions for SSR
127# ifdef HIPRT_SHARED_STACK
128 hiprtGeomTraversalAnyHitCustomStack<Stack> traversal((hiprtGeometry)local_geom,
129 ray_hip,
130 stack,
131 hiprtTraversalHintDefault,
132 &payload,
133 kernel_params.table_local_intersect,
134 2);
135# else
136 hiprtGeomTraversalAnyHit traversal(
137 local_geom, ray_hip, table, hiprtTraversalHintDefault, &payload);
138# endif
139 hiprtHit hit = traversal.getNextHit();
140 return hit.hasHit();
141}
142#endif //__BVH_LOCAL__
143
144#ifdef __SHADOW_RECORD_ALL__
145ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals kg,
147 ccl_private const Ray *ray,
148 uint visibility,
149 uint max_hits,
150 ccl_private uint *num_recorded_hits,
151 ccl_private float *throughput)
152{
153 *throughput = 1.0f;
154 *num_recorded_hits = 0;
155
156 if (!scene_intersect_valid(ray)) {
157 return false;
158 }
159
160 hiprtRay ray_hip;
161
162 SET_HIPRT_RAY(ray_hip, ray)
163 ShadowPayload payload;
164 payload.kg = kg;
165 payload.self = ray->self;
166 payload.in_state = state;
167 payload.max_hits = max_hits;
168 payload.visibility = visibility;
169 payload.prim_type = PRIMITIVE_NONE;
170 payload.ray_time = ray->time;
171 payload.num_hits = 0;
172 payload.r_num_recorded_hits = num_recorded_hits;
173 payload.r_throughput = throughput;
174 GET_TRAVERSAL_STACK()
175 GET_TRAVERSAL_ANY_HIT(table_shadow_intersect, 1, ray->time)
176 hiprtHit hit = traversal.getNextHit();
177 num_recorded_hits = payload.r_num_recorded_hits;
178 throughput = payload.r_throughput;
179 return hit.hasHit();
180}
181#endif /* __SHADOW_RECORD_ALL__ */
182
183#ifdef __VOLUME__
184ccl_device_intersect bool scene_intersect_volume(KernelGlobals kg,
185 ccl_private const Ray *ray,
187 const uint visibility)
188{
189 isect->t = ray->tmax;
190 isect->u = 0.0f;
191 isect->v = 0.0f;
192 isect->prim = PRIM_NONE;
193 isect->object = OBJECT_NONE;
194 isect->type = PRIMITIVE_NONE;
195
196 if (!scene_intersect_valid(ray)) {
197 return false;
198 }
199
200 hiprtRay ray_hip;
201
202 SET_HIPRT_RAY(ray_hip, ray)
203
204 RayPayload payload;
205 payload.self = ray->self;
206 payload.kg = kg;
207 payload.visibility = visibility;
208 payload.prim_type = PRIMITIVE_NONE;
209 payload.ray_time = ray->time;
210
211 GET_TRAVERSAL_STACK()
212
213 GET_TRAVERSAL_CLOSEST_HIT(table_volume_intersect, 3, ray->time)
214 hiprtHit hit = traversal.getNextHit();
215 // return hit.hasHit();
216 if (hit.hasHit()) {
217 set_intersect_point(kg, hit, isect);
218 if (isect->type > 1) { // should be applied only for curves
219 isect->type = payload.prim_type;
220 isect->prim = hit.primID;
221 }
222 return true;
223 }
224 else
225 return false;
226}
227#endif /* __VOLUME__ */
228
unsigned int uint
return(oflags[bm->toolflag_index].f &oflag) !=0
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define kernel_data_fetch(name, index)
#define ccl_private
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define NULL
#define ccl_device_intersect
ccl_device_intersect bool scene_intersect(KernelGlobals kg, ccl_private const Ray *ray, const uint visibility, ccl_private Intersection *isect)
ccl_device_intersect bool scene_intersect_shadow(KernelGlobals kg, ccl_private const Ray *ray, const uint visibility)
CCL_NAMESPACE_BEGIN ccl_device_inline bool scene_intersect_valid(ccl_private const Ray *ray)
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)
ccl_device_inline float3 bvh_clamp_direction(float3 dir)
ccl_device_inline float3 bvh_inverse_direction(float3 dir)
@ PRIMITIVE_NONE
#define PRIM_NONE
@ PATH_RAY_SHADOW_OPAQUE
#define OBJECT_NONE
@ SD_OBJECT_TRANSFORM_APPLIED
ccl_device_inline float len_squared(const float2 a)
static ulong state[N]
IntegratorShadowStateCPU *ccl_restrict IntegratorShadowState
Definition state.h:230
ccl_device_inline bool isfinite_safe(float f)
Definition util/math.h:365