浏览代码

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
yuriy0 4 年之前
父节点
当前提交
ccd4cc65a5
共有 1 个文件被更改,包括 12 次插入8 次删除
  1. 12 8
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli

+ 12 - 8
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)