0

I am developing a Lidar sensor on a simulation using Ray-trace. simulation is configurable to run at desired frame per second (in my case 30 fps. i.e 1 frame runs in 33.34ms).

Currently 300000 ray-tracing are done per second (including horizontal and vertical). at 30 fps, 10000 ray-tracing is done per frame. The code looks like below

//call back at the start of frame (just for understanding - not the actual code, data type conversions and some other basics are ignored)
uint32 channels = 16;
float vert_angle[] = {15, 13, 11, 9, 7, 5, 3, 1, -1, -3, -5, -7, -9, -11, -13, -15};
float hor_angle_ref = 0;
uint32 points_per_second = 300000;
float rotation_frequency = 10;

/* 300000 points per second is divided into points per frame. 
These points are distributed horizontally and vertically*/
void callback_scan(){
    uint32 poits_to_scan_with_one_laser = points_per_second/ (fps * channels);
    auto hor_angle_covered_this_frame = points_per_second* rotation_frequency * (1/fps);
    auto hor_angle_resolution = hor_angle_covered_this_frame / poits_to_scan_with_one_laser ;
    auto hor_angle = hor_angle_ref ;

    for(auto i= 0u; i< poits_to_scan_with_one_laser ; ++i){
       for(auto ch= 0u; ch< channels; ++ch){
          auto hitPoint = raytrace(hor_angle, vert_angle[ch]);
          // process_data(); -> distance, time and energy are calculated
          /* distance -> Euclidean distance calculation and addition of noise
             time -> c=d/t
             energy -> Pr = Pt*pow(D,2)*nsys*natm*row/ pow(dist,2);*/
       }
       hor_angle += hor_angle_resolution ;
    }
    hor_angle_ref = hor_angle;

}

Above piece of code runs pretty good. Everything completes within expected time of 33.33ms. Now it is required to introduce effect divergence https://en.wikipedia.org/wiki/Beam_divergence.

Solution used: 8 samples are taken for each point. i.e 8 more ray-tracing inside the nested for loops. In total (8+1)*300000 ray-trace. This solution is eating up a lot of time and not possible to complete within 33ms. Could any one suggest any other alternative on structuring the architecture of the code/ algorithm / a different approach that I can use to implement this with less computational complexity.

Additional info:

Unreal Engine 4.22, Running on a GPU

Skanda
  • 145
  • 4
  • 14

1 Answers1

1

I have no bacground knowledge about the engine you use nor effect you try to implement but there are 2 main approaches to speed up ray tracers I know of (apart obvious parallelization and GPU):

  1. use old frame/rays instead of casting more rays

    this is commonly used for overglow, reflection, motion blur and similar effects... so simply instead of casting more rays in slightly different directions use rays from last one or more frames... This however needs additional buffers to store the last frame data needed. It can be quite a large bit of RAM especially for raytracers if you need more than just resulting color.

  2. use stochastics instead of spliting rays

    this is very common approach. You know when ray hits a surface it should split into reflection and refraction rays. The stochastic raytracing does not split. instead depending on a pseudorandom value it either reflect or refract with 50/50 chance. As you can see without splitting there is a lot less rays to cast for scene. On the other hand this produces a distinct noise (similar to old CCD camera image in low light conditions). It can be partially suppressed by averaging few last frames together (or ray trace the same scene more times per one frame) ...

    Another advantage of this is that it does not require recursion which is not implemented in GLSL so you can do ray tracing in GLSL much easier. Without it you would need to convert the recursion into iteration which is not simple see:

Spektre
  • 49,595
  • 11
  • 110
  • 380