问题
I am currently developing a lidar sensor model using Ray-cast. A 16 channel sensor rotating at 10Hz should produce 300000 points. I can use 300000 Ray-cast operations to get this result but the performance is very weak (frame rate falls to 8 when motion is given to the sensor). Is there any other better way or algorithms I can use?
Requirement :
- To scan 360 degrees: Horizontal
- -25 to 15 degrees: Vertical
- 300000 scans
Here is what I'm using:
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);
For 1500000 Raycast operation per second above code is used. I am trying to run the loops within 0.033 seconds(30fps). However, simulation fps turns out to be 2 or 3 fps after running this code. Is there any alternative to use Raycast more efficiently.
回答1:
To simulate lidar you can use depth buffer of SceneCaptureComponent2D.
- Create render target texture with format: RTF R16f
- Create SceneCaptureComponent2D, assign target texture, set CaptureSource -> SceneDepth in R
- Create Material with TextureObjectParameter, sample and divide by max_lidar_distance value in cm
- Create DynamicMaterialInstance, set TextureParameterValue to target texture
- Now you have scene depth rendered to texture, can be copied to main memory for other processing.
Check screenshots and example project: https://drive.google.com/open?id=1TImwJXmk5syvcPdPCylKXaaSCP99UI-m
来源:https://stackoverflow.com/questions/58930543/improving-speed-with-ray-cast-in-ue4