Integrating latest from github/staging

Integrating up through commit 5e1bdae
This commit is contained in:
alexpete
2021-03-26 14:31:50 -07:00
parent 9c54341af8
commit 36c4e827bd
764 changed files with 11453 additions and 20251 deletions
@@ -0,0 +1,124 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "AtomOutputFrameCapture.h"
#include <Atom/RPI.Public/Pass/Specific/RenderToTexturePass.h>
#include <Atom/RPI.Public/RenderPipeline.h>
#include <Atom/RPI.Public/Scene.h>
#include <Atom/RPI.Public/View.h>
#include <Atom/RPI.Reflect/System/RenderPipelineDescriptor.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Math/MatrixUtils.h>
#include <AzCore/Name/Name.h>
#include <AzFramework/Entity/GameEntityContextBus.h>
#include <AzFramework/Scene/Scene.h>
#include <AzFramework/Scene/SceneSystemBus.h>
namespace TrackView
{
void AtomOutputFrameCapture::CreatePipeline(
AZ::RPI::Scene& scene, const AZStd::string& pipelineName, const uint32_t width, const uint32_t height)
{
AZ::RPI::RenderPipelineDescriptor pipelineDesc;
pipelineDesc.m_mainViewTagName = "MainCamera"; // must be "MainCamera"
pipelineDesc.m_name = pipelineName;
pipelineDesc.m_rootPassTemplate = "MainPipelineRenderToTexture";
pipelineDesc.m_renderSettings.m_multisampleState.m_samples = 4;
m_renderPipeline = AZ::RPI::RenderPipeline::CreateRenderPipeline(pipelineDesc);
if (auto renderToTexturePass = azrtti_cast<AZ::RPI::RenderToTexturePass*>(m_renderPipeline->GetRootPass().get()))
{
renderToTexturePass->ResizeOutput(width, height);
}
scene.AddRenderPipeline(m_renderPipeline);
// rendering pipeline has a tree structure
m_passHierarchy.push_back(pipelineName);
m_passHierarchy.push_back("CopyToSwapChain");
// retrieve View from the camera that's animating
AZ::Name viewName = AZ::Name("MainCamera");
m_view = AZ::RPI::View::CreateView(viewName, AZ::RPI::View::UsageCamera);
m_renderPipeline->SetDefaultView(m_view);
}
void AtomOutputFrameCapture::DestroyPipeline(AZ::RPI::Scene& scene)
{
scene.RemoveRenderPipeline(m_renderPipeline->GetId());
m_passHierarchy.clear();
m_renderPipeline.reset();
m_view.reset();
}
void AtomOutputFrameCapture::UpdateView(const AZ::Matrix3x4& cameraTransform, const AZ::Matrix4x4& cameraProjection)
{
m_view->SetCameraTransform(cameraTransform);
m_view->SetViewToClipMatrix(cameraProjection);
}
bool AtomOutputFrameCapture::BeginCapture(
const AZ::RPI::AttachmentReadback::CallbackFunction& attachmentReadbackCallback, CaptureFinishedCallback captureFinishedCallback)
{
AZ::Render::FrameCaptureNotificationBus::Handler::BusConnect();
m_captureFinishedCallback = AZStd::move(captureFinishedCallback);
// note: "Output" (slot name) maps to MainPipeline.pass CopyToSwapChain
bool startedCapture = false;
AZ::Render::FrameCaptureRequestBus::BroadcastResult(
startedCapture, &AZ::Render::FrameCaptureRequestBus::Events::CapturePassAttachmentWithCallback, m_passHierarchy,
AZStd::string("Output"), attachmentReadbackCallback);
return startedCapture;
}
void AtomOutputFrameCapture::OnCaptureFinished(
[[maybe_unused]] AZ::Render::FrameCaptureResult result, [[maybe_unused]] const AZStd::string& info)
{
m_captureFinishedCallback();
AZ::Render::FrameCaptureNotificationBus::Handler::BusDisconnect();
}
AZ::Matrix3x4 TransformFromEntityId(const AZ::EntityId entityId)
{
AZ::Transform cameraTransform = AZ::Transform::CreateIdentity();
AZ::TransformBus::EventResult(cameraTransform, entityId, &AZ::TransformBus::Events::GetWorldTM);
return AZ::Matrix3x4::CreateFromTransform(cameraTransform);
}
AZ::Matrix4x4 ProjectionFromCameraEntityId(const AZ::EntityId entityId, const float outputWidth, const float outputHeight)
{
float nearDist = 0.0f;
Camera::CameraRequestBus::EventResult(nearDist, entityId, &Camera::CameraRequestBus::Events::GetNearClipDistance);
float farDist = 0.0f;
Camera::CameraRequestBus::EventResult(farDist, entityId, &Camera::CameraRequestBus::Events::GetFarClipDistance);
float fovRad = 0.0f;
Camera::CameraRequestBus::EventResult(fovRad, entityId, &Camera::CameraRequestBus::Events::GetFovRadians);
const float aspectRatio = outputWidth / outputHeight;
AZ::Matrix4x4 viewToClipMatrix;
AZ::MakePerspectiveFovMatrixRH(viewToClipMatrix, fovRad, aspectRatio, nearDist, farDist, /*reverseDepth=*/true);
return viewToClipMatrix;
}
AZ::RPI::Scene* SceneFromGameEntityContext()
{
AzFramework::EntityContextId entityContextId;
AzFramework::GameEntityContextRequestBus::BroadcastResult(
entityContextId, &AzFramework::GameEntityContextRequestBus::Events::GetGameEntityContextId);
return AZ::RPI::Scene::GetSceneForEntityContextId(entityContextId);
}
} // namespace TrackView
@@ -0,0 +1,74 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <Atom/Feature/Utils/FrameCaptureBus.h>
#include <AzFramework/Components/CameraBus.h>
namespace TrackView
{
//! Provides functionality to capture frames from the "MainCamera".
//! A new pipeline is created (and associated with the scene provided), a callback can be
//! provided to handle the attachment readback (what to do with the captured frame) and also
//! what to do after an individual capture fully completes (called in OnCaptureFinished).
class AtomOutputFrameCapture : private AZ::Render::FrameCaptureNotificationBus::Handler
{
public:
AtomOutputFrameCapture() = default;
using CaptureFinishedCallback = AZStd::function<void()>;
//! Create a new pipeline associated with a given scene.
//! @note "MainCamera" is the view that is captured.
void CreatePipeline(AZ::RPI::Scene& scene, const AZStd::string& pipelineName, uint32_t width, uint32_t height);
//! Removes the pipeline from the scene provided and then destroys it.
//! @note scene must be the same scene used to create the pipeline.
void DestroyPipeline(AZ::RPI::Scene& scene);
//! Request a capture to start.
//! @param attachmentReadbackCallback Handles the returned attachment (image data returned by the renderer).
//! @param captureFinishedCallback Logic to run once the capture has completed fully.
bool BeginCapture(
const AZ::RPI::AttachmentReadback::CallbackFunction& attachmentReadbackCallback,
CaptureFinishedCallback captureFinishedCallback);
//! Update the internal view that is associated with the created pipeline.
void UpdateView(const AZ::Matrix3x4& cameraTransform, const AZ::Matrix4x4& cameraProjection);
private:
AZ::RPI::RenderPipelinePtr m_renderPipeline; //!< The internal render pipeline.
AZ::RPI::ViewPtr m_view; //!< The view associated with the render pipeline.
AZStd::vector<AZStd::string> m_passHierarchy; //!< Pass hierarchy (includes pipelineName and CopyToSwapChain).
CaptureFinishedCallback m_captureFinishedCallback; //!< Stored callback called from OnCaptureFinished.
// FrameCaptureNotificationBus overrides ...
void OnCaptureFinished(AZ::Render::FrameCaptureResult result, const AZStd::string& info) override;
};
inline AZ::EntityId ActiveCameraEntityId()
{
AZ::EntityId activeCameraId;
Camera::CameraSystemRequestBus::BroadcastResult(activeCameraId, &Camera::CameraSystemRequests::GetActiveCamera);
return activeCameraId;
}
//! Returns the transform for the given EntityId.
AZ::Matrix3x4 TransformFromEntityId(AZ::EntityId entityId);
//! Returns the projection matrix for the given camera EntityId.
//! @note Must provide a valid camera entity.
AZ::Matrix4x4 ProjectionFromCameraEntityId(AZ::EntityId entityId, float outputWidth, float outputHeight);
//! Helper to return the GameEntityContext scene.
AZ::RPI::Scene* SceneFromGameEntityContext();
} // namespace TrackView
@@ -43,7 +43,6 @@ AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
#include <TrackView/ui_SequenceBatchRenderDialog.h>
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
namespace
{
const int g_useActiveViewportResolution = -1; // reserved value to indicate the use of the active viewport resolution
@@ -92,6 +91,14 @@ namespace
}
}
static void UpdateAtomOutputFrameCaptureView(TrackView::AtomOutputFrameCapture& atomOutputFrameCapture, const int width, const int height)
{
const AZ::EntityId activeCameraEntityId = TrackView::ActiveCameraEntityId();
atomOutputFrameCapture.UpdateView(
TrackView::TransformFromEntityId(activeCameraEntityId),
TrackView::ProjectionFromCameraEntityId(activeCameraEntityId, width, height));
}
CSequenceBatchRenderDialog::CSequenceBatchRenderDialog(float fps, QWidget* pParent /* = nullptr */)
: QDialog(pParent)
, m_fpsForTimeToFrameConversion(fps)
@@ -874,8 +881,6 @@ void CSequenceBatchRenderDialog::InitializeContext()
void CSequenceBatchRenderDialog::CaptureItemStart()
{
AZ::Render::FrameCaptureNotificationBus::Handler::BusConnect();
// Disable most of the UI in group chunks.
// (Leave the start/cancel button and feedback elements).
m_ui->BATCH_RENDER_LIST_GROUP_BOX->setEnabled(false);
@@ -976,20 +981,11 @@ void CSequenceBatchRenderDialog::CaptureItemStart()
m_renderContext.cvarCustomResHeightBU = pCVarCustomResHeight->GetIVal();
pCVarCustomResWidth->Set(renderWidth);
pCVarCustomResHeight->Set(renderHeight);
// awaiting ATOM-14859
// AzFramework::NativeWindowHandle windowHandle = nullptr;
// AzFramework::WindowSystemRequestBus::BroadcastResult(
// windowHandle, &AzFramework::WindowSystemRequestBus::Events::GetDefaultWindowHandle);
// AzFramework::WindowRequestBus::Event(
// windowHandle, &AzFramework::WindowRequestBus::Events::ResizeClientArea,
// AzFramework::WindowSize(renderWidth, renderHeight));
}
else
{
// Otherwise, try to adjust the viewport resolution accordingly.
CLayoutViewPane* viewPane = MainWindow::instance()->GetActiveView();
if (viewPane)
if (CLayoutViewPane* viewPane = MainWindow::instance()->GetActiveView())
{
viewPane->ResizeViewport(renderWidth, renderHeight);
}
@@ -1008,6 +1004,11 @@ void CSequenceBatchRenderDialog::CaptureItemStart()
}
}
// create a new atom pipeline to capture the frames of the current sequence
m_atomOutputFrameCapture.CreatePipeline(
*TrackView::SceneFromGameEntityContext(), "TrackViewSequencePipeline", renderItem.resW, renderItem.resH);
UpdateAtomOutputFrameCaptureView(m_atomOutputFrameCapture, renderItem.resW, renderItem.resH);
GetIEditor()->GetMovieSystem()->EnableFixedStepForCapture(m_renderContext.captureOptions.timeStep);
// The capturing doesn't actually start here. It just flags the warming-up and
@@ -1205,7 +1206,7 @@ void CSequenceBatchRenderDialog::OnUpdateFinalize()
m_renderContext.frameNumber = 0;
m_renderContext.capturingFrame = false;
AZ::Render::FrameCaptureNotificationBus::Handler::BusDisconnect();
m_atomOutputFrameCapture.DestroyPipeline(*TrackView::SceneFromGameEntityContext());
// Check to see if there is more items to process
bool done = m_renderContext.currentItemIndex == m_renderItems.size() - 1;
@@ -1330,6 +1331,9 @@ void CSequenceBatchRenderDialog::OnKickIdle()
// being captured, it's safe to move to the next step of the main update
if (!capturing() || !m_renderContext.capturingFrame)
{
const auto& renderItem = m_renderItems[m_renderContext.currentItemIndex];
// update the view given the current camera transform and projection
UpdateAtomOutputFrameCaptureView(m_atomOutputFrameCapture, renderItem.resW, renderItem.resH);
GetIEditor()->GetGameEngine()->Update(); // step update (original frame capture)
}
@@ -1341,14 +1345,24 @@ void CSequenceBatchRenderDialog::OnKickIdle()
m_renderContext.captureOptions.folder.c_str(), fileName.c_str(), filePath, /*caseInsensitive=*/true,
/*normalize=*/false);
bool capturedScreenshot = false;
AZ::Render::FrameCaptureRequestBus::BroadcastResult(
capturedScreenshot, &AZ::Render::FrameCaptureRequestBus::Events::CaptureScreenshot, filePath);
// track view callback after each frame is captured
const auto captureFinishedCallback = [this]() {
m_renderContext.capturingFrame = false;
GetIEditor()->GetMovieSystem()->EndCapture();
GetIEditor()->GetMovieSystem()->ControlCapture();
};
if (capturedScreenshot)
{
m_renderContext.capturingFrame = true;
}
// readback result callback (how the image should be captured)
// currently only .dds
const auto readbackCallback = [filePath](const AZ::RPI::AttachmentReadback::ReadbackResult& readbackResult) {
if (const AZ::Render::FrameCaptureOutputResult result = AZ::Render::DdsFrameCaptureOutput(filePath, readbackResult);
result.m_errorMessage.has_value())
{
AZ_Printf("TrackView", "Frame capture failed: %s", result.m_errorMessage.value().c_str());
}
};
m_renderContext.capturingFrame = m_atomOutputFrameCapture.BeginCapture(readbackCallback, captureFinishedCallback);
}
}
else
@@ -1358,14 +1372,6 @@ void CSequenceBatchRenderDialog::OnKickIdle()
}
}
void CSequenceBatchRenderDialog::OnCaptureFinished(
[[maybe_unused]] AZ::Render::FrameCaptureResult result, [[maybe_unused]] const AZStd::string& info)
{
m_renderContext.capturingFrame = false;
GetIEditor()->GetMovieSystem()->EndCapture();
GetIEditor()->GetMovieSystem()->ControlCapture();
}
void CSequenceBatchRenderDialog::OnCancelRender()
{
if (m_renderContext.captureState == CaptureState::Capturing)
@@ -15,8 +15,9 @@
#pragma once
#include "AtomOutputFrameCapture.h"
#include <AzFramework/StringFunc/StringFunc.h>
#include <Atom/Feature/Utils/FrameCaptureBus.h>
#include <QDialog>
#include <QTimer>
@@ -33,7 +34,6 @@ namespace Ui
class CSequenceBatchRenderDialog
: public QDialog
, public IMovieListener
, private AZ::Render::FrameCaptureNotificationBus::Handler
{
public:
CSequenceBatchRenderDialog(float fps, QWidget* pParent = nullptr);
@@ -219,9 +219,6 @@ protected slots:
bool GetResolutionFromCustomResText(const char* customResText, int& retCustomWidth, int& retCustomHeight) const;
private:
// FrameCaptureNotificationBus overrides ...
void OnCaptureFinished(AZ::Render::FrameCaptureResult result, const AZStd::string& info) override;
void CheckForEnableUpdateButton();
void stashActiveViewportResolution();
void UpdateSpinnerProgressMessage(const char* description);
@@ -234,4 +231,6 @@ private:
bool m_editorIdleProcessingEnabled;
int32 CV_TrackViewRenderOutputCapturing;
QScopedPointer<CPrefixValidator> m_prefixValidator;
TrackView::AtomOutputFrameCapture m_atomOutputFrameCapture;
};