浏览代码

Factor out 'halfRcpVariance'

/Branch_Batching2
Evgenii Golubev 8 年前
当前提交
e5974544
共有 3 个文件被更改,包括 27 次插入16 次删除
  1. 10
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  2. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader
  3. 26
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs

10
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


// Currently, forward-rendered objects do not output split lighting required for the SSS pass.
if (m_Owner.renderingParameters.ShouldUseForwardRenderingOnly()) return;
// Load the kernel data.
Vector4[] kernelData = new Vector4[SubsurfaceScatteringParameters.maxNumProfiles * SubsurfaceScatteringProfile.numVectors];
// Load the kernel and variance data.
Vector4[] kernelData = new Vector4[SubsurfaceScatteringParameters.maxNumProfiles * SubsurfaceScatteringProfile.numSamples];
Vector4[] varianceData = new Vector4[SubsurfaceScatteringParameters.maxNumProfiles];
for (int i = 0, n = SubsurfaceScatteringProfile.numVectors; i < n; i++)
for (int i = 0, n = SubsurfaceScatteringProfile.numSamples; i < n; i++)
varianceData[j] = sssParameters.profiles[j].halfRcpVariance;
}
var cmd = new CommandBuffer() { name = "Subsurface Scattering Pass" };

m_FilterSubsurfaceScattering.SetVectorArray("_FilterKernels", kernelData);
m_FilterSubsurfaceScattering.SetVectorArray("_HalfRcpVariances", varianceData);
cmd.SetGlobalTexture("_IrradianceSource", m_CameraSubsurfaceBufferRT);
Utilities.DrawFullScreen(cmd, m_FilterSubsurfaceScattering, hdCamera,
m_CameraFilteringBufferRT, m_CameraStencilBufferRT);

m_FilterAndCombineSubsurfaceScattering.SetVectorArray("_FilterKernels", kernelData);
m_FilterAndCombineSubsurfaceScattering.SetVectorArray("_HalfRcpVariances", varianceData);
cmd.SetGlobalTexture("_IrradianceSource", m_CameraFilteringBufferRT);
Utilities.DrawFullScreen(cmd, m_FilterAndCombineSubsurfaceScattering, hdCamera,
m_CameraColorBufferRT, m_CameraStencilBufferRT);

7
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Resources/CombineSubsurfaceScattering.shader


#define N_PROFILES 8
#define N_SAMPLES 7
float4 _FilterKernels[N_PROFILES][N_SAMPLES + 1]; // RGB = weights, A = radial distance
float4 _FilterKernels[N_PROFILES][N_SAMPLES]; // RGB = weights, A = radial distance
float4 _HalfRcpVariances[N_PROFILES]; // RGB for chromatic, A for achromatic
float4x4 _InvProjMatrix;
TEXTURE2D_FLOAT(_CameraDepthTexture);

// Load (1 / (2 * Variance)) for bilateral weighting.
#ifdef RBG_BILATERAL_WEIGHTS
float3 halfRcpVariance = _FilterKernels[profileID][N_SAMPLES].rgb;
float3 halfRcpVariance = _HalfRcpVariances[profileID].rgb;
float halfRcpVariance = _FilterKernels[profileID][N_SAMPLES].a;
float halfRcpVariance = _HalfRcpVariances[profileID].a;
#endif
// Take the first (central) sample.
float2 samplePosition = posInput.unPositionSS;

26
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs


public class SubsurfaceScatteringProfile
{
public const int numSamples = 7; // Must be an odd number
public const int numVectors = 8; // numSamples + 1 for (1 / (2 * WeightedVariance))
[SerializeField, ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_StdDev1;
[SerializeField, ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]

[SerializeField]
[SerializeField] [HideInInspector]
[SerializeField]
[SerializeField] [HideInInspector]
Vector4 m_HalfRcpVariance;
[SerializeField] [HideInInspector]
public bool m_KernelNeedsUpdate;
// --- Public Methods ---

get { if (m_KernelNeedsUpdate) ComputeKernel(); return m_FilterKernel; }
}
public Vector4 halfRcpVariance
{
get { if (m_KernelNeedsUpdate) ComputeKernel(); return m_HalfRcpVariance; }
}
public void SetDirtyFlag()
{
m_KernelNeedsUpdate = true;

void ComputeKernel()
{
if (m_FilterKernel == null || m_FilterKernel.Length != numVectors)
if (m_FilterKernel == null || m_FilterKernel.Length != numSamples)
m_FilterKernel = new Vector4[numVectors];
m_FilterKernel = new Vector4[numSamples];
}
// Our goal is to blur the image using a filter which is represented

weightedStdDev.w = Mathf.Lerp(maxStdDev1, maxStdDev2, m_LerpWeight);
// Store (1 / (2 * Variance)) per color channel.
m_FilterKernel[numSamples].x = 0.5f / (weightedStdDev.x * weightedStdDev.x);
m_FilterKernel[numSamples].y = 0.5f / (weightedStdDev.y * weightedStdDev.y);
m_FilterKernel[numSamples].z = 0.5f / (weightedStdDev.z * weightedStdDev.z);
m_FilterKernel[numSamples].w = 0.5f / (weightedStdDev.w * weightedStdDev.w);
m_HalfRcpVariance.x = 0.5f / (weightedStdDev.x * weightedStdDev.x);
m_HalfRcpVariance.y = 0.5f / (weightedStdDev.y * weightedStdDev.y);
m_HalfRcpVariance.z = 0.5f / (weightedStdDev.z * weightedStdDev.z);
m_HalfRcpVariance.w = 0.5f / (weightedStdDev.w * weightedStdDev.w);
}
}

正在加载...
取消
保存