At the moment, I am working on volume rendering with Optix, usually the volume data is stored in a cubic grid, so I need to get the two points intersected with the ray. However, the optix usually provide us with the closest point rather than two points, is there any method to get the points,and then sample the space between them. The following is a intersection program for a box.
RT_PROGRAM void box_intersect(int)
{
float3 t0 = (boxmin - ray.origin)/ray.direction;
float3 t1 = (boxmax - ray.origin)/ray.direction;
float3 near = fminf(t0, t1);
float3 far = fmaxf(t0, t1);
float tmin = fmaxf( near );
float tmax = fminf( far );
if(tmin <= tmax)
{
bool check_second = true;
if( rtPotentialIntersection( tmin ) )
{
texcoord = make_float3( 0.0f );
shading_normal = geometric_normal = boxnormal( tmin );
if(rtReportIntersection(0))
check_second = false;
}
if(check_second)
{
if( rtPotentialIntersection( tmax ) )
{
texcoord = make_float3( 0.0f );
shading_normal = geometric_normal = boxnormal( tmax );
rtReportIntersection(0);
}
}
}
}
As we can see, the “rtPotentialIntersection” is called twice, the first time is for the near point, and the second is for the far point. So the closest hit program attached with the box will be called twice, but for volume rendering, the closest hit program should be called once, at the same time, the two points should be fetched. Is it possible to get the two points from intersection program or closest hit program? I have no idea how to deal with it. Is there anyone have any idea? Thank you very much for your help.