浏览代码

Implement the min-max slider for thickness

/Branch_Batching2
Evgenii Golubev 7 年前
当前提交
fb5cc01d
共有 4 个文件被更改,包括 56 次插入47 次删除
  1. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 14
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  3. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader
  4. 81
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


// Broadcast SSS parameters to all shaders.
Shader.SetGlobalInt("_TransmissionFlags", sssParameters.transmissionFlags);
Shader.SetGlobalFloatArray("_ThicknessScales", sssParameters.thicknessScales);
Shader.SetGlobalFloatArray("_ThicknessMaps", sssParameters.thicknessMaps);
Shader.SetGlobalVectorArray("_HalfRcpVariancesAndLerpWeights", sssParameters.halfRcpVariancesAndLerpWeights);
if (sssParameters.enableSSS)

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


// SSS parameters
#define N_PROFILES 8
uint _TransmissionFlags; // One bit per profile; 1 = enabled
float _ThicknessScales[N_PROFILES];
float _ThicknessMaps[N_PROFILES][2]; // Remap: 0 = start, 1 = end - start
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.subsurfaceProfile = surfaceData.subsurfaceProfile;
bsdfData.subsurfaceRadius = surfaceData.subsurfaceRadius * 0.01;
bsdfData.thickness = surfaceData.thickness * 0.01 * _ThicknessScales[bsdfData.subsurfaceProfile];
bsdfData.subsurfaceRadius = 0.01 * surfaceData.subsurfaceRadius;
bsdfData.thickness = 0.01 * (_ThicknessMaps[bsdfData.subsurfaceProfile][0]
+ _ThicknessMaps[bsdfData.subsurfaceProfile][1] * surfaceData.thickness);
bsdfData.enableTransmission = (1 << bsdfData.subsurfaceProfile) & _TransmissionFlags;
if (bsdfData.enableTransmission)
{

{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subsurfaceProfile
bsdfData.subsurfaceProfile = inGBuffer2.a * 8.0;
bsdfData.subsurfaceRadius = inGBuffer2.r * 0.01;
bsdfData.thickness = inGBuffer2.g * 0.01 * _ThicknessScales[bsdfData.subsurfaceProfile];
bsdfData.subsurfaceProfile = 8.00 * inGBuffer2.a;
bsdfData.subsurfaceRadius = 0.01 * inGBuffer2.r;
bsdfData.thickness = 0.01 * (_ThicknessMaps[bsdfData.subsurfaceProfile][0]
+ _ThicknessMaps[bsdfData.subsurfaceProfile][1] * inGBuffer2.g);
bsdfData.enableTransmission = (1 << bsdfData.subsurfaceProfile) & _TransmissionFlags;
if (bsdfData.enableTransmission)
{

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader


// Inputs & outputs
//-------------------------------------------------------------------------------------
float4 _StdDev1, _StdDev2;
float _LerpWeight, _ThicknessScale; // See 'SubsurfaceScatteringParameters'
float4 _StdDev1, _StdDev2, _ThicknessMap;
float _LerpWeight; // See 'SubsurfaceScatteringParameters'
//-------------------------------------------------------------------------------------
// Implementation

float4 Frag(Varyings input) : SV_Target
{
float thickness = input.texcoord.x * _ThicknessScale;
float thickness = _ThicknessMap.x + input.texcoord.x * (_ThicknessMap.y - _ThicknessMap.x);
float t2 = thickness * thickness;
float3 var1 = _StdDev1.rgb * _StdDev1.rgb;

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


public const int numSamples = 7; // Must be an odd number
[SerializeField, ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
public Color stdDev1;
public Color stdDev1;
public Color stdDev2;
public Color stdDev2;
public float lerpWeight;
public float lerpWeight;
public bool enableTransmission;
public bool enableTransmission;
public float thicknessScale;
public Vector2 thicknessMap;
Vector4[] m_FilterKernel;
Vector4[] m_FilterKernel;
Vector3[] m_HalfRcpVariances;
Vector3[] m_HalfRcpVariances;
Vector4 m_HalfRcpWeightedVariances;
Vector4 m_HalfRcpWeightedVariances;
// --- Public Methods ---

stdDev2 = new Color(0.6f, 0.6f, 0.6f, 0.0f);
lerpWeight = 0.5f;
enableTransmission = false;
thicknessScale = 3.0f;
thicknessMap = new Vector2(0, 3);
UpdateKernelAndVarianceData();
}

[SerializeField]
SubsurfaceScatteringProfile[] m_Profiles;
[SerializeField]
float[] m_ThicknessScales;
float[] m_ThicknessMaps;
[SerializeField]
Vector4[] m_HalfRcpVariancesAndLerpWeights;
[SerializeField]

get { return m_TransmissionFlags; }
}
// Supplies '_ThicknessScales' to Lit.hlsl.
public float[] thicknessScales
// Supplies '_ThicknessMaps' to Lit.hlsl.
public float[] thicknessMaps
get { return m_ThicknessScales; }
get { return m_ThicknessMaps; }
}
// Supplies '_HalfRcpVariancesAndLerpWeights' to Lit.hlsl.

Array.Resize(ref m_Profiles, maxNumProfiles);
}
m_NumProfiles = m_Profiles.Length;
m_NumProfiles = m_Profiles.Length;
if (m_ThicknessScales == null)
if (m_ThicknessMaps == null)
m_ThicknessScales = new float[maxNumProfiles];
m_ThicknessMaps = new float[maxNumProfiles * 2];
}
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].thicknessMap.x = Mathf.Clamp(m_Profiles[i].thicknessMap.x, 0, m_Profiles[i].thicknessMap.y);
m_Profiles[i].thicknessMap.y = Mathf.Max(m_Profiles[i].thicknessMap.x, m_Profiles[i].thicknessMap.y);
m_Profiles[i].UpdateKernelAndVarianceData();
}

{
m_ThicknessScales[i] = m_Profiles[i].thicknessScale;
m_ThicknessMaps[2 * i] = m_Profiles[i].thicknessMap.x;
m_ThicknessMaps[2 * i + 1] = m_Profiles[i].thicknessMap.y - m_Profiles[i].thicknessMap.x;
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];

public readonly GUIContent profileStdDev2 = 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 profileLerpWeight = new GUIContent("Filter interpolation", "Controls linear interpolation between the two Gaussian filters.");
public readonly GUIContent profileTransmission = new GUIContent("Enable transmission", "Toggles simulation of light passing through thin objects. Depends on the thickness of the material.");
public readonly GUIContent profileThicknessScale = new GUIContent("Thickness scale", "Linearly scales the object thickness which affects the amount of transmitted lighting.");
public readonly GUIContent profileThicknessScale = new GUIContent("Thickness map", "Remaps the thickness parameter from [0, 1] to the desired range.");
public readonly GUIStyle centeredMiniBoldLabel = new GUIStyle (GUI.skin.label);
}

if (s_Styles == null)
{
s_Styles = new Styles();
s_Styles.centeredMiniBoldLabel.alignment = TextAnchor.MiddleCenter;
s_Styles.centeredMiniBoldLabel.fontSize = 10;
s_Styles.centeredMiniBoldLabel.fontStyle = FontStyle.Bold;
s_Styles.centeredMiniBoldLabel.alignment = TextAnchor.MiddleCenter;
s_Styles.centeredMiniBoldLabel.fontSize = 10;
s_Styles.centeredMiniBoldLabel.fontStyle = FontStyle.Bold;
return s_Styles;
}

{
EditorGUI.indentLevel++;
SerializedProperty profileStdDev1 = profile.FindPropertyRelative("stdDev1");
SerializedProperty profileStdDev2 = profile.FindPropertyRelative("stdDev2");
SerializedProperty profileLerpWeight = profile.FindPropertyRelative("lerpWeight");
SerializedProperty profileTransmission = profile.FindPropertyRelative("enableTransmission");
SerializedProperty profileThicknessScale = profile.FindPropertyRelative("thicknessScale");
SerializedProperty profileStdDev1 = profile.FindPropertyRelative("stdDev1");
SerializedProperty profileStdDev2 = profile.FindPropertyRelative("stdDev2");
SerializedProperty profileLerpWeight = profile.FindPropertyRelative("lerpWeight");
SerializedProperty profileTransmission = profile.FindPropertyRelative("enableTransmission");
SerializedProperty profileThicknessMap = profile.FindPropertyRelative("thicknessMap");
EditorGUILayout.PropertyField(profileStdDev1, styles.profileStdDev1);
EditorGUILayout.PropertyField(profileStdDev2, styles.profileStdDev2);
EditorGUILayout.PropertyField(profileLerpWeight, styles.profileLerpWeight);
EditorGUILayout.PropertyField(profileTransmission, styles.profileTransmission);
EditorGUILayout.PropertyField(profileStdDev1, styles.profileStdDev1);
EditorGUILayout.PropertyField(profileStdDev2, styles.profileStdDev2);
EditorGUILayout.PropertyField(profileLerpWeight, styles.profileLerpWeight);
EditorGUILayout.PropertyField(profileTransmission, styles.profileTransmission);
EditorGUILayout.PropertyField(profileThicknessScale, styles.profileThicknessScale);
Vector2 thicknessMap = profileThicknessMap.vector2Value;
EditorGUILayout.LabelField("Min thickness: ", thicknessMap.x.ToString());
EditorGUILayout.LabelField("Max thickness: ", thicknessMap.y.ToString());
EditorGUILayout.MinMaxSlider(styles.profileThicknessScale, ref thicknessMap.x, ref thicknessMap.y, 0, 10);
profileThicknessMap.vector2Value = thicknessMap;
EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.profilePreview0, styles.centeredMiniBoldLabel);

EditorGUILayout.Space();
// Draw the transmittance graph.
m_TransmittanceMaterial.SetColor("_StdDev1", profileStdDev1.colorValue);
m_TransmittanceMaterial.SetColor("_StdDev2", profileStdDev2.colorValue);
m_TransmittanceMaterial.SetFloat("_LerpWeight", profileLerpWeight.floatValue);
m_TransmittanceMaterial.SetFloat("_ThicknessScale", profileThicknessScale.floatValue);
m_TransmittanceMaterial.SetColor("_StdDev1", profileStdDev1.colorValue);
m_TransmittanceMaterial.SetColor("_StdDev2", profileStdDev2.colorValue);
m_TransmittanceMaterial.SetFloat("_LerpWeight", profileLerpWeight.floatValue);
m_TransmittanceMaterial.SetVector("_ThicknessMap", profileThicknessMap.vector2Value);
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(16, 16), m_TransmittanceImages[i], m_TransmittanceMaterial, ScaleMode.ScaleToFit, 16.0f);
EditorGUILayout.Space();

正在加载...
取消
保存