Question about CloseHit Point Location

I’am trying to use Optix 5.1, and I set the fov to 30 and the max trace time to one to to simulate Lidar behavior,however there are some points that shouldn’t be in the final output.

Here is my Ray Generation program

RT_PROGRAM void pinhole_camera()
{

  size_t2 screen = output_buffer.size();
  unsigned int seed = tea<16>(screen.x*launch_index.y+launch_index.x, frame);


  float2 d = (make_float2(launch_index)) / make_float2(screen) * 2.f - 1.f;
  float3 ray_origin = eye;
  float3 ray_direction = normalize(d.x*U + d.y*V + W);

  PerRayData_radiance prd;
  prd.depth = 0;
  prd.seed = seed;
  prd.done = false;
  prd.pdf = 0.0f;
  prd.specularBounce = false;

  // These represent the current shading state and will be set by the closest-hit or miss program

  // attenuation (<= 1) from surface interaction.
  prd.throughput = make_float3( 1.0f );

  // light from a light source or miss program
  prd.radiance = make_float3( 0.0f );

  // next ray to be traced
  prd.origin = make_float3( 0.0f );
  prd.direction = make_float3( 0.0f );

  float3 result = make_float3( 0.0f );

  // Main render loop. This is not recursive, and for high ray depths
  // will generally perform better than tracing radiance rays recursively
  // in closest hit programs.
  for(;;) {
      optix::Ray ray(ray_origin, ray_direction, /*ray type*/ 0, scene_epsilon );
      rtTrace(top_object, ray, prd);

      if ( prd.done || prd.depth >= max_depth)
          break;

      prd.depth++;

      // Update ray data for the next path segment
      ray_origin = prd.origin;
      ray_direction = prd.direction;
  }

  result = prd.radiance;

  float4 acc_val = accum_buffer[launch_index];
  if( frame > 0 ) {
    acc_val = lerp( acc_val, make_float4( result, 0.f ), 1.0f / static_cast<float>( frame+1 ) );
  } else {
    acc_val = make_float4( result, 0.f );
  }

  float4 val = LinearToSrgb(ToneMap(acc_val, 1.5));
  //float4 val = LinearToSrgb(acc_val);

  output_buffer[launch_index] = make_color(make_float3(val));
  accum_buffer[launch_index] = acc_val;

Here is what I see in the Optix

And there is the point cloud output

Thanks a lot.

Please always provide the following system configuration information when asking about OptiX issues:
OS version, installed GPU(s), VRAM amount, display driver version, OptiX major.minor.micro version, CUDA toolkit version used to generate the input PTX, host compiler version.

It’s not quite clear what either image visualizes exactly.
A fully refined image with more than a single sample per pixel might help.
It doesn’t look like the second image uses the same model and view.

The path tracing ray generation program you cite is using a scene size dependent scene_epsilon value to offset the t_min interval start value of the ray for a simple self intersection avoidance.
Could it be that the value is too small and the pixels you visualized inside the second image are from that?

If you mean with setting “the max trace time to one” that you set the variable “max_depth == 1” and only wanted primary rays, then you’re shooting one ray segment too many.
You start at prd.depth == 0, unconditionally shoot a ray, break when prd.depth >= max_depth which is false, then increment prd.depth and shoot another ray, and only then break.
If you only need the primary rays, no such loop construct would be required. Example:
https://github.com/nvpro-samples/optix_advanced_samples/blob/master/src/optixIntroduction/optixIntro_03/shaders/raygeneration.cu#L53

Also the provided triangle intersection function inside the OptiX 5 example code is not watertight.
Means rays could pass through the edge between two adjacent triangles in some cases.
This is not the case with the built-in triangle primitives in OptiX 6 and higher, which are using a watertight implementation and also run in hardware on RTX boards.

Your variables ray_origin and ray_direction are redundant. You can use prd.origin and prd.direction directly for that. (Move line 12 up, change assignments in lines 9 and 10, remove lines 44 to 47 from the loop.)

Why are you using OptiX 5.1.x?
There are three newer versions available: 6.0.0, 6.5.0, 7.0.0, all with better RTX support.
While OptiX 7.0.0 uses a completely different explicit API, it is faster and more flexible than any earlier OptiX version. If this is for a new project, it’s highly recommended to start with OptiX 7.0.0.