|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|