MCPcopy Create free account
hub / github.com/RenderKit/embree / sphereOccludedFunc

Function sphereOccludedFunc

tutorials/user_geometry/user_geometry_device.cpp:377–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375}
376
377RTC_SYCL_INDIRECTLY_CALLABLE void sphereOccludedFunc(const RTCOccludedFunctionNArguments* args)
378{
379 int* valid = args->valid;
380 void* ptr = args->geometryUserPtr;
381 Ray *ray = (Ray*)args->ray;
382 unsigned int primID = args->primID;
383
384 assert(args->N == 1);
385 const Sphere* spheres = (const Sphere*) ptr;
386 const Sphere& sphere = spheres[primID];
387
388 if (!valid[0]) return;
389 valid[0] = 0;
390
391 const Vec3fa v = ray->org-sphere.p;
392 const float A = dot(ray->dir,ray->dir);
393 const float B = 2.0f*dot(v,ray->dir);
394 const float C = dot(v,v) - sqr(sphere.r);
395 const float D = B*B - 4.0f*A*C;
396 if (D < 0.0f) return;
397 const float Q = sqrt(D);
398 const float rcpA = rcp(A);
399 const float t0 = 0.5f*rcpA*(-B-Q);
400 const float t1 = 0.5f*rcpA*(-B+Q);
401
402 RTCHit potentialHit;
403 potentialHit.u = 0.0f;
404 potentialHit.v = 0.0f;
405 copyInstanceIdStack(args->context, potentialHit.instID);
406 potentialHit.geomID = sphere.geomID;
407 potentialHit.primID = primID;
408 if ((ray->tnear() < t0) & (t0 < ray->tfar))
409 {
410 int imask;
411 bool mask = 1;
412 {
413 imask = mask ? -1 : 0;
414 }
415
416 const Vec3fa Ng = ray->org+t0*ray->dir-sphere.p;
417 potentialHit.Ng_x = Ng.x;
418 potentialHit.Ng_y = Ng.y;
419 potentialHit.Ng_z = Ng.z;
420
421 RTCFilterFunctionNArguments fargs;
422 fargs.valid = (int*)&imask;
423 fargs.geometryUserPtr = ptr;
424 fargs.context = args->context;
425 fargs.ray = args->ray;
426 fargs.hit = (RTCHitN*)&potentialHit;
427 fargs.N = 1;
428
429 const float old_t = ray->tfar;
430 ray->tfar = t0;
431#if USE_ARGUMENT_CALLBACKS
432 contextFilterFunction(&fargs);
433#else
434 rtcInvokeOccludedFilterFromGeometry(args,&fargs);

Callers 1

contextOccludedFuncFunction · 0.85

Calls 8

copyInstanceIdStackFunction · 0.85
tnearMethod · 0.80
contextFilterFunctionFunction · 0.70
dotFunction · 0.50
sqrFunction · 0.50
sqrtFunction · 0.50
rcpFunction · 0.50

Tested by

no test coverage detected