浏览代码

Create an asset for the SSS UI

/main
Evgenii Golubev 8 年前
当前提交
517ba2ae
共有 7 个文件被更改,包括 199 次插入113 次删除
  1. 7
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs
  2. 20
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  3. 48
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  4. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs
  5. 31
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
  6. 29
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs
  7. 175
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/SubsurfaceScatteringParameters.cs

7
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipeWindow.cs


{
CommonSettingsSingleton.overrideSettings = (CommonSettings)EditorGUILayout.ObjectField(new GUIContent("Common Settings"), CommonSettingsSingleton.overrideSettings, typeof(CommonSettings), false);
SkyParametersSingleton.overrideSettings = (SkyParameters)EditorGUILayout.ObjectField(new GUIContent("Sky Settings"), SkyParametersSingleton.overrideSettings, typeof(SkyParameters), false);
SubsurfaceScatteringSettings.overrideSettings = (SubsurfaceScatteringParameters)EditorGUILayout.ObjectField(new GUIContent("Subsurface Scattering Settings"), SubsurfaceScatteringSettings.overrideSettings, typeof(SubsurfaceScatteringParameters), false);
if (GUILayout.Button("Create new common settings"))
{

{
var instance = CreateInstance<ProceduralSkyParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewProceduralSkyParameters.asset");
}
if (GUILayout.Button("Create new SSS params"))
{
var instance = CreateInstance<SubsurfaceScatteringParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewSssParameters.asset");
}
}
}

20
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


public int[] debugViewMaterialValues = null;
public readonly GUIContent skyParams = new GUIContent("Sky Settings");
public readonly GUIContent sssSettings = new GUIContent("Subsurface Scattering Settings");
public readonly GUIContent shadowSettings = new GUIContent("Shadow Settings");
public readonly GUIContent shadowsEnabled = new GUIContent("Enabled");

public readonly GUIContent clustered = new GUIContent("Enable clustered", "Toggle");
public readonly GUIContent disableTileAndCluster = new GUIContent("Disable Tile/clustered", "Toggle");
public readonly GUIContent disableDeferredShadingInCompute = new GUIContent("Disable deferred shading in compute", "Toggle");
public readonly GUIContent textureSettings = new GUIContent("Texture Settings");

}
}
private void SssSettingsUI(HDRenderPipeline pipe)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.sssSettings);
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
pipe.sssParameters = (SubsurfaceScatteringParameters) EditorGUILayout.ObjectField(new GUIContent("Subsurface Scattering Parameters"), pipe.sssParameters, typeof(SubsurfaceScatteringParameters), false);
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(pipe); // Repaint
}
}
private void ShadowParametersUI(HDRenderPipeline renderContext)
{
EditorGUILayout.Space();

DebugParametersUI(renderContext);
SkySettingsUI(renderContext);
SssSettingsUI(renderContext);
ShadowParametersUI(renderContext);
TextureParametersUI(renderContext);
//TilePassUI(renderContext);

48
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


}
}
[SerializeField]
private SkyParameters m_SkyParameters;

return m_SkyParameters;
}
}
[SerializeField]
SubsurfaceScatteringParameters m_SssParameters;
public SubsurfaceScatteringParameters sssParameters
{
set { m_SssParameters = value; }
get { return m_SssParameters; }
}
public SubsurfaceScatteringParameters sssParametersToUse
{
get
{
if (SubsurfaceScatteringSettings.overrideSettings != null)
{
return SubsurfaceScatteringSettings.overrideSettings;
}
else if (m_SssParameters != null)
{
return m_SssParameters;
}
else
{
m_SssParameters = new SubsurfaceScatteringParameters();
return m_SssParameters;
}
}
}
[SerializeField]
private LightLoopProducer m_LightLoopProducer;

}
[SerializeField]
SubsurfaceScatteringParameters m_SssParameters = SubsurfaceScatteringParameters.Default;
public SubsurfaceScatteringParameters sssParameters
{
get { return m_SssParameters; }
}
[SerializeField]
TextureSettings m_TextureSettings = TextureSettings.Default;
public TextureSettings textureSettings

m_ShadowSettings.directionalLightCascadeCount = commonSettings.shadowCascadeCount;
m_ShadowSettings.directionalLightCascades = new Vector3(commonSettings.shadowCascadeSplit0, commonSettings.shadowCascadeSplit1, commonSettings.shadowCascadeSplit2);
m_ShadowSettings.maxShadowDistance = commonSettings.shadowMaxDistance;
// TODO: how can we avoid dynamic memory allocation each frame?
m_SssParameters.profiles = new SubsurfaceScatteringProfile[SubsurfaceScatteringParameters.numProfiles];
m_SssParameters.profiles[0] = new SubsurfaceScatteringProfile();
m_SssParameters.profiles[0].stdDev1 = commonSettings.sssProfileStdDev1;
m_SssParameters.profiles[0].stdDev2 = commonSettings.sssProfileStdDev2;
m_SssParameters.profiles[0].lerpWeight = commonSettings.sssProfileLerpWeight;
m_SssParameters.bilateralScale = commonSettings.sssBilateralScale;
}
}

// We compute subsurface scattering here. Therefore, no objects rendered afterwards will exhibit SSS.
// Currently, there is no efficient way to switch between SRT and MRT for the forward pass;
// therefore, forward-rendered objects do not output split lighting required for the SSS pass.
CombineSubsurfaceScattering(hdCamera, renderContext, m_Owner.sssParameters);
CombineSubsurfaceScattering(hdCamera, renderContext, m_Owner.sssParametersToUse);
// For opaque forward we have split rendering in two categories
// Material that are always forward and material that can be deferred or forward depends on render pipeline options (like switch to rendering forward only mode)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.cs


// SSS
public float subsurfaceRadius;
public float thickness;
public int subsurfaceProfile;
public int subsurfaceProfile;
// Clearcoat
public Vector3 coatNormalWS;

31
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs


public float shadowCascadeSplit1 { set { m_ShadowCascadeSplit1 = value; OnValidate(); } get { return m_ShadowCascadeSplit1; } }
public float shadowCascadeSplit2 { set { m_ShadowCascadeSplit2 = value; OnValidate(); } get { return m_ShadowCascadeSplit2; } }
// Subsurface scattering
[SerializeField] [ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_SssProfileStdDev1;
[SerializeField] [ColorUsage(false, true, 0.05f, 2.0f, 1.0f, 1.0f)]
Color m_SssProfileStdDev2;
[SerializeField]
float m_SssProfileLerpWeight;
[SerializeField]
float m_SssBilateralScale;
public Color sssProfileStdDev1 { set { m_SssProfileStdDev1 = value; OnValidate(); } get { return m_SssProfileStdDev1; } }
public Color sssProfileStdDev2 { set { m_SssProfileStdDev2 = value; OnValidate(); } get { return m_SssProfileStdDev2; } }
public float sssProfileLerpWeight { set { m_SssProfileLerpWeight = value; OnValidate(); } get { return m_SssProfileLerpWeight; } }
public float sssBilateralScale { set { m_SssBilateralScale = value; OnValidate(); } get { return m_SssBilateralScale; } }
void OnValidate()
{
m_ShadowMaxDistance = Mathf.Max(0.0f, m_ShadowMaxDistance);

m_ShadowCascadeSplit2 = Mathf.Clamp01(m_ShadowCascadeSplit2);
m_SssProfileStdDev1.r = Mathf.Max(0.05f, m_SssProfileStdDev1.r);
m_SssProfileStdDev1.g = Mathf.Max(0.05f, m_SssProfileStdDev1.g);
m_SssProfileStdDev1.b = Mathf.Max(0.05f, m_SssProfileStdDev1.b);
m_SssProfileStdDev1.a = 0.0f;
m_SssProfileStdDev2.r = Mathf.Max(0.05f, m_SssProfileStdDev2.r);
m_SssProfileStdDev2.g = Mathf.Max(0.05f, m_SssProfileStdDev2.g);
m_SssProfileStdDev2.b = Mathf.Max(0.05f, m_SssProfileStdDev2.b);
m_SssProfileStdDev2.a = 0.0f;
m_SssProfileLerpWeight = Mathf.Clamp01(m_SssProfileLerpWeight);
m_SssBilateralScale = Mathf.Clamp01(m_SssBilateralScale);
}
public static readonly Settings s_Defaultsettings = new Settings

m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x,
m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y,
m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z,
m_SssProfileStdDev1 = SubsurfaceScatteringProfile.Default.stdDev1,
m_SssProfileStdDev2 = SubsurfaceScatteringProfile.Default.stdDev2,
m_SssProfileLerpWeight = SubsurfaceScatteringProfile.Default.lerpWeight,
m_SssBilateralScale = SubsurfaceScatteringParameters.Default.bilateralScale
};
}

29
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs


public readonly int[] shadowsCascadeCountValues = new int[] { 1, 2, 3, 4 };
public readonly GUIContent shadowsCascades = new GUIContent("Cascade values");
public readonly GUIContent[] shadowSplits = new GUIContent[] { new GUIContent("Split 0"), new GUIContent("Split 1"), new GUIContent("Split 2") };
public readonly GUIContent sssCategory = new GUIContent("Subsurface scattering");
public readonly GUIContent sssProfileStdDev1 = new GUIContent("SSS profile 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("SSS profile 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("SSS profile filter interpolation", "Controls linear interpolation between the two Gaussian filters.");
public readonly GUIContent sssBilateralScale = new GUIContent("SSS bilateral filtering scale", "Larger values make the filter more tolerant to depth differences.");
}
private static Styles s_Styles = null;

private SerializedProperty m_ShadowCascadeCount;
private SerializedProperty[] m_ShadowCascadeSplits = new SerializedProperty[3];
// Subsurface scattering
private SerializedProperty m_SssProfileStdDev1;
private SerializedProperty m_SssProfileStdDev2;
private SerializedProperty m_SssProfileLerpWeight;
private SerializedProperty m_SssBilateralScale;
void OnEnable()
{
m_SkyRenderer = serializedObject.FindProperty("m_SkyRendererTypeName");

m_SkyRendererFullTypeNames.Add("");
m_SkyRendererTypeValues.Add(m_SkyRendererTypeValues.Count);
m_SkyRendererTypes.Add(null);
m_SssProfileStdDev1 = serializedObject.FindProperty("m_SssProfileStdDev1");
m_SssProfileStdDev2 = serializedObject.FindProperty("m_SssProfileStdDev2");
m_SssProfileLerpWeight = serializedObject.FindProperty("m_SssProfileLerpWeight");
m_SssBilateralScale = serializedObject.FindProperty("m_SssBilateralScale");
}
void OnSkyInspectorGUI()

EditorGUI.indentLevel--;
}
void OnSubsurfaceInspectorGUI()
{
EditorGUILayout.LabelField(styles.sssCategory);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_SssProfileStdDev1, styles.sssProfileStdDev1);
EditorGUILayout.PropertyField(m_SssProfileStdDev2, styles.sssProfileStdDev2);
EditorGUILayout.PropertyField(m_SssProfileLerpWeight, styles.sssProfileLerpWeight);
EditorGUILayout.PropertyField(m_SssBilateralScale, styles.sssBilateralScale);
EditorGUI.indentLevel--;
}
/*
public override void OnInspectorGUI()
{

OnShadowInspectorGUI();
OnSubsurfaceInspectorGUI();
serializedObject.ApplyModifiedProperties();
}

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


using System;
using UnityEditor;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

public const int numSamples = 7; // Must be an odd number
[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)]
Color m_StdDev2;
[SerializeField]
float m_LerpWeight;
[SerializeField]
Vector4[] m_FilterKernel;
[SerializeField]
public bool m_KernelNeedsUpdate;
Color m_StdDev1;
Color m_StdDev2;
float m_LerpWeight;
Vector4[] m_FilterKernel;
bool m_KernelNeedsUpdate;
// --- Public Methods ---
// --- Methods ---
public SubsurfaceScatteringProfile()
{
m_StdDev1 = new Color(0.3f, 0.3f, 0.3f, 0.0f);
m_StdDev2 = new Color(1.0f, 1.0f, 1.0f, 0.0f);
m_LerpWeight = 0.5f;
ComputeKernel();
}
public Color stdDev1
{

get { if (m_KernelNeedsUpdate) ComputeKernel(); return m_FilterKernel; }
}
public static SubsurfaceScatteringProfile Default
public void SetDirtyFlag()
get
{
SubsurfaceScatteringProfile profile = new SubsurfaceScatteringProfile();
profile.m_StdDev1 = new Color(0.3f, 0.3f, 0.3f, 0.0f);
profile.m_StdDev2 = new Color(1.0f, 1.0f, 1.0f, 0.0f);
profile.m_LerpWeight = 0.5f;
profile.ComputeKernel();
return profile;
}
m_KernelNeedsUpdate = true;
// --- Private Methods ---
static float Gaussian(float x, float stdDev)
{

void ComputeKernel()
{
if (m_FilterKernel == null)
if (m_FilterKernel == null || m_FilterKernel.Length != numSamples)
{
m_FilterKernel = new Vector4[numSamples];
}

}
}
[System.Serializable]
public class SubsurfaceScatteringParameters
public class SubsurfaceScatteringParameters : ScriptableObject
{
const int m_maxNumProfiles = 8;
[SerializeField]
int m_NumProfiles;
[SerializeField]
SubsurfaceScatteringProfile[] m_Profiles;
[SerializeField]
float m_BilateralScale;
// --- Public Methods ---
public SubsurfaceScatteringParameters()
{
m_NumProfiles = 1;
m_Profiles = new SubsurfaceScatteringProfile[m_NumProfiles];
m_BilateralScale = 0.1f;
}
public SubsurfaceScatteringProfile[] profiles { set { m_Profiles = value; OnValidate(); } get { return m_Profiles; } }
public float bilateralScale { set { m_BilateralScale = value; OnValidate(); } get { return m_BilateralScale; } }
public void SetDirtyFlag()
{
for (int i = 0; i < m_Profiles.Length; i++)
{
m_Profiles[i].SetDirtyFlag();
}
}
// --- Private Methods ---
void OnValidate()
{
if (m_Profiles.Length > m_maxNumProfiles)
{
Array.Resize(ref m_Profiles, m_maxNumProfiles);
}
m_NumProfiles = m_Profiles.Length;
Color c = new Color();
for (int i = 0; i < m_NumProfiles; i++)
{
c.r = Mathf.Clamp(m_Profiles[i].stdDev1.r, 0.05f, 2.0f);
c.g = Mathf.Clamp(m_Profiles[i].stdDev1.g, 0.05f, 2.0f);
c.b = Mathf.Clamp(m_Profiles[i].stdDev1.b, 0.05f, 2.0f);
c.a = 0.0f;
m_Profiles[i].stdDev1 = c;
c.r = Mathf.Clamp(m_Profiles[i].stdDev2.r, 0.05f, 2.0f);
c.g = Mathf.Clamp(m_Profiles[i].stdDev2.g, 0.05f, 2.0f);
c.b = Mathf.Clamp(m_Profiles[i].stdDev2.b, 0.05f, 2.0f);
c.a = 0.0f;
m_Profiles[i].stdDev2 = c;
m_Profiles[i].lerpWeight = Mathf.Clamp01(m_Profiles[i].lerpWeight);
}
m_BilateralScale = Mathf.Clamp01(m_BilateralScale);
}
}
public class SubsurfaceScatteringSettings : Singleton<SubsurfaceScatteringSettings>
public const int numProfiles = 1;
public SubsurfaceScatteringProfile[] profiles;
public float bilateralScale;
SubsurfaceScatteringParameters settings { get; set; }
public static SubsurfaceScatteringParameters overrideSettings
{
get { return instance.settings; }
set { instance.settings = value; }
}
}
[CustomEditor(typeof(SubsurfaceScatteringParameters))]
public class SubsurfaceScatteringParametersEditor : Editor
{
private class Styles
{
public readonly GUIContent sssCategory = new GUIContent("Subsurface scattering");
public readonly GUIContent sssProfileStdDev1 = new GUIContent("SSS profile 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("SSS profile 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("SSS profile filter interpolation", "Controls linear interpolation between the two Gaussian filters.");
public readonly GUIContent sssBilateralScale = new GUIContent("SSS bilateral filtering scale", "Larger values make the filter more tolerant to depth differences.");
}
private static Styles s_Styles;
private SerializedProperty m_Profiles;
private SerializedProperty m_BilateralScale;
// --- Methods ---
// --- Public Methods ---
public static SubsurfaceScatteringParameters Default
private static Styles styles
SubsurfaceScatteringParameters parameters = new SubsurfaceScatteringParameters();
parameters.profiles = new SubsurfaceScatteringProfile[numProfiles];
for (int i = 0; i < numProfiles; i++)
if (s_Styles == null)
parameters.profiles[i] = SubsurfaceScatteringProfile.Default;
s_Styles = new Styles();
return s_Styles;
}
}
parameters.bilateralScale = 0.1f;
return parameters;
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_Profiles, true);
EditorGUILayout.PropertyField(m_BilateralScale, styles.sssBilateralScale);
if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
// Serialization ignores setters.
((SubsurfaceScatteringParameters)target).SetDirtyFlag();
}
// --- Private Methods ---
void OnEnable()
{
m_Profiles = serializedObject.FindProperty("m_Profiles");
m_BilateralScale = serializedObject.FindProperty("m_BilateralScale");
}
}
}
正在加载...
取消
保存