Improved DiffuseProbeGrid blending around the edges of the volume

Signed-off-by: dmcdiarmid-ly <63674186+dmcdiarmid-ly@users.noreply.github.com>
This commit is contained in:
dmcdiarmid-ly
2022-01-05 21:51:42 -07:00
parent 7581967da3
commit 23293a13c1
7 changed files with 23 additions and 6 deletions
@@ -150,7 +150,7 @@ PSOutput MainPS(VSOutput IN, in uint sampleIndex : SV_SampleIndex)
float4 encodedNormal = PassSrg::m_normal.Load(screenCoords, sampleIndex);
float3 normal = DecodeNormalSignedOctahedron(encodedNormal.rgb);
float4 albedo = PassSrg::m_albedo.Load(screenCoords, sampleIndex);
float probeIrradianceBlendWeight = PassSrg::m_downsampledProbeIrradiance.Load(probeIrradianceCoords, sampleIndex).a;
float probeIrradianceBlendWeight = saturate(PassSrg::m_downsampledProbeIrradiance.Load(probeIrradianceCoords, sampleIndex).a);
float3 diffuse = float3(0.0f, 0.0f, 0.0f);
if (probeIrradianceBlendWeight > 0.0f)
@@ -102,8 +102,17 @@ namespace AZ
void DiffuseProbeGrid::SetProbeSpacing(const AZ::Vector3& probeSpacing)
{
// remove previous spacing from the render extents
m_renderExtents -= m_probeSpacing;
// update probe spacing
m_probeSpacing = probeSpacing;
// expand the extents by one probe spacing unit in order to blend properly around the edges of the volume
m_renderExtents += m_probeSpacing;
m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_renderExtents / 2.0f);
// recompute the number of probes since the spacing changed
UpdateProbeCount();
@@ -128,7 +137,8 @@ namespace AZ
void DiffuseProbeGrid::SetTransform(const AZ::Transform& transform)
{
m_transform = transform;
m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_extents / 2.0f);
m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_renderExtents / 2.0f);
// probes need to be relocated since the grid position changed
m_remainingRelocationIterations = DefaultNumRelocationIterations;
@@ -144,11 +154,15 @@ namespace AZ
void DiffuseProbeGrid::SetExtents(const AZ::Vector3& extents)
{
m_extents = extents;
m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_extents / 2.0f);
// recompute the number of probes since the extents changed
UpdateProbeCount();
// expand the extents by one probe spacing unit in order to blend properly around the edges of the volume
m_renderExtents = m_extents + m_probeSpacing;
m_obbWs = Obb::CreateFromPositionRotationAndHalfLengths(m_transform.GetTranslation(), m_transform.GetRotation(), m_renderExtents / 2.0f);
// probes need to be relocated since the grid extents changed
m_remainingRelocationIterations = DefaultNumRelocationIterations;
@@ -700,11 +714,11 @@ namespace AZ
RHI::ShaderInputImageIndex imageIndex;
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_modelToWorld"));
AZ::Matrix3x4 modelToWorld = AZ::Matrix3x4::CreateFromTransform(m_transform) * AZ::Matrix3x4::CreateScale(m_extents);
AZ::Matrix3x4 modelToWorld = AZ::Matrix3x4::CreateFromTransform(m_transform) * AZ::Matrix3x4::CreateScale(m_renderExtents);
m_renderObjectSrg->SetConstant(constantIndex, modelToWorld);
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_modelToWorldInverse"));
AZ::Matrix3x4 modelToWorldInverse = AZ::Matrix3x4::CreateFromTransform(m_transform).GetInverseFull();
AZ::Matrix3x4 modelToWorldInverse = modelToWorld.GetInverseFull();
m_renderObjectSrg->SetConstant(constantIndex, modelToWorldInverse);
constantIndex = srgLayout->FindShaderInputConstantIndex(Name("m_obbHalfLengths"));
@@ -183,11 +183,14 @@ namespace AZ
// extents of the probe grid
AZ::Vector3 m_extents = AZ::Vector3(0.0f, 0.0f, 0.0f);
// expanded extents for rendering the volume
AZ::Vector3 m_renderExtents = AZ::Vector3(0.0f, 0.0f, 0.0f);
// 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;
AZ::Vector3 m_probeSpacing = AZ::Vector3(0.0f, 0.0f, 0.0f);
// per-axis number of probes in the grid
uint32_t m_probeCountX = 0;