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
This commit is contained in:
yuriy0
2021-07-16 13:26:09 -04:00
committed by GitHub
parent 4407891740
commit ccd4cc65a5
@@ -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)