refracted ray and closest hit

I generated a ray that towards a box object and refracted the ray at the point where closest_hit occured.
the refracted ray would hit inside of the box object and i want to get the position where the refracted ray hit.
in this case, should i use any hit program or closest hit?? how can i get the data

RT_PROGRAM void closest_hit_radiance()
{
// prd_radiance.result = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal))*0.5f + 0.5f;
float3 world_geo_normal = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, geometric_normal));
float3 world_shade_normal = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal));
float3 ffnormal = faceforward(world_shade_normal, -ray.direction, world_geo_normal);

float3 hit_point = ray.origin + t_hit * ray.direction;

PerRayData_beam data;
//data.importance = prd_beam.importance * refracted;
data.depth = prd_beam.depth + 1;
if (data.depth < max_depth) {
	float3 R;
	if (refract(R, normalize(ray.direction), ffnormal, index)) {		
		Ray refraction(hit_point, R, BEAM_RAY_TYPE, scene_epsilon);
		rtTrace(top_object, refraction, data);

		//result = (opacity * result) + (refracted * data.result);
	}
}

}
after I rtTrace the refracted ray what should i do?
please give me some ideas. thank you.

Use a closest hit program to get the next closest intersection along a ray.

Let’s assume the example already has defined two ray types like
#define RADIANCE_RAY_TYPE 0
#define SHADOW_RAY_TYPE 1
and your BEAM_RAY_TYPE should behave differently, you can do two things:

  • Define a third ray type
    #define BEAM_RAY_TYPE 2
    and write an RT_PROGRAM void closest_hit_beam() which handles the closest hit of that by storing data into that beam ray’s variable with rtPayload semantic, and assign that to the proper raytype at the material, just like the closest_hit_radiance.

  • Or if that beam ray only behaves a little differently than the radiance ray, you can reuse the code by setting a flag inside the radiance ray’s rtPayload structure which indicates that this is a beam ray and not a radiance ray and special case the handling in the existing closest_hit_radiance() program.

In either case, after the rtTrace() returned, the values you have written last to the ray’s rtPayload variable in the invoked program will be inside your per ray data structure, in “data” in your code excerpt.

If you’re new to OptiX, please have a look at the OptiX Introduction presentation video and open source examples.
[url]https://devtalk.nvidia.com/default/topic/998546/optix/optix-advanced-samples-on-github/[/url]