浏览代码

Add thickness scale to the profile information

/Branch_Batching2
Evgenii Golubev 8 年前
当前提交
92b18150
共有 3 个文件被更改,包括 37 次插入16 次删除
  1. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 5
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  3. 47
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


// Broadcast SSS parameters to all shaders.
Shader.SetGlobalInt("_TransmittanceFlags", sssParameters.transmittanceFlags);
Shader.SetGlobalFloatArray("_ThicknessScales", sssParameters.thicknessScales);
Shader.SetGlobalVectorArray("_HalfRcpVariancesAndLerpWeights", sssParameters.halfRcpVariancesAndLerpWeights);
var cmd = new CommandBuffer {name = "Push Global Parameters"};

5
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


// SSS parameters
#define N_PROFILES 8
uint _TransmittanceFlags; // One bit per profile; 1 = enabled
float _ThicknessScales[N_PROFILES];
float4 _HalfRcpVariancesAndLerpWeights[N_PROFILES][2]; // 2x Gaussians per color channel, A is the the associated interpolation weight
//-----------------------------------------------------------------------------

bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
bsdfData.subsurfaceRadius = surfaceData.subsurfaceRadius * 0.01;
bsdfData.thickness = surfaceData.thickness * (0.01 * 3);
bsdfData.thickness = surfaceData.thickness * 0.01 * _ThicknessScales[bsdfData.subsurfaceProfile];
bsdfData.subsurfaceProfile = surfaceData.subsurfaceProfile;
bsdfData.enableTransmittance = (1 << bsdfData.subsurfaceProfile) & _TransmittanceFlags;
if (bsdfData.enableTransmittance)

bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
bsdfData.subsurfaceRadius = inGBuffer2.r * 0.01;
bsdfData.thickness = inGBuffer2.g * (0.01 * 3);
bsdfData.thickness = inGBuffer2.g * 0.01 * _ThicknessScales[bsdfData.subsurfaceProfile];
bsdfData.subsurfaceProfile = inGBuffer2.a * 8.0;
bsdfData.enableTransmittance = (1 << bsdfData.subsurfaceProfile) & _TransmittanceFlags;
if (bsdfData.enableTransmittance)

47
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs


public float lerpWeight;
[SerializeField]
public bool enableTransmittance;
[SerializeField]
public float thicknessScale;
[SerializeField] [HideInInspector]
Vector4[] m_FilterKernel;
[SerializeField] [HideInInspector]

stdDev2 = new Color(1.0f, 1.0f, 1.0f, 0.0f);
lerpWeight = 0.5f;
enableTransmittance = false;
m_FilterKernel = null;
m_HalfRcpVariances = null;
thicknessScale = 3.0f;
UpdateKernelAndVarianceData();
}

}
public Vector3[] halfRcpVariances
{
{
// Set via UpdateKernelAndVarianceData().
get { return m_HalfRcpVariances; }
}

float maxStdDev1 = Mathf.Max(stdDev1.r, stdDev1.g, stdDev1.b);
float maxStdDev2 = Mathf.Max(stdDev2.r, stdDev2.g, stdDev2.b);
Vector3 weightSum = new Vector3(0, 0, 0);
Vector3 weightSum = new Vector3(0, 0, 0);
// Importance sample the linear combination of two Gaussians.
for (uint i = 0; i < numSamples; i++)

m_HalfRcpWeightedVariances.z = 0.5f / (weightedStdDev.z * weightedStdDev.z);
m_HalfRcpWeightedVariances.w = 0.5f / (weightedStdDev.w * weightedStdDev.w);
}
// --- Private Methods ---
static float Gaussian(float x, float stdDev)

float[] d = {1.432788f, 0.189269f, 0.001308f};
return t - ((c[2] * t + c[1]) * t + c[0]) / (((d[2] * t + d[1]) * t + d[0]) * t + 1.0f);
}
// Ref: https://www.johndcook.com/blog/csharp_phi_inverse/
static float NormalCdfInverse(float p, float stdDev)
{

int m_TransmittanceFlags;
[SerializeField]
SubsurfaceScatteringProfile[] m_Profiles;
[SerializeField]
float[] m_ThicknessScales;
[SerializeField]
Vector4[] m_HalfRcpVariancesAndLerpWeights;
[SerializeField]

get { return m_TransmittanceFlags; }
}
// Supplies '_ThicknessScales' to Lit.hlsl.
public float[] thicknessScales
{
// Set during OnValidate().
get { return m_ThicknessScales; }
}
}
}
}
}
get { return m_FilterKernels; }
get { return m_FilterKernels; }
}
// --- Private Methods ---

m_NumProfiles = m_Profiles.Length;
m_TransmittanceFlags = 0;
if (m_ThicknessScales == null)
{
m_ThicknessScales = new float[maxNumProfiles];
}
if (m_HalfRcpVariancesAndLerpWeights == null)
{

m_Profiles[i].lerpWeight = Mathf.Clamp01(m_Profiles[i].lerpWeight);
m_Profiles[i].thicknessScale = Mathf.Max(0.0f, m_Profiles[i].thicknessScale);
m_Profiles[i].UpdateKernelAndVarianceData();
}

m_ThicknessScales[i] = m_Profiles[i].thicknessScale;
m_HalfRcpVariancesAndLerpWeights[2 * i] = m_Profiles[i].halfRcpVariances[0];
m_HalfRcpVariancesAndLerpWeights[2 * i].w = 1.0f - m_Profiles[i].lerpWeight;
m_HalfRcpVariancesAndLerpWeights[2 * i + 1] = m_Profiles[i].halfRcpVariances[1];

{
private class Styles
{
public readonly GUIContent sssCategory = new GUIContent("Subsurface scattering");
public readonly GUIContent sssProfileStdDev1 = new GUIContent("Standard deviation #1", "Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileStdDev2 = new GUIContent("Standard deviation #2", "Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileLerpWeight = new GUIContent("Filter interpolation", "Controls linear interpolation between the two Gaussian filters.");
public readonly GUIContent sssProfileTransmittance = new GUIContent("Enable transmittance", "Toggles simulation of light passing through thin objects. Depends on the thickness of the material.");
public readonly GUIContent sssCategory = new GUIContent("Subsurface scattering");
public readonly GUIContent sssProfileStdDev1 = new GUIContent("Standard deviation #1", "Determines the shape of the 1st Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileStdDev2 = new GUIContent("Standard deviation #2", "Determines the shape of the 2nd Gaussian filter. Increases the strength and the radius of the blur of the corresponding color channel.");
public readonly GUIContent sssProfileLerpWeight = new GUIContent("Filter interpolation", "Controls linear interpolation between the two Gaussian filters.");
public readonly GUIContent sssProfileTransmittance = new GUIContent("Enable transmittance", "Toggles simulation of light passing through thin objects. Depends on the thickness of the material.");
public readonly GUIContent sssProfileThicknessScale = new GUIContent("Thickness scale", "Linearly scales the thickness of the object which affects the amount of transmitted lighting.");
}
private static Styles s_Styles;

正在加载...
取消
保存