Changed the DiffuseProbeGrid to an OBB
Signed-off-by: dmcdiar <dmcdiar@amazon.com>
This commit is contained in:
+17
-12
@@ -128,8 +128,8 @@ namespace AZ
|
||||
|
||||
void DiffuseProbeGrid::SetTransform(const AZ::Transform& transform)
|
||||
{
|
||||
m_position = transform.GetTranslation();
|
||||
m_aabbWs = Aabb::CreateCenterHalfExtents(m_position, m_extents / 2.0f);
|
||||
m_transform = transform;
|
||||
m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_extents / 2.0f);
|
||||
|
||||
// probes need to be relocated since the grid position changed
|
||||
m_remainingRelocationIterations = DefaultNumRelocationIterations;
|
||||
@@ -145,7 +145,7 @@ namespace AZ
|
||||
void DiffuseProbeGrid::SetExtents(const AZ::Vector3& extents)
|
||||
{
|
||||
m_extents = extents;
|
||||
m_aabbWs = Aabb::CreateCenterHalfExtents(m_position, m_extents / 2.0f);
|
||||
m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_extents / 2.0f);
|
||||
|
||||
// recompute the number of probes since the extents changed
|
||||
UpdateProbeCount();
|
||||
@@ -467,7 +467,10 @@ namespace AZ
|
||||
RHI::ShaderInputConstantIndex constantIndex;
|
||||
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(AZ::Name("m_probeGrid.origin"));
|
||||
srg->SetConstant(constantIndex, m_position);
|
||||
srg->SetConstant(constantIndex, m_transform.GetTranslation());
|
||||
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(AZ::Name("m_probeGrid.rotation"));
|
||||
srg->SetConstant(constantIndex, m_transform.GetRotation());
|
||||
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(AZ::Name("m_probeGrid.numRaysPerProbe"));
|
||||
srg->SetConstant(constantIndex, m_numRaysPerProbe);
|
||||
@@ -760,14 +763,15 @@ namespace AZ
|
||||
RHI::ShaderInputImageIndex imageIndex;
|
||||
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_modelToWorld"));
|
||||
AZ::Matrix3x4 modelToWorld = AZ::Matrix3x4::CreateFromMatrix3x3AndTranslation(Matrix3x3::CreateIdentity(), m_position) * AZ::Matrix3x4::CreateScale(m_extents);
|
||||
AZ::Matrix3x4 modelToWorld = AZ::Matrix3x4::CreateFromTransform(m_transform) * AZ::Matrix3x4::CreateScale(m_extents);
|
||||
m_renderObjectSrg->SetConstant(constantIndex, modelToWorld);
|
||||
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_aabbMin"));
|
||||
m_renderObjectSrg->SetConstant(constantIndex, m_aabbWs.GetMin());
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_modelToWorldInverse"));
|
||||
AZ::Matrix3x4 modelToWorldInverse = AZ::Matrix3x4::CreateFromTransform(m_transform).GetInverseFull();
|
||||
m_renderObjectSrg->SetConstant(constantIndex, modelToWorldInverse);
|
||||
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_aabbMax"));
|
||||
m_renderObjectSrg->SetConstant(constantIndex, m_aabbWs.GetMax());
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_obbHalfLengths"));
|
||||
m_renderObjectSrg->SetConstant(constantIndex, m_obbWs.GetHalfLengths());
|
||||
|
||||
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_enableDiffuseGI"));
|
||||
m_renderObjectSrg->SetConstant(constantIndex, m_enabled);
|
||||
@@ -821,13 +825,14 @@ namespace AZ
|
||||
lod.m_screenCoverageMax = 1.0f;
|
||||
|
||||
// update cullable bounds
|
||||
Aabb aabbWs = Aabb::CreateFromObb(m_obbWs);
|
||||
Vector3 center;
|
||||
float radius;
|
||||
m_aabbWs.GetAsSphere(center, radius);
|
||||
aabbWs.GetAsSphere(center, radius);
|
||||
|
||||
m_cullable.m_cullData.m_boundingSphere = Sphere(center, radius);
|
||||
m_cullable.m_cullData.m_boundingObb = m_aabbWs.GetTransformedObb(AZ::Transform::CreateIdentity());
|
||||
m_cullable.m_cullData.m_visibilityEntry.m_boundingVolume = m_aabbWs;
|
||||
m_cullable.m_cullData.m_boundingObb = aabbWs.GetTransformedObb(AZ::Transform::CreateIdentity());
|
||||
m_cullable.m_cullData.m_visibilityEntry.m_boundingVolume = aabbWs;
|
||||
m_cullable.m_cullData.m_visibilityEntry.m_userData = &m_cullable;
|
||||
m_cullable.m_cullData.m_visibilityEntry.m_typeFlags = AzFramework::VisibilityEntry::TYPE_RPI_Cullable;
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace AZ
|
||||
const AZ::Vector3& GetExtents() const { return m_extents; }
|
||||
void SetExtents(const AZ::Vector3& extents);
|
||||
|
||||
const AZ::Aabb& GetAabbWs() const { return m_aabbWs; }
|
||||
const AZ::Obb& GetObbWs() const { return m_obbWs; }
|
||||
|
||||
bool ValidateProbeSpacing(const AZ::Vector3& newSpacing);
|
||||
const AZ::Vector3& GetProbeSpacing() const { return m_probeSpacing; }
|
||||
@@ -183,14 +183,14 @@ namespace AZ
|
||||
// scene
|
||||
RPI::Scene* m_scene = nullptr;
|
||||
|
||||
// probe grid position
|
||||
AZ::Vector3 m_position = AZ::Vector3(0.0f, 0.0f, 0.0f);
|
||||
// probe grid transform
|
||||
AZ::Transform m_transform = AZ::Transform::CreateIdentity();
|
||||
|
||||
// extents of the probe grid
|
||||
AZ::Vector3 m_extents = AZ::Vector3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
// probe grid AABB (world space), built from position and extents
|
||||
AZ::Aabb m_aabbWs = AZ::Aabb::CreateNull();
|
||||
// probe grid OBB (world space), built from transform and extents
|
||||
AZ::Obb m_obbWs;
|
||||
|
||||
// per-axis spacing of probes in the grid
|
||||
AZ::Vector3 m_probeSpacing;
|
||||
|
||||
+5
-4
@@ -154,10 +154,11 @@ namespace AZ
|
||||
// sort the probes by descending inner volume size, so the smallest volumes are rendered last
|
||||
auto sortFn = [](AZStd::shared_ptr<DiffuseProbeGrid> const& probe1, AZStd::shared_ptr<DiffuseProbeGrid> const& probe2) -> bool
|
||||
{
|
||||
const Aabb& aabb1 = probe1->GetAabbWs();
|
||||
const Aabb& aabb2 = probe2->GetAabbWs();
|
||||
float size1 = aabb1.GetXExtent() * aabb1.GetZExtent() * aabb1.GetYExtent();
|
||||
float size2 = aabb2.GetXExtent() * aabb2.GetZExtent() * aabb2.GetYExtent();
|
||||
const Obb& obb1 = probe1->GetObbWs();
|
||||
const Obb& obb2 = probe2->GetObbWs();
|
||||
float size1 = obb1.GetHalfLengthX() * obb1.GetHalfLengthZ() * obb1.GetHalfLengthY();
|
||||
float size2 = obb2.GetHalfLengthX() * obb2.GetHalfLengthZ() * obb2.GetHalfLengthY();
|
||||
|
||||
return (size1 > size2);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user