Fix game mode camera components not working in-Editor

Ensures RPI::View updates always make it back to the ViewportContext, even if you talk directly to the View
This commit is contained in:
nvsickle
2021-04-22 17:35:27 -07:00
parent e1ae61ca06
commit 9e6244dc99
4 changed files with 45 additions and 4 deletions
@@ -104,6 +104,9 @@ namespace AZ
m_worldToClipMatrix = m_viewToClipMatrix * m_worldToViewMatrix;
m_worldToClipMatrixChanged = true;
m_onWorldToViewMatrixChange.Signal(m_worldToViewMatrix);
m_oWworldToClipMatrixChange.Signal(m_worldToClipMatrix);
InvalidateSrg();
}
@@ -132,6 +135,9 @@ namespace AZ
m_clipToWorldMatrix = m_viewToWorldMatrix * m_clipToViewMatrix;
m_worldToClipMatrixChanged = true;
m_onWorldToViewMatrixChange.Signal(m_worldToViewMatrix);
m_oWworldToClipMatrixChange.Signal(m_worldToClipMatrix);
InvalidateSrg();
}
@@ -166,6 +172,8 @@ namespace AZ
m_unprojectionConstants.SetZ(float(-tanHalfFovX));
m_unprojectionConstants.SetW(float(tanHalfFovY));
m_oWworldToClipMatrixChange.Signal(m_worldToClipMatrix);
InvalidateSrg();
}
@@ -225,6 +233,16 @@ namespace AZ
passWithDrawListTag->SortDrawList(drawList);
}
void View::ConnectWorldToViewMatrixChangedHandler(View::MatrixChangedEvent::Handler& handler)
{
handler.Connect(m_onWorldToViewMatrixChange);
}
void View::ConnectWorldToClipMatrixChangedHandler(View::MatrixChangedEvent::Handler& handler)
{
handler.Connect(m_oWworldToClipMatrixChange);
}
// [GFX TODO] This function needs unit tests and might need to be reworked
RHI::DrawItemSortKey View::GetSortKeyForPosition(const Vector3& positionInWorld) const
{
@@ -34,8 +34,16 @@ namespace AZ
&AzFramework::WindowRequestBus::Events::GetClientAreaSize);
AzFramework::WindowNotificationBus::Handler::BusConnect(nativeWindow);
SetRenderScene(renderScene);
}
m_onProjectionMatrixChangedHandler = ViewportContext::MatrixChangedEvent::Handler([this](const AZ::Matrix4x4& matrix)
{
m_projectionMatrixChangedEvent.Signal(matrix);
});
m_onViewMatrixChangedHandler = ViewportContext::MatrixChangedEvent::Handler([this](const AZ::Matrix4x4& matrix)
{
m_projectionMatrixChangedEvent.Signal(matrix);
});
SetRenderScene(renderScene); }
ViewportContext::~ViewportContext()
{
@@ -175,7 +183,6 @@ namespace AZ
void ViewportContext::SetCameraProjectionMatrix(const AZ::Matrix4x4& matrix)
{
GetDefaultView()->SetViewToClipMatrix(matrix);
m_projectionMatrixChangedEvent.Signal(matrix);
}
AZ::Transform ViewportContext::GetCameraTransform() const
@@ -192,18 +199,23 @@ namespace AZ
{
const auto view = GetDefaultView();
view->SetCameraTransform(AZ::Matrix3x4::CreateFromTransform(transform.GetOrthogonalized()));
m_viewMatrixChangedEvent.Signal(view->GetWorldToViewMatrix());
}
void ViewportContext::SetDefaultView(ViewPtr view)
{
if (m_defaultView != view)
{
m_onProjectionMatrixChangedHandler.Disconnect();
m_onViewMatrixChangedHandler.Disconnect();
m_defaultView = view;
UpdatePipelineView();
m_viewMatrixChangedEvent.Signal(view->GetWorldToViewMatrix());
m_projectionMatrixChangedEvent.Signal(view->GetViewToClipMatrix());
view->ConnectWorldToViewMatrixChangedHandler(m_onViewMatrixChangedHandler);
view->ConnectWorldToClipMatrixChangedHandler(m_onProjectionMatrixChangedHandler);
}
}