浏览代码

Fix depth bias in PCSS blocker search

/main
Antoine Lelievre 7 年前
当前提交
b03972ff
共有 1 个文件被更改,包括 12 次插入12 次删除
  1. 24
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/PCSS.hlsl

24
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/PCSS.hlsl


return abs((Reciever - Blocker) / Blocker);
}
bool BlockerSearch(inout real averageBlockerDepth, inout real numBlockers, real lightArea, real3 coord, float slice, real2 sampleJitter, real2 sampleBias, Texture2DArray shadowMap, SamplerState PointSampler, int sampleCount)
bool BlockerSearch(inout real averageBlockerDepth, inout real numBlockers, real lightArea, real3 coord, real2 sampleJitter, real2 sampleBias, ShadowContext shadowContext, float slice, uint texIdx, uint sampIdx, int sampleCount)
{
real blockerSum = 0.0;
for (int i = 0; i < sampleCount; ++i)

real shadowMapDepth = SAMPLE_TEXTURE2D_ARRAY_LOD( shadowMap, PointSampler, coord.xy + offset, slice, 0.0 ).x;
real shadowMapDepth = SampleShadow_T2DA(shadowContext, texIdx, sampIdx, coord.xy, slice).x;
if (COMPARE_DEVICE_DEPTH_CLOSER(shadowMapDepth, coord.z))
if (COMPARE_DEVICE_DEPTH_CLOSER(shadowMapDepth, coord.z + dot(sampleBias, offset)))
{
blockerSum += shadowMapDepth;
numBlockers += 1.0;

return numBlockers >= 1;
}
bool BlockerSearch(inout real averageBlockerDepth, inout real numBlockers, real lightArea, real3 coord, real2 sampleJitter, real2 sampleBias, ShadowContext shadowContext, float slice, uint texIdx, uint sampIdx, int sampleCount)
bool BlockerSearch(inout real averageBlockerDepth, inout real numBlockers, real lightArea, real3 coord, float slice, real2 sampleJitter, real2 sampleBias, Texture2DArray shadowMap, SamplerState PointSampler, int sampleCount)
{
real blockerSum = 0.0;
for (int i = 0; i < sampleCount; ++i)

real shadowMapDepth = SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(coord.xy, coord.z + dot(sampleBias, offset)), slice).x;
real shadowMapDepth = SAMPLE_TEXTURE2D_ARRAY_LOD(shadowMap, PointSampler, coord.xy + offset, slice, 0.0).x;
if (COMPARE_DEVICE_DEPTH_CLOSER(shadowMapDepth, coord.z))
if (COMPARE_DEVICE_DEPTH_CLOSER(shadowMapDepth, coord.z + dot(sampleBias, offset)))
{
blockerSum += shadowMapDepth;
numBlockers += 1.0;

return numBlockers >= 1;
}
real PCSS(real3 coord, real filterRadius, real4 scaleOffset, float slice, real2 sampleBias, real2 sampleJitter, Texture2DArray shadowMap, SamplerComparisonState compSampler, int sampleCount)
real PCSS(real3 coord, real filterRadius, real4 scaleOffset, float slice, real2 sampleBias, real2 sampleJitter, ShadowContext shadowContext, uint texIdx, uint sampIdx, int sampleCount)
{
real UMin = scaleOffset.z;
real UMax = scaleOffset.z + scaleOffset.x;

// Overfiltering will leak results from other shadow lights.
//TODO: Investigate moving this to blocker search.
if (U <= UMin || U >= UMax || V <= VMin || V >= VMax)
sum += SAMPLE_TEXTURE2D_ARRAY_SHADOW(shadowMap, compSampler, real3(coord.xy, coord.z), slice);
sum += SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(coord.xy, coord.z), slice);
sum += SAMPLE_TEXTURE2D_ARRAY_SHADOW(shadowMap, compSampler, real3(U, V, coord.z + dot(sampleBias, offset)), slice);
sum += SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(U, V, coord.z + dot(sampleBias, offset)), slice);
real PCSS(real3 coord, real filterRadius, real4 scaleOffset, float slice, real2 sampleBias, real2 sampleJitter, ShadowContext shadowContext, uint texIdx, uint sampIdx, int sampleCount)
real PCSS(real3 coord, real filterRadius, real4 scaleOffset, float slice, real2 sampleBias, real2 sampleJitter, Texture2DArray shadowMap, SamplerComparisonState compSampler, int sampleCount)
{
real UMin = scaleOffset.z;
real UMax = scaleOffset.z + scaleOffset.x;

// Overfiltering will leak results from other shadow lights.
//TODO: Investigate moving this to blocker search.
if (U <= UMin || U >= UMax || V <= VMin || V >= VMax)
sum += SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(coord.xy, coord.z), slice);
sum += SAMPLE_TEXTURE2D_ARRAY_SHADOW(shadowMap, compSampler, real3(coord.xy, coord.z), slice);
sum += SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(U, V, coord.z + dot(sampleBias, offset)), slice);
sum += SAMPLE_TEXTURE2D_ARRAY_SHADOW(shadowMap, compSampler, real3(U, V, coord.z + dot(sampleBias, offset)), slice);
}
return sum / sampleCount;
正在加载...
取消
保存