浏览代码

Optimize SSS with an early-out based on the distance and the radius

/Branch_Batching2
Evgenii Golubev 8 年前
当前提交
c0b4b9e8
共有 1 个文件被更改,包括 22 次插入11 次删除
  1. 33
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader

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


float2 unitDirection = float2(0, 1);
#endif
float2 scaledDirection = distScale * stepSize * unitDirection;
float scaledStepSize = distScale * stepSize;
float2 scaledDirection = scaledStepSize * unitDirection;
float phi = 0; // Random rotation; unused for now
float2x2 rotationMatrix = float2x2(cos(phi), -sin(phi), sin(phi), cos(phi));
float2 rotatedDirection = mul(rotationMatrix, scaledDirection);

float halfRcpVariance = _HalfRcpWeightedVariances[profileID].a;
#endif
#ifdef SSS_FILTER_HORIZONTAL_AND_COMBINE
bool performPostScatterTexturing = IsBitSet(_TexturingModeFlags, profileID);
// It's either post-scatter, or pre- and post-scatter texturing.
float3 albedoContrib = performPostScatterTexturing ? bsdfData.diffuseColor
: sqrt(bsdfData.diffuseColor);
#else
float3 albedoContrib = float3(1, 1, 1);
#endif
// The max. value of the scattering distance is 2. We perform point sampling.
// Therefore, we do not need to perform filtering if (scaledStepSize * 2 < 0.5).
// This is a conservative estimate.
[branch]
if (scaledStepSize < 0.25)
{
return float4(albedoContrib * sampleIrradiance, 1);
}
// Accumulate filtered irradiance.
float3 totalIrradiance = sampleWeight * sampleIrradiance;

totalWeight += sampleWeight;
}
#ifdef SSS_FILTER_HORIZONTAL_AND_COMBINE
bool performPostScatterTexturing = IsBitSet(_TexturingModeFlags, profileID);
// It's either post-scatter, or pre- and post-scatter texturing.
float3 diffuseContrib = performPostScatterTexturing ? bsdfData.diffuseColor
: sqrt(bsdfData.diffuseColor);
return float4(diffuseContrib * totalIrradiance / totalWeight, 1.0);
#else
return float4(totalIrradiance / totalWeight, 1.0);
#endif
return float4(albedoContrib * totalIrradiance / totalWeight, 1);
}
ENDHLSL
}

正在加载...
取消
保存