浏览代码

Merge pull request #167 from EvgeniiG/master

Implement the min-max slider for thickness
/Branch_Batching2
GitHub 8 年前
当前提交
0732e483
共有 4 个文件被更改,包括 53 次插入44 次删除
  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. 75
      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("_ThicknessRemaps", sssParameters.thicknessRemaps);
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 _ThicknessRemaps[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 * (_ThicknessRemaps[bsdfData.subsurfaceProfile][0] +
_ThicknessRemaps[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 * (_ThicknessRemaps[bsdfData.subsurfaceProfile][0] +
_ThicknessRemaps[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, _ThicknessRemap;
float _LerpWeight; // See 'SubsurfaceScatteringParameters'
//-------------------------------------------------------------------------------------
// Implementation

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

75
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 thicknessRemap;
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;
thicknessRemap = new Vector2(0, 3);
UpdateKernelAndVarianceData();
}

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

get { return m_TransmissionFlags; }
}
// Supplies '_ThicknessScales' to Lit.hlsl.
public float[] thicknessScales
// Supplies '_ThicknessRemaps' to Lit.hlsl.
public float[] thicknessRemaps
get { return m_ThicknessScales; }
get { return m_ThicknessRemaps; }
}
// 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_ThicknessRemaps == null)
m_ThicknessScales = new float[maxNumProfiles];
m_ThicknessRemaps = 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].thicknessRemap.x = Mathf.Clamp(m_Profiles[i].thicknessRemap.x, 0, m_Profiles[i].thicknessRemap.y);
m_Profiles[i].thicknessRemap.y = Mathf.Max(m_Profiles[i].thicknessRemap.x, m_Profiles[i].thicknessRemap.y);
m_Profiles[i].UpdateKernelAndVarianceData();
}

{
m_ThicknessScales[i] = m_Profiles[i].thicknessScale;
m_ThicknessRemaps[2 * i] = m_Profiles[i].thicknessRemap.x;
m_ThicknessRemaps[2 * i + 1] = m_Profiles[i].thicknessRemap.y - m_Profiles[i].thicknessRemap.x;
m_HalfRcpWeightedVariances[i] = m_Profiles[i].halfRcpWeightedVariances;
m_HalfRcpWeightedVariances[i] = m_Profiles[i].halfRcpWeightedVariances;
for (int j = 0, n = SubsurfaceScatteringProfile.numSamples; j < n; j++)
{

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 profileThicknessRemap = new GUIContent("Thickness remap", "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;
}
}

SerializedProperty profileStdDev2 = profile.FindPropertyRelative("stdDev2");
SerializedProperty profileLerpWeight = profile.FindPropertyRelative("lerpWeight");
SerializedProperty profileTransmission = profile.FindPropertyRelative("enableTransmission");
SerializedProperty profileThicknessScale = profile.FindPropertyRelative("thicknessScale");
SerializedProperty profileThicknessRemap = profile.FindPropertyRelative("thicknessRemap");
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 thicknessRemap = profileThicknessRemap.vector2Value;
EditorGUILayout.LabelField("Min thickness: ", thicknessRemap.x.ToString());
EditorGUILayout.LabelField("Max thickness: ", thicknessRemap.y.ToString());
EditorGUILayout.MinMaxSlider(styles.profileThicknessRemap, ref thicknessRemap.x, ref thicknessRemap.y, 0, 10);
profileThicknessRemap.vector2Value = thicknessRemap;
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("_ThicknessRemap", profileThicknessRemap.vector2Value);
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(16, 16), m_TransmittanceImages[i], m_TransmittanceMaterial, ScaleMode.ScaleToFit, 16.0f);
EditorGUILayout.Space();

正在加载...
取消
保存