Bug in buffer data from rtIntersectionDistance

Hello,

I found out that the distance information about a moving object in my scene isn’t written properly on the output buffer.I’ve given each object in the scene a geometry ID. The following shows how I write the ID and distance information to output buffers.

if(prd_radiance.depth == 0){
     Obj_ID_Buffer[launch_index] = Obj_ID;
     ray_direction_buffer[launch_index] = make_float4(ray.direction, t_hit);
}

However, when I try to find the minimum distance to a certain object from my host code, it always holds 5 to 6 distance informations (line 65-69) constantly in the buffer and I cannot find out why this happens. The following code shows my print to the console.

Min. Dist.: 24.4545 at 200627
Min. Dist.: 24.4515 at 200628
Min. Dist.: 24.4488 at 200629
Min. Dist.: 24.4463 at 200630
Min. Dist.: 24.444 at 200631
Min. Dist.: 24.442 at 200632
Min. Dist.: 24.4402 at 200633
Min. Dist.: 24.4386 at 200634
Min. Dist.: 24.4373 at 200635
Min. Dist.: 24.4362 at 200636
Min. Dist.: 24.4354 at 200637
Min. Dist.: 24.4348 at 200638
Min. Dist.: 24.4345 at 200639
Min. Dist.: 24.4343 at 200640
Min. Dist.: 24.4339 at 201277
Min. Dist.: 24.4333 at 201278
Min. Dist.: 24.4329 at 201279
Min. Dist.: 24.4328 at 201280
Min. Dist.: 24.4325 at 201917
Min. Dist.: 24.432 at 201918
Min. Dist.: 24.4316 at 201919
Min. Dist.: 24.4315 at 201920
Min. Dist.: 24.4309 at 202558
Min. Dist.: 24.4305 at 202559
Min. Dist.: 24.4304 at 202560
Min. Dist.: 24.43 at 203198
Min. Dist.: 24.4297 at 203199
Min. Dist.: 24.4296 at 203200
Min. Dist.: 24.4294 at 203838
Min. Dist.: 24.429 at 203840
Min. Dist.: 8.4817 at 204444
Min. Dist.: 8.48166 at 205084
Min. Dist.: 7.99284 at 214758
Min. Dist.: 7.49961 at 216041
Min. Dist.: 7.00577 at 217324
Min. Dist.: 24.952 at 200628
Min. Dist.: 24.9492 at 200629
Min. Dist.: 24.9466 at 200630
Min. Dist.: 24.9443 at 200631
Min. Dist.: 24.9422 at 200632
Min. Dist.: 24.9404 at 200633
Min. Dist.: 24.9388 at 200634
Min. Dist.: 24.9375 at 200635
Min. Dist.: 24.9364 at 200636
Min. Dist.: 24.9355 at 200637
Min. Dist.: 24.9349 at 200638
Min. Dist.: 24.9346 at 200639
Min. Dist.: 24.9345 at 200640
Min. Dist.: 24.934 at 201277
Min. Dist.: 24.9334 at 201278
Min. Dist.: 24.933 at 201279
Min. Dist.: 24.9329 at 201280
Min. Dist.: 24.9326 at 201917
Min. Dist.: 24.932 at 201918
Min. Dist.: 24.9317 at 201919
Min. Dist.: 24.9315 at 201920
Min. Dist.: 24.9309 at 202558
Min. Dist.: 24.9306 at 202559
Min. Dist.: 24.9304 at 202560
Min. Dist.: 24.9301 at 203198
Min. Dist.: 24.9297 at 203199
Min. Dist.: 24.9296 at 203200
Min. Dist.: 24.9295 at 203838
Min. Dist.: 24.929 at 203840
Min. Dist.: 8.4817 at 204444
Min. Dist.: 8.48166 at 205084
Min. Dist.: 7.99284 at 214758
Min. Dist.: 7.49961 at 216041
Min. Dist.: 7.00577 at 217324

Here’s my minimum detection:

m_IDs = static_cast<int*> (m_obj_id_buffer->map());
RTsize ID_hor, ID_ver;
m_obj_id_buffer->getSize(ID_hor, ID_ver);

m_ray_directions = static_cast<float4*> (m_ray_direction_buffer->map());
RTsize ray_hor, ray_ver;
m_ray_direction_buffer->getSize(ray_hor, ray_ver);

// Find minimum distance
for(size_t i=0; i < ID_hor * ID_hor; i++){
	if( m_IDs[i] == 2  && m_ray_directions[i].w < m_obj_min_dist ){
		m_obj_min_dist = m_ray_directions[i].w;
		m_obj_direction = make_float3(m_ray_directions[i]);
		std::cerr << "Min. Dist.: " << m_obj_min_dist << " at " << i << std::endl;
	}
}
	m_ray_direction_buffer->unmap();
	m_obj_id_buffer->unmap();

Wrong loop length in line 10? ID_hor * ID_ver.
Lines 6 and 7 must result in the same sizes which make them redundant.
Also try OptiX 4.0.1, it contains some fixes.

Good call, Detlef.

You could also use a device buffer and CUDA kernel for the reduction rather than reading back the entire image to the host. Depends on how much time you’re spending reducing vs. tracing.