Fix track view bug where postfxs do not render correctly. (#5465)

* Fix track view bug where postfxs do not render correctly.

Signed-off-by: hershey5045 <43485729+hershey5045@users.noreply.github.com>

* Reduce scope and add comments.

Signed-off-by: hershey5045 <43485729+hershey5045@users.noreply.github.com>
monroegm-disable-blank-issue-2
hershey5045 4 years ago committed by GitHub
parent 27f0aa7f13
commit 9c57c9e64f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,6 +13,7 @@
#include <Atom/RPI.Public/Scene.h> #include <Atom/RPI.Public/Scene.h>
#include <Atom/RPI.Public/View.h> #include <Atom/RPI.Public/View.h>
#include <Atom/RPI.Reflect/System/RenderPipelineDescriptor.h> #include <Atom/RPI.Reflect/System/RenderPipelineDescriptor.h>
#include <PostProcess/PostProcessFeatureProcessor.h>
#include <AzCore/Component/TransformBus.h> #include <AzCore/Component/TransformBus.h>
#include <AzCore/Math/MatrixUtils.h> #include <AzCore/Math/MatrixUtils.h>
#include <AzCore/Name/Name.h> #include <AzCore/Name/Name.h>
@ -47,18 +48,42 @@ namespace TrackView
AZ::Name viewName = AZ::Name("MainCamera"); AZ::Name viewName = AZ::Name("MainCamera");
m_view = AZ::RPI::View::CreateView(viewName, AZ::RPI::View::UsageCamera); m_view = AZ::RPI::View::CreateView(viewName, AZ::RPI::View::UsageCamera);
m_renderPipeline->SetDefaultView(m_view); m_renderPipeline->SetDefaultView(m_view);
m_targetView = scene.GetDefaultRenderPipeline()->GetDefaultView();
if (AZ::Render::PostProcessFeatureProcessor* fp = scene.GetFeatureProcessor<AZ::Render::PostProcessFeatureProcessor>())
{
// This will be set again to mimic the active camera in UpdateView
fp->SetViewAlias(m_view, m_targetView);
}
} }
void AtomOutputFrameCapture::DestroyPipeline(AZ::RPI::Scene& scene) void AtomOutputFrameCapture::DestroyPipeline(AZ::RPI::Scene& scene)
{ {
if (AZ::Render::PostProcessFeatureProcessor* fp = scene.GetFeatureProcessor<AZ::Render::PostProcessFeatureProcessor>())
{
// Remove view alias introduced in CreatePipeline and UpdateView
fp->RemoveViewAlias(m_view);
}
scene.RemoveRenderPipeline(m_renderPipeline->GetId()); scene.RemoveRenderPipeline(m_renderPipeline->GetId());
m_passHierarchy.clear(); m_passHierarchy.clear();
m_renderPipeline.reset(); m_renderPipeline.reset();
m_view.reset(); m_view.reset();
m_targetView.reset();
} }
void AtomOutputFrameCapture::UpdateView(const AZ::Matrix3x4& cameraTransform, const AZ::Matrix4x4& cameraProjection) void AtomOutputFrameCapture::UpdateView(const AZ::Matrix3x4& cameraTransform, const AZ::Matrix4x4& cameraProjection, const AZ::RPI::ViewPtr targetView)
{ {
if (targetView && targetView != m_targetView)
{
if (AZ::RPI::Scene* scene = SceneFromGameEntityContext())
{
if (AZ::Render::PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<AZ::Render::PostProcessFeatureProcessor>())
{
fp->SetViewAlias(m_view, targetView);
m_targetView = targetView;
}
}
}
m_view->SetCameraTransform(cameraTransform); m_view->SetCameraTransform(cameraTransform);
m_view->SetViewToClipMatrix(cameraProjection); m_view->SetViewToClipMatrix(cameraProjection);
} }

@ -39,11 +39,12 @@ namespace TrackView
CaptureFinishedCallback captureFinishedCallback); CaptureFinishedCallback captureFinishedCallback);
//! Update the internal view that is associated with the created pipeline. //! Update the internal view that is associated with the created pipeline.
void UpdateView(const AZ::Matrix3x4& cameraTransform, const AZ::Matrix4x4& cameraProjection); void UpdateView(const AZ::Matrix3x4& cameraTransform, const AZ::Matrix4x4& cameraProjection, const AZ::RPI::ViewPtr targetView = nullptr);
private: private:
AZ::RPI::RenderPipelinePtr m_renderPipeline; //!< The internal render pipeline. AZ::RPI::RenderPipelinePtr m_renderPipeline; //!< The internal render pipeline.
AZ::RPI::ViewPtr m_view; //!< The view associated with the render pipeline. AZ::RPI::ViewPtr m_view; //!< The view associated with the render pipeline.
AZ::RPI::ViewPtr m_targetView; //!< The view that this render pipeline will mimic.
AZStd::vector<AZStd::string> m_passHierarchy; //!< Pass hierarchy (includes pipelineName and CopyToSwapChain). AZStd::vector<AZStd::string> m_passHierarchy; //!< Pass hierarchy (includes pipelineName and CopyToSwapChain).
CaptureFinishedCallback m_captureFinishedCallback; //!< Stored callback called from OnCaptureFinished. CaptureFinishedCallback m_captureFinishedCallback; //!< Stored callback called from OnCaptureFinished.

@ -16,6 +16,7 @@
#include <AzCore/Component/ComponentApplication.h> #include <AzCore/Component/ComponentApplication.h>
#include <AzFramework/Windowing/WindowBus.h> #include <AzFramework/Windowing/WindowBus.h>
#include <Atom/RPI.Public/ViewProviderBus.h>
// Qt // Qt
#include <QAction> #include <QAction>
@ -91,9 +92,12 @@ namespace
static void UpdateAtomOutputFrameCaptureView(TrackView::AtomOutputFrameCapture& atomOutputFrameCapture, const int width, const int height) static void UpdateAtomOutputFrameCaptureView(TrackView::AtomOutputFrameCapture& atomOutputFrameCapture, const int width, const int height)
{ {
const AZ::EntityId activeCameraEntityId = TrackView::ActiveCameraEntityId(); const AZ::EntityId activeCameraEntityId = TrackView::ActiveCameraEntityId();
AZ::RPI::ViewPtr view = nullptr;
AZ::RPI::ViewProviderBus::EventResult(view, activeCameraEntityId, &AZ::RPI::ViewProvider::GetView);
atomOutputFrameCapture.UpdateView( atomOutputFrameCapture.UpdateView(
TrackView::TransformFromEntityId(activeCameraEntityId), TrackView::TransformFromEntityId(activeCameraEntityId),
TrackView::ProjectionFromCameraEntityId(activeCameraEntityId, static_cast<float>(width), static_cast<float>(height))); TrackView::ProjectionFromCameraEntityId(activeCameraEntityId, aznumeric_cast<float>(width), aznumeric_cast<float>(height)),
view);
} }
CSequenceBatchRenderDialog::CSequenceBatchRenderDialog(float fps, QWidget* pParent /* = nullptr */) CSequenceBatchRenderDialog::CSequenceBatchRenderDialog(float fps, QWidget* pParent /* = nullptr */)

@ -37,6 +37,11 @@ namespace AZ
m_currentTime = AZStd::chrono::system_clock::now(); m_currentTime = AZStd::chrono::system_clock::now();
} }
void PostProcessFeatureProcessor::Deactivate()
{
m_viewAliasMap.clear();
}
void PostProcessFeatureProcessor::UpdateTime() void PostProcessFeatureProcessor::UpdateTime()
{ {
AZStd::chrono::system_clock::time_point now = AZStd::chrono::system_clock::now(); AZStd::chrono::system_clock::time_point now = AZStd::chrono::system_clock::now();
@ -45,6 +50,16 @@ namespace AZ
m_deltaTime = deltaTime.count(); m_deltaTime = deltaTime.count();
} }
void PostProcessFeatureProcessor::SetViewAlias(const AZ::RPI::ViewPtr sourceView, const AZ::RPI::ViewPtr targetView)
{
m_viewAliasMap[sourceView.get()] = targetView.get();
}
void PostProcessFeatureProcessor::RemoveViewAlias(const AZ::RPI::ViewPtr sourceView)
{
m_viewAliasMap.erase(sourceView.get());
}
void PostProcessFeatureProcessor::Simulate(const FeatureProcessor::SimulatePacket& packet) void PostProcessFeatureProcessor::Simulate(const FeatureProcessor::SimulatePacket& packet)
{ {
AZ_PROFILE_SCOPE(RPI, "PostProcessFeatureProcessor: Simulate"); AZ_PROFILE_SCOPE(RPI, "PostProcessFeatureProcessor: Simulate");
@ -200,8 +215,12 @@ namespace AZ
AZ::Render::PostProcessSettings* PostProcessFeatureProcessor::GetLevelSettingsFromView(AZ::RPI::ViewPtr view) AZ::Render::PostProcessSettings* PostProcessFeatureProcessor::GetLevelSettingsFromView(AZ::RPI::ViewPtr view)
{ {
// check for view aliases first
auto viewAliasiterator = m_viewAliasMap.find(view.get());
// Use the view alias if it exists
auto settingsIterator = m_blendedPerViewSettings.find(viewAliasiterator != m_viewAliasMap.end() ? viewAliasiterator->second : view.get());
// If no settings for the view is found, the global settings is returned. // If no settings for the view is found, the global settings is returned.
auto settingsIterator = m_blendedPerViewSettings.find(view.get());
return settingsIterator != m_blendedPerViewSettings.end() return settingsIterator != m_blendedPerViewSettings.end()
? &settingsIterator->second ? &settingsIterator->second
: m_globalAggregateLevelSettings.get(); : m_globalAggregateLevelSettings.get();

@ -34,6 +34,7 @@ namespace AZ
//! FeatureProcessor overrides... //! FeatureProcessor overrides...
void Activate() override; void Activate() override;
void Deactivate() override;
void Simulate(const FeatureProcessor::SimulatePacket& packet) override; void Simulate(const FeatureProcessor::SimulatePacket& packet) override;
//! PostProcessFeatureProcessorInterface... //! PostProcessFeatureProcessorInterface...
@ -43,6 +44,9 @@ namespace AZ
void OnPostProcessSettingsChanged() override; void OnPostProcessSettingsChanged() override;
PostProcessSettings* GetLevelSettingsFromView(AZ::RPI::ViewPtr view); PostProcessSettings* GetLevelSettingsFromView(AZ::RPI::ViewPtr view);
void SetViewAlias(const AZ::RPI::ViewPtr sourceView, const AZ::RPI::ViewPtr targetView);
void RemoveViewAlias(const AZ::RPI::ViewPtr sourceView);
private: private:
PostProcessFeatureProcessor(const PostProcessFeatureProcessor&) = delete; PostProcessFeatureProcessor(const PostProcessFeatureProcessor&) = delete;
@ -83,6 +87,8 @@ namespace AZ
// Each camera/view will have its own PostProcessSettings // Each camera/view will have its own PostProcessSettings
AZStd::unordered_map<AZ::RPI::View*, PostProcessSettings> m_blendedPerViewSettings; AZStd::unordered_map<AZ::RPI::View*, PostProcessSettings> m_blendedPerViewSettings;
// This is used for mimicking a postfx setting of a different view
AZStd::unordered_map<AZ::RPI::View*, AZ::RPI::View*> m_viewAliasMap;
}; };
} // namespace Render } // namespace Render
} // namespace AZ } // namespace AZ

@ -81,7 +81,7 @@ namespace AZ
if (scene) if (scene)
{ {
PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>(); PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>();
AZ::RPI::ViewPtr view = GetView(); AZ::RPI::ViewPtr view = GetRenderPipeline()->GetDefaultView();
if (fp) if (fp)
{ {
PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view); PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view);
@ -110,7 +110,7 @@ namespace AZ
PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>(); PostProcessFeatureProcessor* fp = scene->GetFeatureProcessor<PostProcessFeatureProcessor>();
if (fp) if (fp)
{ {
AZ::RPI::ViewPtr view = GetView(); AZ::RPI::ViewPtr view = GetRenderPipeline()->GetDefaultView();
PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view); PostProcessSettings* postProcessSettings = fp->GetLevelSettingsFromView(view);
if (postProcessSettings) if (postProcessSettings)
{ {

Loading…
Cancel
Save