【问题标题】:Reducing time complexity for C++ on Unreal Engine 4.22在 Unreal Engine 4.22 上降低 C++ 的时间复杂度
【发布时间】:2020-02-08 17:29:56
【问题描述】:

我正在使用 Ray-trace 进行模拟开发激光雷达传感器。模拟可配置为以每秒所需的帧数运行(在我的情况下为 30 fps。即 1 帧在 33.34 毫秒内运行)。

目前每秒进行 300000 次光线追踪(包括水平和垂直)。在 30 fps 时,每帧进行 10000 次光线追踪。代码如下所示

//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;

}

以上代码运行良好。一切都在 33.33 毫秒的预期时间内完成。现在需要引入效果散度https://en.wikipedia.org/wiki/Beam_divergence

使用的解决方案:每个点取 8 个样本。即嵌套 for 循环内还有 8 个光线跟踪。总共(8+1)*300000 光线追踪。该解决方案占用了大量时间,并且不可能在 33 毫秒内完成。任何人都可以建议任何其他替代方案来构建代码/算法的体系结构/一种不同的方法,我可以用它来实现这一点,并且计算复杂度更低。

附加信息:

虚幻引擎 4.22,在 GPU 上运行

【问题讨论】:

  • 这个算法已经在 GPU 上运行了吗?
  • 是的,这已经在 GPU 上运行了

标签: c++ algorithm optimization time-complexity


【解决方案1】:

我对您使用的引擎或您尝试实现的效果一无所知,但我知道有 2 种主要方法可以加速光线追踪器(除了明显的并行化和 GPU):

  1. 使用旧框架/光线而不是投射更多光线

    这通常用于过度发光、反射、运动模糊和类似的效果...所以只需使用来自最后一帧或多帧的光线而不是在稍微不同的方向上投射更多光线...但是这需要额外的缓冲区来存储需要最后一帧数据。如果您需要的不仅仅是生成的颜色,它可能会占用大量 RAM,尤其是对于光线追踪器而言。

  2. 使用随机而不是分裂光线

    这是非常常见的方法。你知道当光线照射到一个表面时,它应该分裂成反射和折射光线。随机光线追踪不会分裂。相反,取决于伪随机值,它以 50/50 的机会反射或折射。正如你所看到的,在没有分裂的情况下,为场景投射的光线要少得多。另一方面,这会产生明显的噪声(类似于低光照条件下的旧 CCD 相机图像)。可以通过将最后几帧一起平均来部分抑制它(或每帧对同一场景进行多次光线追踪)...

    这样做的另一个优点是它不需要在 GLSL 中未实现的递归,因此您可以更轻松地在 GLSL 中进行光线追踪。没有它,您需要将递归转换为迭代,这并不简单,请参阅:

【讨论】:

    猜你喜欢
    • 2011-06-15
    • 2012-07-28
    • 2016-10-07
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 1970-01-01
    相关资源
    最近更新 更多