Fix for two viewports not computing the right camera matrices (#5672)

Signed-off-by: mrieggeramzn <mriegger@amazon.com>
monroegm-disable-blank-issue-2
mrieggeramzn 4 years ago committed by GitHub
parent a74fa5c5b8
commit 6c1eefe605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -343,7 +343,6 @@ namespace AZ
m_shadowBufferNeedsUpdate = true; m_shadowBufferNeedsUpdate = true;
m_shadowProperties.GetData(index).m_cameraConfigurations[nullptr] = {}; m_shadowProperties.GetData(index).m_cameraConfigurations[nullptr] = {};
m_shadowProperties.GetData(index).m_cameraTransforms[nullptr] = Transform::CreateIdentity();
const LightHandle handle(index); const LightHandle handle(index);
m_shadowingLightHandle = handle; // only the recent light has shadows. m_shadowingLightHandle = handle; // only the recent light has shadows.
@ -495,20 +494,10 @@ namespace AZ
void DirectionalLightFeatureProcessor::SetCameraTransform( void DirectionalLightFeatureProcessor::SetCameraTransform(
LightHandle handle, LightHandle handle,
const Transform& cameraTransform, const Transform&,
const RPI::RenderPipelineId& renderPipelineId) const RPI::RenderPipelineId&)
{ {
ShadowProperty& property = m_shadowProperties.GetData(handle.GetIndex()); ShadowProperty& property = m_shadowProperties.GetData(handle.GetIndex());
if (RPI::RenderPipeline* renderPipeline = GetParentScene()->GetRenderPipeline(renderPipelineId).get())
{
const RPI::View* cameraView = renderPipeline->GetDefaultView().get();
property.m_cameraTransforms[cameraView] = cameraTransform;
}
else
{
property.m_cameraTransforms[nullptr] = cameraTransform;
}
property.m_shadowmapViewNeedsUpdate = true; property.m_shadowmapViewNeedsUpdate = true;
} }
@ -934,17 +923,6 @@ namespace AZ
return property.m_cameraConfigurations.at(nullptr); return property.m_cameraConfigurations.at(nullptr);
} }
const Transform& DirectionalLightFeatureProcessor::GetCameraTransform(LightHandle handle, const RPI::View* cameraView) const
{
const ShadowProperty& property = m_shadowProperties.GetData(handle.GetIndex());
const auto findIt = property.m_cameraTransforms.find(cameraView);
if (findIt != property.m_cameraTransforms.end())
{
return findIt->second;
}
return property.m_cameraTransforms.at(nullptr);
}
void DirectionalLightFeatureProcessor::UpdateFrustums( void DirectionalLightFeatureProcessor::UpdateFrustums(
LightHandle handle) LightHandle handle)
{ {
@ -1365,10 +1343,11 @@ namespace AZ
// If we used an AABB whose Y-direction range is from a segment, // If we used an AABB whose Y-direction range is from a segment,
// the depth value on the shadowmap saturated to 0 or 1, // the depth value on the shadowmap saturated to 0 or 1,
// and we could not draw shadow correctly. // and we could not draw shadow correctly.
const Transform cameraTransform = cameraView->GetCameraTransform();
const Vector3 entireFrustumCenterLight = const Vector3 entireFrustumCenterLight =
lightTransform.GetInverseFast() * (GetCameraTransform(handle, cameraView).TransformPoint(property.m_entireFrustumCenterLocal)); lightTransform.GetInverseFast() * (cameraTransform.TransformPoint(property.m_entireFrustumCenterLocal));
const float entireCenterY = entireFrustumCenterLight.GetElement(1); const float entireCenterY = entireFrustumCenterLight.GetElement(1);
const Vector3 cameraLocationWorld = GetCameraTransform(handle, cameraView).GetTranslation(); const Vector3 cameraLocationWorld = cameraTransform.GetTranslation();
const Vector3 cameraLocationLight = lightTransformInverse * cameraLocationWorld; const Vector3 cameraLocationLight = lightTransformInverse * cameraLocationWorld;
// Extend light view frustum by camera depth far in order to avoid shadow lacking behind camera. // Extend light view frustum by camera depth far in order to avoid shadow lacking behind camera.
const float cameraBehindMinY = cameraLocationLight.GetElement(1) - GetCameraConfiguration(handle, cameraView).GetDepthFar(); const float cameraBehindMinY = cameraLocationLight.GetElement(1) - GetCameraConfiguration(handle, cameraView).GetDepthFar();
@ -1429,7 +1408,7 @@ namespace AZ
depthFar); depthFar);
const Vector3 localCenter{ 0.f, depthCenter, 0.f }; const Vector3 localCenter{ 0.f, depthCenter, 0.f };
return GetCameraTransform(handle, cameraView).TransformPoint(localCenter); return cameraView->GetCameraTransform().TransformPoint(localCenter);
} }
float DirectionalLightFeatureProcessor::GetRadius( float DirectionalLightFeatureProcessor::GetRadius(
@ -1483,7 +1462,7 @@ namespace AZ
const ShadowProperty& property = m_shadowProperties.GetData(handle.GetIndex()); const ShadowProperty& property = m_shadowProperties.GetData(handle.GetIndex());
const Vector3& boundaryCenter = GetWorldCenterPosition(handle, cameraView, depthNear, depthFar); const Vector3& boundaryCenter = GetWorldCenterPosition(handle, cameraView, depthNear, depthFar);
const CascadeShadowCameraConfiguration& cameraConfiguration = GetCameraConfiguration(handle, cameraView); const CascadeShadowCameraConfiguration& cameraConfiguration = GetCameraConfiguration(handle, cameraView);
const Transform& cameraTransform = GetCameraTransform(handle, cameraView); const Transform cameraTransform = cameraView->GetCameraTransform();
const Vector3& cameraFwd = cameraTransform.GetBasis(1); const Vector3& cameraFwd = cameraTransform.GetBasis(1);
const Vector3& cameraUp = cameraTransform.GetBasis(2); const Vector3& cameraUp = cameraTransform.GetBasis(2);
const Vector3 cameraToBoundaryCenter = boundaryCenter - cameraTransform.GetTranslation(); const Vector3 cameraToBoundaryCenter = boundaryCenter - cameraTransform.GetTranslation();

@ -134,9 +134,6 @@ namespace AZ
// Default far depth of each cascade. // Default far depth of each cascade.
AZStd::array<float, Shadow::MaxNumberOfCascades> m_defaultFarDepths; AZStd::array<float, Shadow::MaxNumberOfCascades> m_defaultFarDepths;
// Transforms of camera who offers view frustum for each camera view.
AZStd::unordered_map<const RPI::View*, Transform> m_cameraTransforms;
// Configuration offers shape of the camera view frustum for each camera view. // Configuration offers shape of the camera view frustum for each camera view.
AZStd::unordered_map<const RPI::View*, CascadeShadowCameraConfiguration> m_cameraConfigurations; AZStd::unordered_map<const RPI::View*, CascadeShadowCameraConfiguration> m_cameraConfigurations;
@ -259,11 +256,6 @@ namespace AZ
//! it returns one of the fallback render pipeline ID. //! it returns one of the fallback render pipeline ID.
const CascadeShadowCameraConfiguration& GetCameraConfiguration(LightHandle handle, const RPI::View* cameraView) const; const CascadeShadowCameraConfiguration& GetCameraConfiguration(LightHandle handle, const RPI::View* cameraView) const;
//! This returns the camera transform.
//! If it has not been registered for the given camera view.
//! it returns one of the fallback render pipeline ID.
const Transform& GetCameraTransform(LightHandle handle, const RPI::View* cameraView) const;
//! This update view frustum of camera. //! This update view frustum of camera.
void UpdateFrustums(LightHandle handle); void UpdateFrustums(LightHandle handle);

Loading…
Cancel
Save