1// Copyright 2009-2021 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "../common/geometry.h"
7#include "../common/ray.h"
8#include "../common/hit.h"
9#include "../common/context.h"
10
11namespace embree
12{
13 namespace isa
14 {
15 __forceinline bool runIntersectionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context)
16 {
17 if (geometry->intersectionFilterN)
18 {
19 assert(context->scene->hasGeometryFilterFunction());
20 geometry->intersectionFilterN(args);
21
22 if (args->valid[0] == 0)
23 return false;
24 }
25
26 if (context->user->filter) {
27 assert(context->scene->hasContextFilterFunction());
28 context->user->filter(args);
29
30 if (args->valid[0] == 0)
31 return false;
32 }
33
34 copyHitToRay(ray&: *(RayHit*)args->ray,hit: *(Hit*)args->hit);
35 return true;
36 }
37
38 __forceinline bool runIntersectionFilter1(const Geometry* const geometry, RayHit& ray, IntersectContext* context, Hit& hit)
39 {
40 RTCFilterFunctionNArguments args;
41 int mask = -1;
42 args.valid = &mask;
43 args.geometryUserPtr = geometry->userPtr;
44 args.context = context->user;
45 args.ray = (RTCRayN*)&ray;
46 args.hit = (RTCHitN*)&hit;
47 args.N = 1;
48 return runIntersectionFilter1Helper(args: &args,geometry,context);
49 }
50
51 __forceinline void reportIntersection1(IntersectFunctionNArguments* args, const RTCFilterFunctionNArguments* filter_args)
52 {
53#if defined(EMBREE_FILTER_FUNCTION)
54 IntersectContext* MAYBE_UNUSED context = args->internal_context;
55 const Geometry* const geometry = args->geometry;
56 if (geometry->intersectionFilterN) {
57 assert(context->scene->hasGeometryFilterFunction());
58 geometry->intersectionFilterN(filter_args);
59 }
60
61 //if (args->valid[0] == 0)
62 // return;
63
64 if (context->user->filter) {
65 assert(context->scene->hasContextFilterFunction());
66 context->user->filter(filter_args);
67 }
68#endif
69 }
70
71 __forceinline bool runOcclusionFilter1Helper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context)
72 {
73 if (geometry->occlusionFilterN)
74 {
75 assert(context->scene->hasGeometryFilterFunction());
76 geometry->occlusionFilterN(args);
77
78 if (args->valid[0] == 0)
79 return false;
80 }
81
82 if (context->user->filter) {
83 assert(context->scene->hasContextFilterFunction());
84 context->user->filter(args);
85
86 if (args->valid[0] == 0)
87 return false;
88 }
89 return true;
90 }
91
92 __forceinline bool runOcclusionFilter1(const Geometry* const geometry, Ray& ray, IntersectContext* context, Hit& hit)
93 {
94 RTCFilterFunctionNArguments args;
95 int mask = -1;
96 args.valid = &mask;
97 args.geometryUserPtr = geometry->userPtr;
98 args.context = context->user;
99 args.ray = (RTCRayN*)&ray;
100 args.hit = (RTCHitN*)&hit;
101 args.N = 1;
102 return runOcclusionFilter1Helper(args: &args,geometry,context);
103 }
104
105 __forceinline void reportOcclusion1(OccludedFunctionNArguments* args, const RTCFilterFunctionNArguments* filter_args)
106 {
107#if defined(EMBREE_FILTER_FUNCTION)
108 IntersectContext* MAYBE_UNUSED context = args->internal_context;
109 const Geometry* const geometry = args->geometry;
110 if (geometry->occlusionFilterN) {
111 assert(context->scene->hasGeometryFilterFunction());
112 geometry->occlusionFilterN(filter_args);
113 }
114
115 //if (args->valid[0] == 0)
116 // return false;
117
118 if (context->user->filter) {
119 assert(context->scene->hasContextFilterFunction());
120 context->user->filter(filter_args);
121 }
122#endif
123 }
124
125 template<int K>
126 __forceinline vbool<K> runIntersectionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context)
127 {
128 vint<K>* mask = (vint<K>*) args->valid;
129 if (geometry->intersectionFilterN)
130 {
131 assert(context->scene->hasGeometryFilterFunction());
132 geometry->intersectionFilterN(args);
133 }
134
135 vbool<K> valid_o = *mask != vint<K>(zero);
136 if (none(valid_o)) return valid_o;
137
138 if (context->user->filter) {
139 assert(context->scene->hasContextFilterFunction());
140 context->user->filter(args);
141 }
142
143 valid_o = *mask != vint<K>(zero);
144 if (none(valid_o)) return valid_o;
145
146 copyHitToRay(valid_o,*(RayHitK<K>*)args->ray,*(HitK<K>*)args->hit);
147 return valid_o;
148 }
149
150 template<int K>
151 __forceinline vbool<K> runIntersectionFilter(const vbool<K>& valid, const Geometry* const geometry, RayHitK<K>& ray, IntersectContext* context, HitK<K>& hit)
152 {
153 RTCFilterFunctionNArguments args;
154 vint<K> mask = valid.mask32();
155 args.valid = (int*)&mask;
156 args.geometryUserPtr = geometry->userPtr;
157 args.context = context->user;
158 args.ray = (RTCRayN*)&ray;
159 args.hit = (RTCHitN*)&hit;
160 args.N = K;
161 return runIntersectionFilterHelper<K>(&args,geometry,context);
162 }
163
164 template<int K>
165 __forceinline vbool<K> runOcclusionFilterHelper(RTCFilterFunctionNArguments* args, const Geometry* const geometry, IntersectContext* context)
166 {
167 vint<K>* mask = (vint<K>*) args->valid;
168 if (geometry->occlusionFilterN)
169 {
170 assert(context->scene->hasGeometryFilterFunction());
171 geometry->occlusionFilterN(args);
172 }
173
174 vbool<K> valid_o = *mask != vint<K>(zero);
175
176 if (none(valid_o)) return valid_o;
177
178 if (context->user->filter) {
179 assert(context->scene->hasContextFilterFunction());
180 context->user->filter(args);
181 }
182
183 valid_o = *mask != vint<K>(zero);
184
185 RayK<K>* ray = (RayK<K>*) args->ray;
186 ray->tfar = select(valid_o, vfloat<K>(neg_inf), ray->tfar);
187 return valid_o;
188 }
189
190 template<int K>
191 __forceinline vbool<K> runOcclusionFilter(const vbool<K>& valid, const Geometry* const geometry, RayK<K>& ray, IntersectContext* context, HitK<K>& hit)
192 {
193 RTCFilterFunctionNArguments args;
194 vint<K> mask = valid.mask32();
195 args.valid = (int*)&mask;
196 args.geometryUserPtr = geometry->userPtr;
197 args.context = context->user;
198 args.ray = (RTCRayN*)&ray;
199 args.hit = (RTCHitN*)&hit;
200 args.N = K;
201 return runOcclusionFilterHelper<K>(&args,geometry,context);
202 }
203 }
204}
205

source code of qtquick3d/src/3rdparty/embree/kernels/geometry/filter.h