From fa0c554f598b2783503711357322eabb929b8b47 Mon Sep 17 00:00:00 2001 From: nznaza Date: Sat, 6 Nov 2021 06:04:30 -0600 Subject: [PATCH 1/3] Sets bCapture* true only while showing subwindow Sets bAlwaysPersistRenderingState to true. This fixes bugs of capture Sets bCaptureOnMovement and bCaptureEveryFrame to true only when they are going to be viewed on as subwindow --- .../Plugins/AirSim/Source/CameraDirector.cpp | 23 +++++++---------- Unreal/Plugins/AirSim/Source/PIPCamera.cpp | 25 ++++++++++++------- Unreal/Plugins/AirSim/Source/PIPCamera.h | 3 +++ .../Plugins/AirSim/Source/SimHUD/SimHUD.cpp | 4 ++- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp index cee6965358..a4abceef4d 100644 --- a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp +++ b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp @@ -344,21 +344,16 @@ void ACameraDirector::notifyViewModeChanged() { bool nodisplay = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY == mode_; - if (fpv_camera_) - fpv_camera_->onViewModeChanged(nodisplay); - if (backup_camera_) - backup_camera_->onViewModeChanged(nodisplay); - if (ExternalCamera) - ExternalCamera->onViewModeChanged(nodisplay); - if (front_camera_) - front_camera_->onViewModeChanged(nodisplay); + //if (fpv_camera_) + // fpv_camera_->onViewModeChanged(nodisplay); + //if (backup_camera_) + // backup_camera_->onViewModeChanged(nodisplay); + //if (ExternalCamera) + // ExternalCamera->onViewModeChanged(nodisplay); + //if (front_camera_) + // front_camera_->onViewModeChanged(nodisplay); UWorld* world = GetWorld(); UGameViewportClient* gameViewport = world->GetGameViewport(); - if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY) { - gameViewport->bDisableWorldRendering = 1; - } - else { - gameViewport->bDisableWorldRendering = 0; - } + gameViewport->bDisableWorldRendering = (uint32)mode_; } diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index 05cbdcf25b..7a0243ca00 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -98,7 +98,7 @@ void APIPCamera::BeginPlay() render_targets_[image_type] = NewObject(); } - onViewModeChanged(false); + onViewModeChanged(true); gimbal_stabilization_ = 0; gimbald_rotator_ = this->GetActorRotation(); @@ -270,6 +270,20 @@ void APIPCamera::setCameraTypeEnabled(ImageType type, bool enabled) enableCaptureComponent(type, enabled); } +void APIPCamera::setCaptureUpdate(USceneCaptureComponent2D* capture, bool nodisplay) +{ + capture->bCaptureEveryFrame = !nodisplay; + capture->bCaptureOnMovement = !nodisplay; + capture->bAlwaysPersistRenderingState = true; +} + +void APIPCamera::setCameraTypeUpdate(ImageType type, bool nodisplay) +{ + USceneCaptureComponent2D* capture = getCaptureComponent(type, false); + if (capture != nullptr) + setCaptureUpdate(capture, nodisplay); +} + void APIPCamera::setCameraPose(const msr::airlib::Pose& relative_pose) { FTransform pose = ned_transform_->fromRelativeNed(relative_pose); @@ -579,14 +593,7 @@ void APIPCamera::onViewModeChanged(bool nodisplay) for (unsigned int image_type = 0; image_type < imageTypeCount(); ++image_type) { USceneCaptureComponent2D* capture = getCaptureComponent(static_cast(image_type), false); if (capture) { - if (nodisplay) { - capture->bCaptureEveryFrame = false; - capture->bCaptureOnMovement = false; - } - else { - capture->bCaptureEveryFrame = true; - capture->bCaptureOnMovement = true; - } + setCaptureUpdate(capture, nodisplay); } } } diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.h b/Unreal/Plugins/AirSim/Source/PIPCamera.h index 17780bcdb2..fd4baad6ee 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.h +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.h @@ -41,6 +41,9 @@ class AIRSIM_API APIPCamera : public ACameraActor void setCameraTypeEnabled(ImageType type, bool enabled); bool getCameraTypeEnabled(ImageType type) const; + void setCaptureUpdate(USceneCaptureComponent2D* capture, bool nodisplay); + void setCameraTypeUpdate(ImageType type, bool nodisplay); + void setupCameraFromSettings(const CameraSetting& camera_setting, const NedTransform& ned_transform); void setCameraPose(const msr::airlib::Pose& relative_pose); void setCameraFoV(float fov_degrees); diff --git a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp index 71000329c0..37d23138d5 100644 --- a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp +++ b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp @@ -133,8 +133,10 @@ void ASimHUD::updateWidgetSubwindowVisibility() bool is_visible = getSubWindowSettings().at(window_index).visible && camera != nullptr; - if (camera != nullptr) + if (camera != nullptr) { camera->setCameraTypeEnabled(camera_type, is_visible); + camera->setCameraTypeUpdate(camera_type, false); + } widget_->setSubwindowVisibility(window_index, is_visible, From f588aaedcea4b89ef23714c32a6a09ab543695a2 Mon Sep 17 00:00:00 2001 From: nznaza Date: Tue, 30 Nov 2021 13:24:56 -0600 Subject: [PATCH 2/3] Viewport branchless assignation Fixed gameViewport->bDisableWorldRendering assignation Added comments explaining the reasons behind setting cameras to nodisplay --- Unreal/Plugins/AirSim/Source/CameraDirector.cpp | 12 ++---------- Unreal/Plugins/AirSim/Source/PIPCamera.cpp | 2 ++ Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp | 1 + 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp index a4abceef4d..929e30d2d8 100644 --- a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp +++ b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp @@ -344,16 +344,8 @@ void ACameraDirector::notifyViewModeChanged() { bool nodisplay = ECameraDirectorMode::CAMERA_DIRECTOR_MODE_NODISPLAY == mode_; - //if (fpv_camera_) - // fpv_camera_->onViewModeChanged(nodisplay); - //if (backup_camera_) - // backup_camera_->onViewModeChanged(nodisplay); - //if (ExternalCamera) - // ExternalCamera->onViewModeChanged(nodisplay); - //if (front_camera_) - // front_camera_->onViewModeChanged(nodisplay); - UWorld* world = GetWorld(); UGameViewportClient* gameViewport = world->GetGameViewport(); - gameViewport->bDisableWorldRendering = (uint32)mode_; + gameViewport->bDisableWorldRendering = nodisplay; + } diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index 7a0243ca00..f9853a5371 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -98,6 +98,8 @@ void APIPCamera::BeginPlay() render_targets_[image_type] = NewObject(); } + //We set all cameras to start as nodisplay + //This improves performance because the capture components are no longer updating every frame and only update while requesting an image onViewModeChanged(true); gimbal_stabilization_ = 0; diff --git a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp index 37d23138d5..bffda000ff 100644 --- a/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp +++ b/Unreal/Plugins/AirSim/Source/SimHUD/SimHUD.cpp @@ -135,6 +135,7 @@ void ASimHUD::updateWidgetSubwindowVisibility() if (camera != nullptr) { camera->setCameraTypeEnabled(camera_type, is_visible); + //sub-window captures don’t count as a request, set bCaptureEveryFrame and bCaptureOnMovement to display so we can show correctly the subwindow camera->setCameraTypeUpdate(camera_type, false); } From 8524e35b90a898658b1a67a261ee6d8ee90260b5 Mon Sep 17 00:00:00 2001 From: nznaza Date: Tue, 30 Nov 2021 15:34:00 -0600 Subject: [PATCH 3/3] Fix clang-format violation --- Unreal/Plugins/AirSim/Source/CameraDirector.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp index 929e30d2d8..43f0a3f2ad 100644 --- a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp +++ b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp @@ -347,5 +347,4 @@ void ACameraDirector::notifyViewModeChanged() UWorld* world = GetWorld(); UGameViewportClient* gameViewport = world->GetGameViewport(); gameViewport->bDisableWorldRendering = nodisplay; - }