From ccd4cc65a542f7073338291f2588b1600d2bc994 Mon Sep 17 00:00:00 2001 From: yuriy0 Date: Fri, 16 Jul 2021 13:26:09 -0400 Subject: [PATCH] Use SampleLevel instead of Sample to sample shadow maps. (#1370) * Use SampleLevel instead of Sample to sample shadow maps. This allows shadow code to be used from computer shaders which don't allow Sample. Shadow maps don't have LODs anyways * Fix some very silly typos --- .../Features/Shadow/ProjectedShadow.azsli | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli index 80e23a43cf..4df17cde5d 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli @@ -239,9 +239,10 @@ float ProjectedShadow::GetVisibilityEsm() const float depth = PerspectiveDepthToLinear( m_shadowPosition.z, coefficients); - const float occluder = shadowmap.Sample( + const float occluder = shadowmap.SampleLevel( PassSrg::LinearSampler, - float3(atlasPosition.xy * invAtlasSize, atlasPosition.z)).r; + float3(atlasPosition.xy * invAtlasSize, atlasPosition.z), + /*LOD=*/0).r; const float exponent = -ViewSrg::m_projectedShadows[m_shadowIndex].m_esmExponent * (depth - occluder); const float ratio = exp(exponent); @@ -280,9 +281,10 @@ float ProjectedShadow::GetVisibilityEsmPcf() const float depth = PerspectiveDepthToLinear( m_shadowPosition.z, coefficients); - const float occluder = shadowmap.Sample( + const float occluder = shadowmap.SampleLevel( PassSrg::LinearSampler, - float3(atlasPosition.xy * invAtlasSize, atlasPosition.z)).r; + float3(atlasPosition.xy * invAtlasSize, atlasPosition.z), + /*LOD=*/0).r; const float exponent = -ViewSrg::m_projectedShadows[m_shadowIndex].m_esmExponent * (depth - occluder); float ratio = exp(exponent); @@ -321,8 +323,10 @@ float ProjectedShadow::GetThickness() { const float3 atlasPosition = GetAtlasPosition(m_shadowPosition.xy); - const float depthValue = shadowmap.Sample(PassSrg::LinearSampler, - float3(atlasPosition.xy * invAtlasSize, atlasPosition.z)).r; + const float depthValue = shadowmap.SampleLevel(PassSrg::LinearSampler, + float3(atlasPosition.xy * invAtlasSize, atlasPosition.z), + /*LOD=*/0 + ).r; const float viewSpaceThickness = abs(UnprojectDepth(m_shadowIndex, m_shadowPosition.z) - UnprojectDepth(m_shadowIndex, depthValue)); return viewSpaceThickness; @@ -375,9 +379,9 @@ bool ProjectedShadow::IsShadowed(float3 shadowPosition) shadowPosition.y >= 0 && shadowPosition.y * size < size - PixelMargin) { float3 atlasPosition = GetAtlasPosition(shadowPosition.xy); - const float depthInShadowmap = shadowmap.Sample( + const float depthInShadowmap = shadowmap.SampleLevel( PassSrg::LinearSampler, - float3(atlasPosition.xy * invAtlasSize, atlasPosition.z)).r; + float3(atlasPosition.xy * invAtlasSize, atlasPosition.z), /*LOD=*/0).r; const float depthDiff = depthInShadowmap - shadowPosition.z; float bias = ViewSrg::m_projectedShadows[m_shadowIndex].m_bias; if (depthDiff < -bias)