     }
 
     t += dist;
-    if (t > tfar)
+    if (t > tbfar)
     {
       break;
     }

    return;
  }

  if (fmodf(tnear, dist) != 0.0f)
  {
    int tmp = (tnear / dist);
    tnear = dist * tmp;
  }

  if (tnear < 0.0f)
  {
    tnear = 0.0f;
  }

  // Calc hits with clip sphere.

  const float4 o = mulPost(c_invViewMatrix, make_float4(u, v, -1.0f, 1.0f));
  const float4 d = mulPost(c_invViewMatrix, make_float4(u, v, 1.0f, 1.0f));

  // Dist to far-clipping plane from opengl.
  const float tfar = norm(perspectiveDivide(d) - perspectiveDivide(o));

  Ray ray;
  ray.o = perspectiveDivide(o);
  ray.d = perspectiveDivide(d);
  ray.d = ray.d - ray.o;
  ray.d = normalize(ray.d);

  float tbnear = 0.0f;
  float tbfar = 0.0f;
  const bool hit = intersectBox(ray, probePos - probeSizeHalf, probePos + probeSizeHalf, &tbnear, &tbfar);
  if (!hit)
  {
    d_output[y * texwidth + x] = make_uchar4(0);
