浏览代码

Cleanup code and inconsistencies

/main
Antoine Lelievre 6 年前
当前提交
8120bd8f
共有 3 个文件被更改,包括 31 次插入32 次删除
  1. 40
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/PCSS.hlsl
  2. 19
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/ShadowSampling.hlsl
  3. 4
      com.unity.render-pipelines.core/CoreRP/Shadow/Shadow.cs

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


for (int i = 0; i < sampleCount; ++i)
{
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * lightArea;
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * lightArea;
real shadowMapDepth = SAMPLE_TEXTURE2D_ARRAY_LOD( shadowMap, PointSampler, coord.xy + offset, slice, 0.0 ).x;

}
averageBlockerDepth = blockerSum / numBlockers;
if (numBlockers < 1)
return false;
return true;
return numBlockers >= 1;
}
bool BlockerSearch(inout real averageBlockerDepth, inout real numBlockers, real lightArea, real3 coord, real2 sampleBias, ShadowContext shadowContext, float slice, uint texIdx, uint sampIdx, int sampleCount)

{
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * lightArea;
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * lightArea;
real shadowMapDepth = SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, coord.xyz, slice).x;

}
averageBlockerDepth = blockerSum / numBlockers;
if (numBlockers < 1)
return false;
return true;
return numBlockers >= 1;
real PCSS(real3 coord, real filterRadius, real4 scaleOffset, float slice, real2 sampleBias, Texture2DArray shadowMap, SamplerComparisonState compSampler, 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;

real Sum = 0.0;
real sum = 0.0;
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * filterRadius;
real2 offset = real2(poissonDisk64[i].x * sampleJitter.y + poissonDisk64[i].y * sampleJitter.x,
poissonDisk64[i].x * -sampleJitter.x + poissonDisk64[i].y * sampleJitter.y) * filterRadius;
real U = coord.x + offset.x;
real V = coord.y + offset.y;

//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 += SAMPLE_TEXTURE2D_ARRAY_SHADOW(shadowMap, compSampler, real3(coord.xy, coord.z), slice);
Sum += SAMPLE_TEXTURE2D_ARRAY_SHADOW(shadowMap, compSampler, real3(U, V, coord.z), slice);
sum += SAMPLE_TEXTURE2D_ARRAY_SHADOW(shadowMap, compSampler, real3(U, V, coord.z + dot(sampleBias, offset)), slice);
return Sum / sampleCount;
return sum / sampleCount;
real PCSS(real3 coord, real filterRadius, real4 scaleOffset, float slice, real2 sampleBias, ShadowContext shadowContext, uint texIdx, uint sampIdx, 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;

real Sum = 0.0;
real sum = 0.0;
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * filterRadius;
real2 offset = real2(poissonDisk64[i].x * sampleJitter.y + poissonDisk64[i].y * sampleJitter.x,
poissonDisk64[i].x * -sampleJitter.x + poissonDisk64[i].y * sampleJitter.y) * filterRadius;
real U = coord.x + offset.x;
real V = coord.y + offset.y;

//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 += SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(coord.xy, coord.z), slice);
Sum += SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(U, V, coord.z), slice);
sum += SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, real3(U, V, coord.z + dot(sampleBias, offset)), slice);
return Sum / sampleCount;
return sum / sampleCount;
}

19
com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/ShadowSampling.hlsl


real shadowSoftnesss = params.x;
int sampleCount = params.y;
payloadOffset++;
real2 sampleJitter = real2(sin(GenerateHashedRandomFloat(tcs.x)),
cos(GenerateHashedRandomFloat(tcs.y)));
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.000001, tcs, sampleBias, shadowContext, slice, texIdx, sampIdx, sampleCount))
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.000001, tcs, sampleJitter, shadowContext, slice, texIdx, sampIdx, sampleCount))
return 1.0;
//2) Penumbra Estimation

//3) Filter
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, shadowContext, texIdx, sampIdx, sampleCount);
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, sampleJitter, shadowContext, texIdx, sampIdx, sampleCount);
real SampleShadow_PCSS( ShadowContext shadowContext, inout uint payloadOffset, real3 tcs, real4 scaleOffset, float slice, Texture2DArray tex, SamplerComparisonState compSamp, SamplerState samp )
real SampleShadow_PCSS( ShadowContext shadowContext, inout uint payloadOffset, real3 tcs, real4 scaleOffset, real2 sampleBias, float slice, Texture2DArray tex, SamplerComparisonState compSamp, SamplerState samp )
{
real2 params = asfloat(shadowContext.payloads[payloadOffset].xy);
real shadowSoftnesss = params.x;

real2 sampleBias = real2(sin(GenerateHashedRandomFloat(asuint(tcs.x))),
cos(GenerateHashedRandomFloat(asuint(tcs.y))));
real2 sampleJitter = real2(sin(GenerateHashedRandomFloat(tcs.x)),
cos(GenerateHashedRandomFloat(tcs.y)));
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.000001, tcs, slice, sampleBias, tex, samp, sampleCount))
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.000001, tcs, slice, sampleJitter, tex, samp, sampleCount))
return 1.0;
//2) Penumbra Estimation

//3) Filter
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, tex, compSamp, sampleCount);
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, sampleJitter, tex, compSamp, sampleCount);
}
//-----------------------------------------------------------------------------------------------------

case GPUSHADOWALGORITHM_PCF_TENT_3X3 : return SampleShadow_PCF_Tent_3x3( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, tex, compSamp );
case GPUSHADOWALGORITHM_PCF_TENT_5X5 : return SampleShadow_PCF_Tent_5x5( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, tex, compSamp );
case GPUSHADOWALGORITHM_PCF_TENT_7X7 : return SampleShadow_PCF_Tent_7x7( shadowContext, payloadOffset, shadowData.textureSize, shadowData.texelSizeRcp, posTC, sampleBias, shadowData.slice, tex, compSamp );
case GPUSHADOWALGORITHM_PCSS : return SampleShadow_PCSS( shadowContext, payloadOffset, posTC, shadowData.scaleOffset, shadowData.slice, tex, compSamp, s_point_clamp_sampler );
case GPUSHADOWALGORITHM_PCSS : return SampleShadow_PCSS( shadowContext, payloadOffset, posTC, shadowData.scaleOffset, sampleBias, shadowData.slice, tex, compSamp, s_point_clamp_sampler );
default: return 1.0;
}

4
com.unity.render-pipelines.core/CoreRP/Shadow/Shadow.cs


m_SupportedAlgorithms.AddUniqueUnchecked((int)ShadowUtils.Pack(ShadowAlgorithm.PCF, ShadowVariant.V2, precision));
m_SupportedAlgorithms.AddUniqueUnchecked((int)ShadowUtils.Pack(ShadowAlgorithm.PCF, ShadowVariant.V3, precision));
m_SupportedAlgorithms.AddUniqueUnchecked((int)ShadowUtils.Pack(ShadowAlgorithm.PCF, ShadowVariant.V4, precision));
m_SupportedAlgorithms.AddUniqueUnchecked((int)ShadowUtils.Pack(ShadowAlgorithm.PCSS, ShadowVariant.V0, precision)); //TODO: Consider the highest precision for blocker search.
m_SupportedAlgorithms.AddUniqueUnchecked((int)ShadowUtils.Pack(ShadowAlgorithm.PCSS, ShadowVariant.V0, precision));
ShadowRegistry.VariantDelegate del = (Light l, ShadowAlgorithm dataAlgorithm, ShadowVariant dataVariant, ShadowPrecision dataPrecision, ref int[] dataBlock) =>
{

break;
}
}
else // PCSS
else if (algo == ShadowAlgorithm.PCSS)
{
sp.Set(shadowData[0], shadowData[1], 0, 0);
payload[payloadOffset] = sp;

正在加载...
取消
保存