Vulkan Ray Tracing Invisible Objects by Distance

Hi everyone.

I don’t know whether is the good place for this topic but anyway.

Having this tutorial code: VK RT Intersection Tutorial
which has an implicit procedural geometry (AABB) hit group, I tried to make invisible those geometries by ignoring intersections checking the distance from camera to the geometry as follows:

bool isTooFar(const Aabb aabb, const Ray r) 
{
  // distance > maxDistance?
  float distanceMin = sqrt(pow(aabb.minimum.x - r.origin.x, 2) + pow(aabb.minimum.y - r.origin.y, 2) + pow(aabb.minimum.z - r.origin.z, 2));
  float distanceMax = sqrt(pow(aabb.minimum.x - r.origin.x, 2) + pow(aabb.minimum.y - r.origin.y, 2) + pow(aabb.minimum.z - r.origin.z, 2));
  if(distanceMin > pcRay.maxDistance && distanceMax > pcRay.maxDistance)
    return true;
  else
    return false;
}

If box geometry is too far I don’t report intersection at all:


// AABB intersection
  Aabb aabb;
  aabb.minimum = voxel.center - vec3(voxel.side);
  aabb.maximum = voxel.center + vec3(voxel.side);
 if(!isTooFar(aabb, ray)) {
      hitKind = 1;
      tHit         = hitAabb(aabb, ray);
  }
// Report hit point
  if(hitKind > 0)
      reportIntersectionEXT(tHit, hitKind);

The result is this:

Why do the shadows keep getting cast? Am I having a bad approach? Should I use a any-hit (transparency) shader?

Thank you!

The forum only let me post one file at a time so… picture closer:

Thanks again.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.