Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/kernels/geometry/object_intersector.h
9905 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "object.h"
7
#include "../common/ray.h"
8
9
namespace embree
10
{
11
namespace isa
12
{
13
template<bool mblur>
14
struct ObjectIntersector1
15
{
16
typedef Object Primitive;
17
18
static const bool validIntersectorK = false;
19
20
struct Precalculations {
21
__forceinline Precalculations() {}
22
__forceinline Precalculations (const Ray& ray, const void *ptr) {}
23
};
24
25
static __forceinline void intersect(const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim)
26
{
27
AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
28
29
/* perform ray mask test */
30
#if defined(EMBREE_RAY_MASK)
31
if ((ray.mask & accel->mask) == 0)
32
return;
33
#endif
34
35
accel->intersect(ray,prim.geomID(),prim.primID(),context);
36
}
37
38
static __forceinline bool occluded(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim)
39
{
40
AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
41
/* perform ray mask test */
42
#if defined(EMBREE_RAY_MASK)
43
if ((ray.mask & accel->mask) == 0)
44
return false;
45
#endif
46
47
accel->occluded(ray,prim.geomID(),prim.primID(),context);
48
return ray.tfar < 0.0f;
49
}
50
51
static __forceinline bool intersect(const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) {
52
return occluded(pre,ray,context,prim);
53
}
54
55
static __forceinline void intersect(unsigned int k, const Precalculations& pre, RayHit& ray, RayQueryContext* context, const Primitive& prim)
56
{
57
AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
58
59
/* perform ray mask test */
60
#if defined(EMBREE_RAY_MASK)
61
if ((ray.mask & accel->mask) == 0)
62
return;
63
#endif
64
65
accel->intersect(k,ray,prim.geomID(),prim.primID(),context);
66
}
67
68
static __forceinline bool occluded(unsigned int k, const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim)
69
{
70
AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
71
/* perform ray mask test */
72
#if defined(EMBREE_RAY_MASK)
73
if ((ray.mask & accel->mask) == 0)
74
return false;
75
#endif
76
77
accel->occluded(k, ray,prim.geomID(),prim.primID(),context);
78
return ray.tfar < 0.0f;
79
}
80
81
static __forceinline bool intersect(unsigned int k, const Precalculations& pre, Ray& ray, RayQueryContext* context, const Primitive& prim) {
82
return occluded(k,pre,ray,context,prim);
83
}
84
85
static __forceinline bool pointQuery(PointQuery* query, PointQueryContext* context, const Primitive& prim)
86
{
87
AccelSet* accel = (AccelSet*)context->scene->get(prim.geomID());
88
context->geomID = prim.geomID();
89
context->primID = prim.primID();
90
return accel->pointQuery(query, context);
91
}
92
93
template<int K>
94
static __forceinline void intersectK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayHitK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node)
95
{
96
assert(false);
97
}
98
99
template<int K>
100
static __forceinline vbool<K> occludedK(const vbool<K>& valid, /* PrecalculationsK& pre, */ RayK<K>& ray, RayQueryContext* context, const Primitive* prim, size_t num, size_t& lazy_node)
101
{
102
assert(false);
103
return valid;
104
}
105
};
106
107
template<int K, bool mblur>
108
struct ObjectIntersectorK
109
{
110
typedef Object Primitive;
111
112
struct Precalculations {
113
__forceinline Precalculations (const vbool<K>& valid, const RayK<K>& ray) {}
114
};
115
116
static __forceinline void intersect(const vbool<K>& valid_i, const Precalculations& pre, RayHitK<K>& ray, RayQueryContext* context, const Primitive& prim)
117
{
118
vbool<K> valid = valid_i;
119
AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
120
121
/* perform ray mask test */
122
#if defined(EMBREE_RAY_MASK)
123
valid &= (ray.mask & accel->mask) != 0;
124
if (none(valid)) return;
125
#endif
126
accel->intersect(valid,ray,prim.geomID(),prim.primID(),context);
127
}
128
129
static __forceinline vbool<K> occluded(const vbool<K>& valid_i, const Precalculations& pre, RayK<K>& ray, RayQueryContext* context, const Primitive& prim)
130
{
131
vbool<K> valid = valid_i;
132
AccelSet* accel = (AccelSet*) context->scene->get(prim.geomID());
133
134
/* perform ray mask test */
135
#if defined(EMBREE_RAY_MASK)
136
valid &= (ray.mask & accel->mask) != 0;
137
if (none(valid)) return false;
138
#endif
139
accel->occluded(valid,ray,prim.geomID(),prim.primID(),context);
140
return ray.tfar < 0.0f;
141
}
142
143
static __forceinline void intersect(Precalculations& pre, RayHitK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) {
144
intersect(vbool<K>(1<<int(k)),pre,ray,context,prim);
145
}
146
147
static __forceinline bool occluded(Precalculations& pre, RayK<K>& ray, size_t k, RayQueryContext* context, const Primitive& prim) {
148
occluded(vbool<K>(1<<int(k)),pre,ray,context,prim);
149
return ray.tfar[k] < 0.0f;
150
}
151
};
152
153
typedef ObjectIntersectorK<4,false> ObjectIntersector4;
154
typedef ObjectIntersectorK<8,false> ObjectIntersector8;
155
typedef ObjectIntersectorK<16,false> ObjectIntersector16;
156
157
typedef ObjectIntersectorK<4,true> ObjectIntersector4MB;
158
typedef ObjectIntersectorK<8,true> ObjectIntersector8MB;
159
typedef ObjectIntersectorK<16,true> ObjectIntersector16MB;
160
}
161
}
162
163