Filter callback function that gathers first N hits up to the first opaque surface */
| 196 | |
| 197 | /* Filter callback function that gathers first N hits up to the first opaque surface */ |
| 198 | RTC_SYCL_INDIRECTLY_CALLABLE void gather_next_hits(const RTCFilterFunctionNArguments* args) |
| 199 | { |
| 200 | assert(*args->valid == -1); |
| 201 | RayQueryContext* context = (RayQueryContext*) args->context; |
| 202 | HitList& hits = context->hits; |
| 203 | RTCRay* ray = (RTCRay*) args->ray; |
| 204 | RTCHit* hit = (RTCHit*) args->hit; |
| 205 | assert(args->N == 1); |
| 206 | args->valid[0] = 0; // ignore all hits |
| 207 | |
| 208 | /* avoid overflow of hits array */ |
| 209 | if (hits.end >= MAX_TOTAL_HITS) return; |
| 210 | |
| 211 | /* check if geometry is opaque */ |
| 212 | ISPCGeometry* geometry = (ISPCGeometry*) args->geometryUserPtr; |
| 213 | bool opaque = !hits.data.enable_opacity || geometry->type != CURVES; |
| 214 | |
| 215 | HitList::Hit nhit(opaque, ray->tfar,hit->primID,hit->geomID,hit->instID[0]); |
| 216 | |
| 217 | /* ignore already found hits */ |
| 218 | if (hits.begin > 0 && nhit <= hits.hits[hits.begin-1]) |
| 219 | return; |
| 220 | |
| 221 | /* insert new hit at proper location */ |
| 222 | for (unsigned int i=hits.begin; i<hits.end; i++) |
| 223 | { |
| 224 | if (nhit < hits.hits[i]) { |
| 225 | std::swap(nhit,hits.hits[i]); |
| 226 | if (hits.hits[i].opaque) { |
| 227 | hits.end = i+1; |
| 228 | break; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | /* store farthest hit if place left and last is not opaque */ |
| 234 | if (hits.size() < context->max_next_hits && hits.end < hits.data.max_total_hits && !hits.last_is_opaque()) |
| 235 | hits.hits[hits.end++] = nhit; |
| 236 | |
| 237 | /* shrink tfar when we collected sufficient hits for this pass, or the last hit is opaque */ |
| 238 | if (hits.size() == context->max_next_hits || hits.last_is_opaque()) |
| 239 | { |
| 240 | ray->tfar = hits.last().t; |
| 241 | args->valid[0] = -1; // accept hit |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* gathers hits in multiple passes */ |
| 246 | void multi_pass(const TutorialData& data, const Ray& ray_i, HitList& hits_o, int max_next_hits, RandomSampler& sampler, RayStats& stats, const RTCFeatureFlags feature_mask) |
nothing calls this directly
no test coverage detected