【问题标题】:Improving speed with Ray-cast in UE4在 UE4 中使用 Ray-cast 提高速度
【发布时间】:2019-11-19 09:23:44
【问题描述】:

我目前正在使用 Ray-cast 开发激光雷达传感器模型。以 10Hz 旋转的 16 通道传感器应产生 300000 个点。我可以使用 300000 次 Ray-cast 操作来获得这个结果,但性能非常弱(当传感器运动时帧速率下降到 8)。我可以使用其他更好的方法或算法吗?

要求:

  • 360 度扫描:水平
  • -25 到 15 度:垂直
  • 300000 次扫描

这是我正在使用的:

for (auto i = 0u; i < 3125; ++i){
  for (auto Channel = 0u; Channel < 16; ++Channel){
    FVector Point(0,0,0);
    float DistanceToHitPoint = 0;
    uint8_t Row = 0;
    uint8_t Class = 0u;
    double Intensity = 0;
    float Aoi = 0;
    const float Angle =  std::fmod(CurrentHorizontalAngle + AngleDistanceOfLaserMeasure * i,  360.0f);
    auto timestamp = static_cast<uint32_t>(GetEpisode().GetElapsedGameTime()* pow(10,6));
    ShootLaser(Channel, Angle, Point, DistanceToHitPoint, Row, Aoi, Class);
    if(Description.EnergyEffect && (DistanceToHitPoint != 0)){
        bool isQualified = IsPointIntensityValid(DistanceToHitPoint, Aoi, "test", Row, Intensity);
        LidarMeasurement.WritePoint(Channel, Point, Intensity, Class);
        LidarServer.fill_block(Angle, DistanceToHitPoint, Row, Description.ReturnMode, timestamp);
        continue;
    }
    LidarMeasurement.WritePoint(Channel, Point, Intensity, Class);
    LidarServer.fill_block(Angle, DistanceToHitPoint, Row, Description.ReturnMode, timestamp);

  }
}
const float HorizontalAngle = std::fmod(CurrentHorizontalAngle + AngleDistanceOfTick, 360.0f);
LidarMeasurement.SetHorizontalAngle(HorizontalAngle);

使用上述代码每秒进行 1500000 次 Raycast 操作。我试图在 0.033 秒(30fps)内运行循环。但是,运行此代码后,模拟 fps 变为 2 或 3 fps。有没有其他方法可以更有效地使用 Raycast。

【问题讨论】:

    标签: unreal-engine4 raycasting


    【解决方案1】:

    要模拟激光雷达,您可以使用 SceneCaptureComponent2D 的深度缓冲区。

    1. 使用格式创建渲染目标纹理:RTF R16f
    2. 创建SceneCaptureComponent2D,分配目标纹理,设置CaptureSource -> R中的SceneDepth
    3. 使用 TextureObjectParameter 创建材质,采样并除以 cm_lidar_distance 值
    4. 创建DynamicMaterialInstance,设置TextureParameterValue为目标纹理
    5. 现在您已将场景深度渲染为纹理,可以将其复制到主内存以进行其他处理。

    查看屏幕截图和示例项目: https://drive.google.com/open?id=1TImwJXmk5syvcPdPCylKXaaSCP99UI-m

    【讨论】:

    • 同时查看CARLA项目(由ue4驱动的开源车辆模拟):carla.readthedocs.io/en/latest/cameras_and_sensors/…
    • 我正在尝试将物理效应添加到 CARLA 中的激光雷达传感器
    • 非常感谢您的建议。但我也想知道是否可以仅使用 raycast 采样接近一百万个点。
    • 软件光线投射是死路一条,恕我直言。但无论如何,请检查 SceneQueryLowLevel.cpp LowLevelRaycast 和 PxBatchQuery。
    猜你喜欢
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多