Merge branch 'stabilization/2110' into Atom/santorac/MaterialEditorHandlesMissingTextures
This commit is contained in:
@@ -92,6 +92,8 @@ namespace AZ
|
||||
const AZ::Matrix4x4& GetViewToWorldMatrix() const;
|
||||
const AZ::Matrix4x4& GetViewToClipMatrix() const;
|
||||
const AZ::Matrix4x4& GetWorldToClipMatrix() const;
|
||||
const AZ::Matrix4x4& GetClipToWorldMatrix() const;
|
||||
|
||||
//! Get the camera's world transform, converted from the viewToWorld matrix's native y-up to z-up
|
||||
AZ::Transform GetCameraTransform() const;
|
||||
|
||||
@@ -130,17 +132,22 @@ namespace AZ
|
||||
//! Returns the masked occlusion culling interface
|
||||
MaskedOcclusionCulling* GetMaskedOcclusionCulling();
|
||||
|
||||
//! This is called by RenderPipeline when this view is added to the pipeline.
|
||||
void OnAddToRenderPipeline();
|
||||
|
||||
private:
|
||||
View() = delete;
|
||||
View(const AZ::Name& name, UsageFlags usage);
|
||||
|
||||
|
||||
//! Sorts the finalized draw lists in this view
|
||||
void SortFinalizedDrawLists();
|
||||
|
||||
//! Sorts a drawList using the sort function from a pass with the corresponding drawListTag
|
||||
void SortDrawList(RHI::DrawList& drawList, RHI::DrawListTag tag);
|
||||
|
||||
//! Attempt to create a shader resource group.
|
||||
void TryCreateShaderResourceGroup();
|
||||
|
||||
AZ::Name m_name;
|
||||
UsageFlags m_usageFlags;
|
||||
|
||||
|
||||
@@ -178,6 +178,10 @@ namespace AZ
|
||||
pipelineViews.m_views.resize(1);
|
||||
}
|
||||
ViewPtr previousView = pipelineViews.m_views[0];
|
||||
if (view)
|
||||
{
|
||||
view->OnAddToRenderPipeline();
|
||||
}
|
||||
pipelineViews.m_views[0] = view;
|
||||
|
||||
if (previousView)
|
||||
@@ -238,6 +242,7 @@ namespace AZ
|
||||
pipelineViews.m_type = PipelineViewType::Transient;
|
||||
}
|
||||
view->SetPassesByDrawList(&pipelineViews.m_passesByDrawList);
|
||||
view->OnAddToRenderPipeline();
|
||||
pipelineViews.m_views.push_back(view);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,18 +47,14 @@ namespace AZ
|
||||
{
|
||||
AZ_Assert(!name.IsEmpty(), "invalid name");
|
||||
|
||||
// Set default matrixes.
|
||||
// Set default matrices
|
||||
SetWorldToViewMatrix(AZ::Matrix4x4::CreateIdentity());
|
||||
AZ::Matrix4x4 viewToClipMatrix;
|
||||
AZ::MakePerspectiveFovMatrixRH(viewToClipMatrix, AZ::Constants::HalfPi, 1, 0.1f, 1000.f, true);
|
||||
SetViewToClipMatrix(viewToClipMatrix);
|
||||
|
||||
Data::Asset<ShaderAsset> viewSrgShaderAsset = RPISystemInterface::Get()->GetCommonShaderAssetForSrgs();
|
||||
TryCreateShaderResourceGroup();
|
||||
|
||||
if (viewSrgShaderAsset.IsReady())
|
||||
{
|
||||
m_shaderResourceGroup = ShaderResourceGroup::Create(viewSrgShaderAsset, RPISystemInterface::Get()->GetViewSrgLayout()->GetName());
|
||||
}
|
||||
#if AZ_TRAIT_MASKED_OCCLUSION_CULLING_SUPPORTED
|
||||
m_maskedOcclusionCulling = MaskedOcclusionCulling::Create();
|
||||
m_maskedOcclusionCulling->SetResolution(MaskedSoftwareOcclusionCullingWidth, MaskedSoftwareOcclusionCullingHeight);
|
||||
@@ -125,6 +121,7 @@ namespace AZ
|
||||
|
||||
m_worldToViewMatrix = worldToView;
|
||||
m_worldToClipMatrix = m_viewToClipMatrix * m_worldToViewMatrix;
|
||||
m_clipToWorldMatrix = m_worldToClipMatrix.GetInverseFull();
|
||||
|
||||
m_onWorldToViewMatrixChange.Signal(m_worldToViewMatrix);
|
||||
m_onWorldToClipMatrixChange.Signal(m_worldToClipMatrix);
|
||||
@@ -162,6 +159,7 @@ namespace AZ
|
||||
m_worldToViewMatrix = m_viewToWorldMatrix.GetInverseFast();
|
||||
|
||||
m_worldToClipMatrix = m_viewToClipMatrix * m_worldToViewMatrix;
|
||||
m_clipToWorldMatrix = m_worldToClipMatrix.GetInverseFull();
|
||||
|
||||
// Only signal an update when there is a change, otherwise this might block
|
||||
// user input from changing the value.
|
||||
@@ -177,6 +175,7 @@ namespace AZ
|
||||
m_viewToClipMatrix = viewToClip;
|
||||
|
||||
m_worldToClipMatrix = m_viewToClipMatrix * m_worldToViewMatrix;
|
||||
m_clipToWorldMatrix = m_worldToClipMatrix.GetInverseFull();
|
||||
|
||||
// Update z depth constant simultaneously
|
||||
// zNear -> n, zFar -> f
|
||||
@@ -227,6 +226,11 @@ namespace AZ
|
||||
return m_worldToClipMatrix;
|
||||
}
|
||||
|
||||
const AZ::Matrix4x4& View::GetClipToWorldMatrix() const
|
||||
{
|
||||
return m_clipToWorldMatrix;
|
||||
}
|
||||
|
||||
bool View::HasDrawListTag(RHI::DrawListTag drawListTag)
|
||||
{
|
||||
return drawListTag.IsValid() && m_drawListMask[drawListTag.GetIndex()];
|
||||
@@ -361,16 +365,19 @@ namespace AZ
|
||||
{
|
||||
if (m_clipSpaceOffset.IsZero())
|
||||
{
|
||||
Matrix4x4 worldToClipPrevMatrix = m_viewToClipPrevMatrix * m_worldToViewPrevMatrix;
|
||||
m_shaderResourceGroup->SetConstant(m_worldToClipPrevMatrixConstantIndex, worldToClipPrevMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_viewProjectionMatrixConstantIndex, m_worldToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixConstantIndex, m_viewToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_clipToWorldMatrixConstantIndex, m_clipToWorldMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixInverseConstantIndex, m_viewToClipMatrix.GetInverseFull());
|
||||
if (m_shaderResourceGroup)
|
||||
{
|
||||
Matrix4x4 worldToClipPrevMatrix = m_viewToClipPrevMatrix * m_worldToViewPrevMatrix;
|
||||
m_shaderResourceGroup->SetConstant(m_worldToClipPrevMatrixConstantIndex, worldToClipPrevMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_viewProjectionMatrixConstantIndex, m_worldToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixConstantIndex, m_viewToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_clipToWorldMatrixConstantIndex, m_clipToWorldMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixInverseConstantIndex, m_viewToClipMatrix.GetInverseFull());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Offset the current and previous frame clip matricies
|
||||
// Offset the current and previous frame clip matrices
|
||||
Matrix4x4 offsetViewToClipMatrix = m_viewToClipMatrix;
|
||||
offsetViewToClipMatrix.SetElement(0, 2, m_clipSpaceOffset.GetX());
|
||||
offsetViewToClipMatrix.SetElement(1, 2, m_clipSpaceOffset.GetY());
|
||||
@@ -379,27 +386,33 @@ namespace AZ
|
||||
offsetViewToClipPrevMatrix.SetElement(0, 2, m_clipSpaceOffset.GetX());
|
||||
offsetViewToClipPrevMatrix.SetElement(1, 2, m_clipSpaceOffset.GetY());
|
||||
|
||||
// Build other matricies dependent on the view to clip matricies
|
||||
// Build other matrices dependent on the view to clip matrices
|
||||
Matrix4x4 offsetWorldToClipMatrix = offsetViewToClipMatrix * m_worldToViewMatrix;
|
||||
Matrix4x4 offsetWorldToClipPrevMatrix = offsetViewToClipPrevMatrix * m_worldToViewPrevMatrix;
|
||||
|
||||
Matrix4x4 offsetClipToViewMatrix = offsetViewToClipMatrix.GetInverseFull();
|
||||
Matrix4x4 offsetClipToWorldMatrix = m_viewToWorldMatrix * offsetClipToViewMatrix;
|
||||
|
||||
m_shaderResourceGroup->SetConstant(m_worldToClipPrevMatrixConstantIndex, offsetWorldToClipPrevMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_viewProjectionMatrixConstantIndex, offsetWorldToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixConstantIndex, offsetViewToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_clipToWorldMatrixConstantIndex, offsetClipToWorldMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixInverseConstantIndex, offsetViewToClipMatrix.GetInverseFull());
|
||||
|
||||
if (m_shaderResourceGroup)
|
||||
{
|
||||
m_shaderResourceGroup->SetConstant(m_worldToClipPrevMatrixConstantIndex, offsetWorldToClipPrevMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_viewProjectionMatrixConstantIndex, offsetWorldToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixConstantIndex, offsetViewToClipMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_clipToWorldMatrixConstantIndex, offsetClipToWorldMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_projectionMatrixInverseConstantIndex, offsetViewToClipMatrix.GetInverseFull());
|
||||
}
|
||||
}
|
||||
|
||||
m_shaderResourceGroup->SetConstant(m_worldPositionConstantIndex, m_position);
|
||||
m_shaderResourceGroup->SetConstant(m_viewMatrixConstantIndex, m_worldToViewMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_viewMatrixInverseConstantIndex, m_worldToViewMatrix.GetInverseFull());
|
||||
m_shaderResourceGroup->SetConstant(m_zConstantsConstantIndex, m_nearZ_farZ_farZTimesNearZ_farZMinusNearZ);
|
||||
m_shaderResourceGroup->SetConstant(m_unprojectionConstantsIndex, m_unprojectionConstants);
|
||||
if (m_shaderResourceGroup)
|
||||
{
|
||||
m_shaderResourceGroup->SetConstant(m_worldPositionConstantIndex, m_position);
|
||||
m_shaderResourceGroup->SetConstant(m_viewMatrixConstantIndex, m_worldToViewMatrix);
|
||||
m_shaderResourceGroup->SetConstant(m_viewMatrixInverseConstantIndex, m_worldToViewMatrix.GetInverseFull());
|
||||
m_shaderResourceGroup->SetConstant(m_zConstantsConstantIndex, m_nearZ_farZ_farZTimesNearZ_farZMinusNearZ);
|
||||
m_shaderResourceGroup->SetConstant(m_unprojectionConstantsIndex, m_unprojectionConstants);
|
||||
|
||||
m_shaderResourceGroup->Compile();
|
||||
m_shaderResourceGroup->Compile();
|
||||
}
|
||||
|
||||
m_viewToClipPrevMatrix = m_viewToClipMatrix;
|
||||
m_worldToViewPrevMatrix = m_worldToViewMatrix;
|
||||
@@ -418,5 +431,30 @@ namespace AZ
|
||||
{
|
||||
return m_maskedOcclusionCulling;
|
||||
}
|
||||
|
||||
void View::TryCreateShaderResourceGroup()
|
||||
{
|
||||
if (!m_shaderResourceGroup)
|
||||
{
|
||||
if (auto rpiSystemInterface = RPISystemInterface::Get())
|
||||
{
|
||||
if (Data::Asset<ShaderAsset> viewSrgShaderAsset = rpiSystemInterface->GetCommonShaderAssetForSrgs();
|
||||
viewSrgShaderAsset.IsReady())
|
||||
{
|
||||
m_shaderResourceGroup =
|
||||
ShaderResourceGroup::Create(viewSrgShaderAsset, rpiSystemInterface->GetViewSrgLayout()->GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void View::OnAddToRenderPipeline()
|
||||
{
|
||||
TryCreateShaderResourceGroup();
|
||||
if (!m_shaderResourceGroup)
|
||||
{
|
||||
AZ_Warning("RPI::View", false, "Shader Resource Group failed to initialize");
|
||||
}
|
||||
}
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
|
||||
@@ -69,6 +69,19 @@ namespace UnitTest
|
||||
assetPath /= "Cache";
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@products@", assetPath.c_str());
|
||||
|
||||
// Remark, AZ::Utils::GetProjectPath() is not used when defining "user" folder,
|
||||
// instead We use AZ::Test::GetEngineRootPath();.
|
||||
// Reason:
|
||||
// When running unit tests, using AZ::Utils::GetProjectPath() will resolve to something like:
|
||||
// "/data/workspace/o3de/build/linux/External/Atom-9a4d112b/RPI/Code/Cache"
|
||||
// The ShaderMetricSystem.cpp writes to the @user@ folder and the following runtime error occurs:
|
||||
// "You may not alter data inside the asset cache. Please check the call stack and consider writing into the source asset folder instead."
|
||||
// "Attempted write location: /data/workspace/o3de/build/linux/External/Atom-9a4d112b/RPI/Code/Cache/user/shadermetrics.json"
|
||||
// To avoid the error We use AZ::Test::GetEngineRootPath();
|
||||
AZ::IO::Path userPath = AZ::Test::GetEngineRootPath();
|
||||
userPath /= "user";
|
||||
AZ::IO::FileIOBase::GetInstance()->SetAlias("@user@", userPath.c_str());
|
||||
|
||||
m_jsonRegistrationContext = AZStd::make_unique<AZ::JsonRegistrationContext>();
|
||||
m_jsonSystemComponent = AZStd::make_unique<AZ::JsonSystemComponent>();
|
||||
m_jsonSystemComponent->Reflect(m_jsonRegistrationContext.get());
|
||||
|
||||
Reference in New Issue
Block a user