 # Some question about "Volume rendering" with ray casting about ray intersection

During the SDK, there is a sample about volume rendering using ray casting. And i come across a question about ray intersection with the bounding box. The origin source code is,

``````float tnear, tfar;

int hit = intersectBox(eyeRay, boxMin, boxMax, &tnear, &tfar);

if (!hit) return;

if (tnear < 0.0f) tnear = 0.0f;   // clamp to near plane
``````

i don’t why tnear can’t less than zero.

Thank you very much.

During the SDK, there is a sample about volume rendering using ray casting. And i come across a question about ray intersection with the bounding box. The origin source code is,

``````float tnear, tfar;

int hit = intersectBox(eyeRay, boxMin, boxMax, &tnear, &tfar);

if (!hit) return;

if (tnear < 0.0f) tnear = 0.0f;   // clamp to near plane
``````

i don’t why tnear can’t less than zero.

Thank you very much.

I guess (tnear == 0) corresponds to 3D positions where are beginning the rays (i.e. exactly on the point of view). Every negative values are so behind the point of view (you can not see them).
Generally you even clamp further than 0.

I guess (tnear == 0) corresponds to 3D positions where are beginning the rays (i.e. exactly on the point of view). Every negative values are so behind the point of view (you can not see them).
Generally you even clamp further than 0.

yes. it is the beginning of the ray. but, for each volume data, there is a bounding box, whose size is [-1,-1,-1] to [1, 1, 1]. So, each ray must to test to intersect the bounding box. and, we can get tnear and tfar, so i don’t think tnear must be larger or equal to zero. so, there is a problem.

yes. it is the beginning of the ray. but, for each volume data, there is a bounding box, whose size is [-1,-1,-1] to [1, 1, 1]. So, each ray must to test to intersect the bounding box. and, we can get tnear and tfar, so i don’t think tnear must be larger or equal to zero. so, there is a problem.

and i find that, if you delete this row code. it is ok. it can work as before. so, i need to know why.

and i find that, if you delete this row code. it is ok. it can work as before. so, i need to know why.

That code handles the case when the eye is inside the volume.

That code handles the case when the eye is inside the volume.

If it is really an intersection between a ray and the box that is performed, then tnear should never be < 0.
If the intersection is in fact an intersection between a LINE and the box, then checking if tnear < 0 corresponds to the RAY vs BOX intersection, it is the way not to consider what is before the beginning of the ray on the line (i.e. behind the screen).

Have you checked if tnear is < 0 when the point of view is inside the volume? If yes you need the test, if not, you do not need it.

–pium

If it is really an intersection between a ray and the box that is performed, then tnear should never be < 0.
If the intersection is in fact an intersection between a LINE and the box, then checking if tnear < 0 corresponds to the RAY vs BOX intersection, it is the way not to consider what is before the beginning of the ray on the line (i.e. behind the screen).

Have you checked if tnear is < 0 when the point of view is inside the volume? If yes you need the test, if not, you do not need it.

–pium