浏览代码

Merge pull request #183 from EvgeniiG/master

Improve the quality of SSS
/fptl_cleanup
GitHub 8 年前
当前提交
525f5a64
共有 4 个文件被更改,包括 15 次插入11 次删除
  1. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 10
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  3. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs
  4. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


m_FilterSubsurfaceScattering.SetFloat("_DstBlend", (float)BlendMode.Zero);
m_FilterAndCombineSubsurfaceScattering = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/CombineSubsurfaceScattering");
m_FilterSubsurfaceScattering.EnableKeyword("FILTER_HORIZONTAL_AND_COMBINE");
m_FilterAndCombineSubsurfaceScattering.EnableKeyword("FILTER_HORIZONTAL_AND_COMBINE");
m_FilterAndCombineSubsurfaceScattering.SetFloat("_DstBlend", (float)BlendMode.One);
InitializeDebugMaterials();

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


//-------------------------------------------------------------------------------------
#define N_PROFILES 8
#define N_SAMPLES 7
#define N_SAMPLES 11
float4 _FilterKernels[N_PROFILES][N_SAMPLES]; // RGB = weights, A = radial distance
float4 _HalfRcpWeightedVariances[N_PROFILES]; // RGB for chromatic, A for achromatic

float stepSize = stepSizeY;
float2 unitDirection = float2(0, 1);
#endif
float2 scaledDirection = distScale * stepSize * unitDirection;
float2 scaledDirection = distScale * stepSize * 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);
// Load (1 / (2 * WeightedVariance)) for bilateral weighting.
#ifdef RBG_BILATERAL_WEIGHTS

[unroll]
for (int i = 1; i < N_SAMPLES; i++)
{
samplePosition = posInput.unPositionSS + scaledDirection * _FilterKernels[profileID][i].a;
samplePosition = posInput.unPositionSS + rotatedDirection * _FilterKernels[profileID][i].a;
sampleWeight = _FilterKernels[profileID][i].rgb;
rawDepth = LOAD_TEXTURE2D(_MainDepthTexture, samplePosition).r;

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs


[Serializable]
public class SubsurfaceScatteringProfile
{
public const int numSamples = 7; // Must be an odd number
public const int numSamples = 11; // Must be an odd number
[SerializeField, ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
public Color stdDev1;

public void UpdateKernelAndVarianceData()
{
if (m_FilterKernel == null)
if (m_FilterKernel == null || m_FilterKernel.Length != numSamples)
{
m_FilterKernel = new Vector4[numSamples];
}

// as a product of a linear combination of two normalized 1D Gaussians
// as suggested by Jimenez et al. in "Separable Subsurface Scattering".
// A normalized (i.e. energy-preserving) 1D Gaussian with the mean of 0
// is defined as follows: G1(x, v) = exp(-x / (2 * v)) / sqrt(2 * Pi * v),
// is defined as follows: G1(x, v) = exp(-x * x / (2 * v)) / sqrt(2 * Pi * v),
// where 'v' is variance and 'x' is the radial distance from the origin.
// Using the weight 'w', our 1D and the resulting 2D filters are given as:
// A1(v1, v2, w, x) = G1(x, v1) * (1 - w) + G1(r, v2) * w,

halfRcpWeightedVariances = new Vector4[maxNumProfiles];
}
if (filterKernels == null)
if (filterKernels == null || filterKernels.Length != (maxNumProfiles * SubsurfaceScatteringProfile.numSamples))
{
filterKernels = new Vector4[maxNumProfiles * SubsurfaceScatteringProfile.numSamples];
}

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl


// to represent the position of the primary (scene view) camera in order to
// have identical tessellation levels for both the scene view and shadow views.
// Otherwise, depth comparisons become meaningless!
float4x4 viewMat = transpose(GetWorldToViewMatrix());
float3 rotCamPos = viewMat[3].xyz;
return mul((float3x3)viewMat, -rotCamPos);
float4x4 trViewMat = transpose(GetWorldToViewMatrix());
float3 rotCamPos = trViewMat[3].xyz;
return mul((float3x3)trViewMat, -rotCamPos);
#endif
}

正在加载...
取消
保存