浏览代码

Improve the performance and the quality of the SSS pass

/Branch_Batching2
Evgenii Golubev 7 年前
当前提交
08b5e482
共有 2 个文件被更改,包括 49 次插入3 次删除
  1. 46
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  2. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs

46
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


// TODO: ask Morten if there is a better way to do this.
float3 totalWeight = sampleWeight;
[unroll]
for (int i = 1; i < N_SAMPLES; i++)
uint i; // Sample index
[unroll] // Gather samples from the center to the left (up).
for (i = 1; i <= N_SAMPLES / 2; i++)
{
samplePosition = posInput.unPositionSS + rotatedDirection * _FilterKernels[profileID][i].a;
sampleWeight = _FilterKernels[profileID][i].rgb;

if (any(sampleIrradiance) == false)
{
// The irradiance is 0. There could be two reasons for this.
// Most likely, the surface fragment does not have an SSS material.
// Alternatively, the surface fragment could be completely shadowed.
// Our blur is energy-preserving, so 'sampleWeight' should be 0.
// We can save some bandwidth by terminating the loop early.
break;
}
// Apply bilateral weighting.
// Ref #1: Skin Rendering by Pseudo–Separable Cross Bilateral Filtering.
// Ref #2: Separable SSS, Supplementary Materials, Section E.
float sampleDepth = LinearEyeDepth(rawDepth, _ZBufferParams);
float zDistance = invDistScale * sampleDepth - (invDistScale * centerPosVS.z);
sampleWeight *= exp(-zDistance * zDistance * halfRcpVariance);
totalIrradiance += sampleWeight * sampleIrradiance;
totalWeight += sampleWeight;
}
[unroll] // Gather samples from the center to the right (down).
for (; i < N_SAMPLES; i++)
{
samplePosition = posInput.unPositionSS + rotatedDirection * _FilterKernels[profileID][i].a;
sampleWeight = _FilterKernels[profileID][i].rgb;
rawDepth = LOAD_TEXTURE2D(_MainDepthTexture, samplePosition).r;
sampleIrradiance = LOAD_TEXTURE2D(_IrradianceSource, samplePosition).rgb;
if (any(sampleIrradiance) == false)
{
// The irradiance is 0. There could be two reasons for this.
// Most likely, the surface fragment does not have an SSS material.
// Alternatively, the surface fragment could be completely shadowed.
// Our blur is energy-preserving, so 'sampleWeight' should be 0.
// We can save some bandwidth by terminating the loop early.
break;
}
// Apply bilateral weighting.
// Ref #1: Skin Rendering by Pseudo–Separable Cross Bilateral Filtering.

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs


Vector3 weightSum = new Vector3(0, 0, 0);
float rcpNumSamples = 1.0f / numSamples;
float u = (i + 0.5f) / numSamples;
float u = (i <= numSamples / 2) ? 0.5f - i * rcpNumSamples // The center and to the left
: (i + 0.5f) * rcpNumSamples; // From the center to the right
float pos = GaussianCombinationCdfInverse(u, maxStdDev1, maxStdDev2, lerpWeight);
float pdf = GaussianCombination(pos, maxStdDev1, maxStdDev2, lerpWeight);

正在加载...
取消
保存