Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/include/embree4/rtcore_ray.h
9905 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "rtcore_common.h"
7
8
RTC_NAMESPACE_BEGIN
9
10
/* Ray structure for a single ray */
11
struct RTC_ALIGN(16) RTCRay
12
{
13
float org_x; // x coordinate of ray origin
14
float org_y; // y coordinate of ray origin
15
float org_z; // z coordinate of ray origin
16
float tnear; // start of ray segment
17
18
float dir_x; // x coordinate of ray direction
19
float dir_y; // y coordinate of ray direction
20
float dir_z; // z coordinate of ray direction
21
float time; // time of this ray for motion blur
22
23
float tfar; // end of ray segment (set to hit distance)
24
unsigned int mask; // ray mask
25
unsigned int id; // ray ID
26
unsigned int flags; // ray flags
27
};
28
29
/* Hit structure for a single ray */
30
struct RTC_ALIGN(16) RTCHit
31
{
32
float Ng_x; // x coordinate of geometry normal
33
float Ng_y; // y coordinate of geometry normal
34
float Ng_z; // z coordinate of geometry normal
35
36
float u; // barycentric u coordinate of hit
37
float v; // barycentric v coordinate of hit
38
39
unsigned int primID; // primitive ID
40
unsigned int geomID; // geometry ID
41
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance ID
42
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
43
unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT]; // instance primitive ID
44
#endif
45
};
46
47
/* Combined ray/hit structure for a single ray */
48
struct RTCRayHit
49
{
50
struct RTCRay ray;
51
struct RTCHit hit;
52
};
53
54
/* Ray structure for a packet of 4 rays */
55
struct RTC_ALIGN(16) RTCRay4
56
{
57
float org_x[4];
58
float org_y[4];
59
float org_z[4];
60
float tnear[4];
61
62
float dir_x[4];
63
float dir_y[4];
64
float dir_z[4];
65
float time[4];
66
67
float tfar[4];
68
unsigned int mask[4];
69
unsigned int id[4];
70
unsigned int flags[4];
71
};
72
73
/* Hit structure for a packet of 4 rays */
74
struct RTC_ALIGN(16) RTCHit4
75
{
76
float Ng_x[4];
77
float Ng_y[4];
78
float Ng_z[4];
79
80
float u[4];
81
float v[4];
82
83
unsigned int primID[4];
84
unsigned int geomID[4];
85
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][4];
86
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
87
unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][4];
88
#endif
89
};
90
91
/* Combined ray/hit structure for a packet of 4 rays */
92
struct RTCRayHit4
93
{
94
struct RTCRay4 ray;
95
struct RTCHit4 hit;
96
};
97
98
/* Ray structure for a packet of 8 rays */
99
struct RTC_ALIGN(32) RTCRay8
100
{
101
float org_x[8];
102
float org_y[8];
103
float org_z[8];
104
float tnear[8];
105
106
float dir_x[8];
107
float dir_y[8];
108
float dir_z[8];
109
float time[8];
110
111
float tfar[8];
112
unsigned int mask[8];
113
unsigned int id[8];
114
unsigned int flags[8];
115
};
116
117
/* Hit structure for a packet of 8 rays */
118
struct RTC_ALIGN(32) RTCHit8
119
{
120
float Ng_x[8];
121
float Ng_y[8];
122
float Ng_z[8];
123
124
float u[8];
125
float v[8];
126
127
unsigned int primID[8];
128
unsigned int geomID[8];
129
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][8];
130
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
131
unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][8];
132
#endif
133
};
134
135
/* Combined ray/hit structure for a packet of 8 rays */
136
struct RTCRayHit8
137
{
138
struct RTCRay8 ray;
139
struct RTCHit8 hit;
140
};
141
142
/* Ray structure for a packet of 16 rays */
143
struct RTC_ALIGN(64) RTCRay16
144
{
145
float org_x[16];
146
float org_y[16];
147
float org_z[16];
148
float tnear[16];
149
150
float dir_x[16];
151
float dir_y[16];
152
float dir_z[16];
153
float time[16];
154
155
float tfar[16];
156
unsigned int mask[16];
157
unsigned int id[16];
158
unsigned int flags[16];
159
};
160
161
/* Hit structure for a packet of 16 rays */
162
struct RTC_ALIGN(64) RTCHit16
163
{
164
float Ng_x[16];
165
float Ng_y[16];
166
float Ng_z[16];
167
168
float u[16];
169
float v[16];
170
171
unsigned int primID[16];
172
unsigned int geomID[16];
173
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][16];
174
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
175
unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][16];
176
#endif
177
};
178
179
/* Combined ray/hit structure for a packet of 16 rays */
180
struct RTCRayHit16
181
{
182
struct RTCRay16 ray;
183
struct RTCHit16 hit;
184
};
185
186
struct RTCRayN;
187
struct RTCHitN;
188
struct RTCRayHitN;
189
190
#if defined(__cplusplus)
191
192
/* Helper functions to access ray packets of runtime size N */
193
RTC_FORCEINLINE float& RTCRayN_org_x(RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[0*N+i]; }
194
RTC_FORCEINLINE float& RTCRayN_org_y(RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[1*N+i]; }
195
RTC_FORCEINLINE float& RTCRayN_org_z(RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[2*N+i]; }
196
RTC_FORCEINLINE float& RTCRayN_tnear(RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[3*N+i]; }
197
198
RTC_FORCEINLINE float& RTCRayN_dir_x(RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[4*N+i]; }
199
RTC_FORCEINLINE float& RTCRayN_dir_y(RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[5*N+i]; }
200
RTC_FORCEINLINE float& RTCRayN_dir_z(RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[6*N+i]; }
201
RTC_FORCEINLINE float& RTCRayN_time (RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[7*N+i]; }
202
203
RTC_FORCEINLINE float& RTCRayN_tfar (RTCRayN* ray, unsigned int N, unsigned int i) { return ((float*)ray)[8*N+i]; }
204
RTC_FORCEINLINE unsigned int& RTCRayN_mask (RTCRayN* ray, unsigned int N, unsigned int i) { return ((unsigned*)ray)[9*N+i]; }
205
RTC_FORCEINLINE unsigned int& RTCRayN_id (RTCRayN* ray, unsigned int N, unsigned int i) { return ((unsigned*)ray)[10*N+i]; }
206
RTC_FORCEINLINE unsigned int& RTCRayN_flags(RTCRayN* ray, unsigned int N, unsigned int i) { return ((unsigned*)ray)[11*N+i]; }
207
208
/* Helper functions to access hit packets of runtime size N */
209
RTC_FORCEINLINE float& RTCHitN_Ng_x(RTCHitN* hit, unsigned int N, unsigned int i) { return ((float*)hit)[0*N+i]; }
210
RTC_FORCEINLINE float& RTCHitN_Ng_y(RTCHitN* hit, unsigned int N, unsigned int i) { return ((float*)hit)[1*N+i]; }
211
RTC_FORCEINLINE float& RTCHitN_Ng_z(RTCHitN* hit, unsigned int N, unsigned int i) { return ((float*)hit)[2*N+i]; }
212
213
RTC_FORCEINLINE float& RTCHitN_u(RTCHitN* hit, unsigned int N, unsigned int i) { return ((float*)hit)[3*N+i]; }
214
RTC_FORCEINLINE float& RTCHitN_v(RTCHitN* hit, unsigned int N, unsigned int i) { return ((float*)hit)[4*N+i]; }
215
216
RTC_FORCEINLINE unsigned int& RTCHitN_primID (RTCHitN* hit, unsigned int N, unsigned int i) { return ((unsigned*)hit)[5*N+i]; }
217
RTC_FORCEINLINE unsigned int& RTCHitN_geomID (RTCHitN* hit, unsigned int N, unsigned int i) { return ((unsigned*)hit)[6*N+i]; }
218
RTC_FORCEINLINE unsigned int& RTCHitN_instID (RTCHitN* hit, unsigned int N, unsigned int i, unsigned int l) { return ((unsigned*)hit)[7*N + N*l + i]; }
219
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
220
RTC_FORCEINLINE unsigned int& RTCHitN_instPrimID(RTCHitN* hit, unsigned int N, unsigned int i, unsigned int l) { return ((unsigned*)hit)[7*N + N*RTC_MAX_INSTANCE_LEVEL_COUNT + N*l + i]; }
221
#endif
222
223
/* Helper functions to extract RTCRayN and RTCHitN from RTCRayHitN */
224
RTC_FORCEINLINE RTCRayN* RTCRayHitN_RayN(RTCRayHitN* rayhit, unsigned int N) { return (RTCRayN*)&((float*)rayhit)[0*N]; }
225
RTC_FORCEINLINE RTCHitN* RTCRayHitN_HitN(RTCRayHitN* rayhit, unsigned int N) { return (RTCHitN*)&((float*)rayhit)[12*N]; }
226
227
/* Helper structure for a ray packet of compile-time size N */
228
template<unsigned int N>
229
struct RTC_ALIGN((N && !(N & (N - 1)) ? (N * 4 > 16 ? N * 4 : 16) : 16)) RTCRayNt
230
{
231
float org_x[N];
232
float org_y[N];
233
float org_z[N];
234
float tnear[N];
235
236
float dir_x[N];
237
float dir_y[N];
238
float dir_z[N];
239
float time[N];
240
241
float tfar[N];
242
unsigned int mask[N];
243
unsigned int id[N];
244
unsigned int flags[N];
245
};
246
247
/* Helper structure for a hit packet of compile-time size N */
248
template<unsigned int N>
249
struct RTC_ALIGN((N && !(N & (N - 1)) ? (N * 4 > 16 ? N * 4 : 16) : 16)) RTCHitNt
250
{
251
float Ng_x[N];
252
float Ng_y[N];
253
float Ng_z[N];
254
255
float u[N];
256
float v[N];
257
258
unsigned int primID[N];
259
unsigned int geomID[N];
260
unsigned int instID[RTC_MAX_INSTANCE_LEVEL_COUNT][N];
261
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
262
unsigned int instPrimID[RTC_MAX_INSTANCE_LEVEL_COUNT][N];
263
#endif
264
};
265
266
/* Helper structure for a combined ray/hit packet of compile-time size N */
267
template<int N>
268
struct RTCRayHitNt
269
{
270
RTCRayNt<N> ray;
271
RTCHitNt<N> hit;
272
};
273
274
RTC_FORCEINLINE RTCRay rtcGetRayFromRayN(RTCRayN* rayN, unsigned int N, unsigned int i)
275
{
276
RTCRay ray;
277
ray.org_x = RTCRayN_org_x(rayN,N,i);
278
ray.org_y = RTCRayN_org_y(rayN,N,i);
279
ray.org_z = RTCRayN_org_z(rayN,N,i);
280
ray.tnear = RTCRayN_tnear(rayN,N,i);
281
ray.dir_x = RTCRayN_dir_x(rayN,N,i);
282
ray.dir_y = RTCRayN_dir_y(rayN,N,i);
283
ray.dir_z = RTCRayN_dir_z(rayN,N,i);
284
ray.time = RTCRayN_time(rayN,N,i);
285
ray.tfar = RTCRayN_tfar(rayN,N,i);
286
ray.mask = RTCRayN_mask(rayN,N,i);
287
ray.id = RTCRayN_id(rayN,N,i);
288
ray.flags = RTCRayN_flags(rayN,N,i);
289
return ray;
290
}
291
292
RTC_FORCEINLINE RTCHit rtcGetHitFromHitN(RTCHitN* hitN, unsigned int N, unsigned int i)
293
{
294
RTCHit hit;
295
hit.Ng_x = RTCHitN_Ng_x(hitN,N,i);
296
hit.Ng_y = RTCHitN_Ng_y(hitN,N,i);
297
hit.Ng_z = RTCHitN_Ng_z(hitN,N,i);
298
hit.u = RTCHitN_u(hitN,N,i);
299
hit.v = RTCHitN_v(hitN,N,i);
300
hit.primID = RTCHitN_primID(hitN,N,i);
301
hit.geomID = RTCHitN_geomID(hitN,N,i);
302
for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) {
303
hit.instID[l] = RTCHitN_instID(hitN,N,i,l);
304
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
305
hit.instPrimID[l] = RTCHitN_instPrimID(hitN,N,i,l);
306
#endif
307
}
308
return hit;
309
}
310
311
RTC_FORCEINLINE void rtcCopyHitToHitN(RTCHitN* hitN, const RTCHit* hit, unsigned int N, unsigned int i)
312
{
313
RTCHitN_Ng_x(hitN,N,i) = hit->Ng_x;
314
RTCHitN_Ng_y(hitN,N,i) = hit->Ng_y;
315
RTCHitN_Ng_z(hitN,N,i) = hit->Ng_z;
316
RTCHitN_u(hitN,N,i) = hit->u;
317
RTCHitN_v(hitN,N,i) = hit->v;
318
RTCHitN_primID(hitN,N,i) = hit->primID;
319
RTCHitN_geomID(hitN,N,i) = hit->geomID;
320
for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) {
321
RTCHitN_instID(hitN,N,i,l) = hit->instID[l];
322
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
323
RTCHitN_instPrimID(hitN,N,i,l) = hit->instPrimID[l];
324
#endif
325
}
326
}
327
328
RTC_FORCEINLINE RTCRayHit rtcGetRayHitFromRayHitN(RTCRayHitN* rayhitN, unsigned int N, unsigned int i)
329
{
330
RTCRayHit rh;
331
332
RTCRayN* ray = RTCRayHitN_RayN(rayhitN,N);
333
rh.ray.org_x = RTCRayN_org_x(ray,N,i);
334
rh.ray.org_y = RTCRayN_org_y(ray,N,i);
335
rh.ray.org_z = RTCRayN_org_z(ray,N,i);
336
rh.ray.tnear = RTCRayN_tnear(ray,N,i);
337
rh.ray.dir_x = RTCRayN_dir_x(ray,N,i);
338
rh.ray.dir_y = RTCRayN_dir_y(ray,N,i);
339
rh.ray.dir_z = RTCRayN_dir_z(ray,N,i);
340
rh.ray.time = RTCRayN_time(ray,N,i);
341
rh.ray.tfar = RTCRayN_tfar(ray,N,i);
342
rh.ray.mask = RTCRayN_mask(ray,N,i);
343
rh.ray.id = RTCRayN_id(ray,N,i);
344
rh.ray.flags = RTCRayN_flags(ray,N,i);
345
346
RTCHitN* hit = RTCRayHitN_HitN(rayhitN,N);
347
rh.hit.Ng_x = RTCHitN_Ng_x(hit,N,i);
348
rh.hit.Ng_y = RTCHitN_Ng_y(hit,N,i);
349
rh.hit.Ng_z = RTCHitN_Ng_z(hit,N,i);
350
rh.hit.u = RTCHitN_u(hit,N,i);
351
rh.hit.v = RTCHitN_v(hit,N,i);
352
rh.hit.primID = RTCHitN_primID(hit,N,i);
353
rh.hit.geomID = RTCHitN_geomID(hit,N,i);
354
for (unsigned int l = 0; l < RTC_MAX_INSTANCE_LEVEL_COUNT; l++) {
355
rh.hit.instID[l] = RTCHitN_instID(hit,N,i,l);
356
#if defined(RTC_GEOMETRY_INSTANCE_ARRAY)
357
rh.hit.instPrimID[l] = RTCHitN_instPrimID(hit,N,i,l);
358
#endif
359
}
360
361
return rh;
362
}
363
364
#endif
365
366
RTC_NAMESPACE_END
367
368
369