浏览代码

Added a field to control sampleCount in the inspector

/main
Antoine Lelievre 7 年前
当前提交
f53d652d
共有 5 个文件被更改,包括 55 次插入57 次删除
  1. 62
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/PCSS.hlsl
  2. 33
      com.unity.render-pipelines.core/CoreRP/ShaderLibrary/Shadow/ShadowSampling.hlsl
  3. 2
      com.unity.render-pipelines.core/CoreRP/Shadow/AdditionalShadowData.cs
  4. 3
      com.unity.render-pipelines.core/CoreRP/Shadow/Shadow.cs
  5. 12
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs

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


static const float2 PoissonDisk64[64] =
static const float2 poissonDisk64[64] =
{
float2 ( 0.1187053, 0.7951565),
float2 ( 0.1173675, 0.6087878),

return abs((Reciever - Blocker) / Blocker);
}
bool BlockerSearch(inout real AverageBlockerDepth, inout real NumBlockers, real LightArea, real3 coord, float slice, real2 sampleBias, Texture2DArray shadowMap, SamplerState PointSampler, int sampleCount )
bool BlockerSearch(inout real averageBlockerDepth, inout real numBlockers, real lightArea, real3 coord, float slice, real2 sampleBias, Texture2DArray shadowMap, SamplerState PointSampler, int sampleCount)
return 0;
real BlockerSum = 0.0;
for (int i = 0; i < 64; ++i)
real blockerSum = 0.0;
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;
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
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;
real shadowMapDepth = SAMPLE_TEXTURE2D_ARRAY_LOD( shadowMap, PointSampler, coord.xy + offset, slice, 0.0 ).x;
if(ShadowMapDepth > coord.z)
if(shadowMapDepth > coord.z)
BlockerSum += ShadowMapDepth;
NumBlockers += 1.0;
blockerSum += shadowMapDepth;
numBlockers += 1.0;
AverageBlockerDepth = BlockerSum / NumBlockers;
averageBlockerDepth = blockerSum / numBlockers;
if (NumBlockers < 1)
if (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 )
bool BlockerSearch(inout real averageBlockerDepth, inout real numBlockers, real lightArea, real3 coord, real2 sampleBias, ShadowContext shadowContext, float slice, uint texIdx, uint sampIdx, int sampleCount)
return 0;
real BlockerSum = 0.0;
for (int i = 0; i < 64; ++i)
real blockerSum = 0.0;
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;
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * lightArea;
real ShadowMapDepth = SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, coord.xyz, slice).x;
real shadowMapDepth = SampleCompShadow_T2DA(shadowContext, texIdx, sampIdx, coord.xyz, slice).x;
if(ShadowMapDepth > coord.z)
if(shadowMapDepth > coord.z)
BlockerSum += ShadowMapDepth;
NumBlockers += 1.0;
blockerSum += shadowMapDepth;
numBlockers += 1.0;
AverageBlockerDepth = BlockerSum / NumBlockers;
averageBlockerDepth = blockerSum / numBlockers;
if (NumBlockers < 1)
if (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, Texture2DArray shadowMap, SamplerComparisonState compSampler, int sampleCount)
return 0;
real UMin = scaleOffset.z;
real UMax = scaleOffset.z + scaleOffset.x;

real Sum = 0.0;
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) * filterRadius;
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * filterRadius;
real U = coord.x + offset.x;
real V = coord.y + offset.y;

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, ShadowContext shadowContext, uint texIdx, uint sampIdx, int sampleCount)
return 0;
real UMin = scaleOffset.z;
real UMax = scaleOffset.z + scaleOffset.x;

real Sum = 0.0;
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) * filterRadius;
real2 offset = real2(poissonDisk64[i].x * sampleBias.y + poissonDisk64[i].y * sampleBias.x,
poissonDisk64[i].x * -sampleBias.x + poissonDisk64[i].y * sampleBias.y) * filterRadius;
real U = coord.x + offset.x;
real V = coord.y + offset.y;

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


real SampleShadow_PCSS( ShadowContext shadowContext, inout uint payloadOffset, real3 tcs, real4 scaleOffset, real2 sampleBias, float slice, uint texIdx, uint sampIdx )
{
return 1;
real2 SampleBias = real2(sin(GenerateHashedRandomFloat(asuint(tcs.x))),
cos(GenerateHashedRandomFloat(asuint(tcs.y))));
real AverageBlockerDepth = 0.0;
real NumBlockers = 0.0;
if (!BlockerSearch(AverageBlockerDepth, NumBlockers, shadowSoftnesss + 0.001, tcs, sampleBias, shadowContext, slice, texIdx, sampIdx, sampleCount))
real averageBlockerDepth = 0.0;
real numBlockers = 0.0;
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.001, tcs, sampleBias, shadowContext, slice, texIdx, sampIdx, sampleCount))
real FilterSize = shadowSoftnesss * PenumbraSize(tcs.z, AverageBlockerDepth);
FilterSize = max(FilterSize, 0.001);
real filterSize = shadowSoftnesss * PenumbraSize(tcs.z, averageBlockerDepth);
filterSize = max(filterSize, 0.001);
return PCSS(tcs, FilterSize, scaleOffset, slice, SampleBias, shadowContext, texIdx, sampIdx, sampleCount);
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, shadowContext, texIdx, sampIdx, sampleCount);
return 1;
real2 SampleBias = real2(sin(GenerateHashedRandomFloat(asuint(tcs.x))),
real2 sampleBias = real2(sin(GenerateHashedRandomFloat(asuint(tcs.x))),
real AverageBlockerDepth = 0.0;
real NumBlockers = 0.0;
// if (!BlockerSearch(AverageBlockerDepth, NumBlockers, shadowSoftnesss + 0.001, tcs, slice, SampleBias, tex, samp, sampleCount))
// return 1.0;
real averageBlockerDepth = 0.0;
real numBlockers = 0.0;
if (!BlockerSearch(averageBlockerDepth, numBlockers, shadowSoftnesss + 0.001, tcs, slice, sampleBias, tex, samp, sampleCount))
return 1.0;
real FilterSize = shadowSoftnesss * PenumbraSize(tcs.z, AverageBlockerDepth);
FilterSize = max(FilterSize, 0.001);
real filterSize = shadowSoftnesss * PenumbraSize(tcs.z, averageBlockerDepth);
filterSize = max(filterSize, 0.001);
return PCSS(tcs, FilterSize, scaleOffset, slice, SampleBias, tex, compSamp, sampleCount);
return PCSS(tcs, filterSize, scaleOffset, slice, sampleBias, tex, compSamp, sampleCount);
}
//-----------------------------------------------------------------------------------------------------

2
com.unity.render-pipelines.core/CoreRP/Shadow/AdditionalShadowData.cs


// PCSS specific parameters (can be moved somewhere else)
[Range(0.0f, 1.0f)]
public float shadowSoftness = 0.5f;
[Range(0, 64)]
[Range(1, 64)]
public int sampleCount = 32;
// End of PCSS parameters

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


readonly ValRange m_DefPCF_FilterSize = new ValRange("Filter Size", 1.0f, 1.0f, 10.0f, 1.0f);
readonly ValRange m_DefPCSS_ShadowSoftness = new ValRange("Shadow Softness", 0.0f, 0.5f, 1.0f, 0.01f);
readonly ValRange m_DefPCSS_SampleCount = new ValRange("Sample Count", 0, 32, 64, 1);
readonly ValRange m_DefPCSS_SampleCount = new ValRange("Sample Count", 1, 32, 64, 1);
public ShadowAtlas(ref AtlasInit init) : base(ref init.baseInit)

m_DefPCSS_ShadowSoftness.Slider(ref dataBlock[0]);
m_DefPCSS_SampleCount.Slider(ref dataBlock[1]);
dataBlock[1] = ShadowUtils.Asint(Mathf.RoundToInt(ShadowUtils.Asfloat(dataBlock[1])));
};
registry.Register(type, precision, ShadowAlgorithm.PCF, "Percentage Closer Filtering (PCF)",

12
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs


EditorGUILayout.LabelField("Additional Settings", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
//TOOD: check the current shadowing algorithm and hide these fields
EditorGUILayout.Slider(m_AdditionalShadowData.softness, 0.0f, 1.0f, s_Styles.shadowSoftness);
EditorGUILayout.IntSlider(m_AdditionalShadowData.pcssSampleCount, 0, 64, s_Styles.pcssSampleCount);
int shadowAlgorithm, variant, precision;
(target as Light).GetComponent< AdditionalShadowData >().GetShadowAlgorithm(out shadowAlgorithm, out variant, out precision);
if (shadowAlgorithm == (int)ShadowAlgorithm.PCSS)
{
//TOOD: check the current shadowing algorithm and hide these fields
EditorGUILayout.Slider(m_AdditionalShadowData.softness, 0.0f, 1.0f, s_Styles.shadowSoftness);
EditorGUILayout.IntSlider(m_AdditionalShadowData.pcssSampleCount, 1, 64, s_Styles.pcssSampleCount);
}
EditorGUILayout.PropertyField(m_AdditionalShadowData.contactShadows, s_Styles.contactShadows);

正在加载...
取消
保存