浏览代码

Merge pull request #462 from Unity-Technologies/sss-refactor

Full SSS refactor
/stochastic_alpha_test
GitHub 7 年前
当前提交
1b740960
共有 33 个文件被更改,包括 1257 次插入1982 次删除
  1. 38
      ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs
  2. 58
      ScriptableRenderPipeline/Core/Editor/PropertyFetcher.cs
  3. 250
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  4. 16
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  5. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  6. 601
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset
  7. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs
  8. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs
  9. 42
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs
  10. 64
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  11. 5
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs
  12. 4
      ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardGUI.cs
  13. 53
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDBaseEditor.cs
  14. 13
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDBaseEditor.cs.meta
  15. 56
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.Styles.cs
  16. 13
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.Styles.cs.meta
  17. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs.meta
  18. 258
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.cs
  19. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.cs.meta
  20. 85
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SSS Settings.asset
  21. 10
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SSS Settings.asset.meta
  22. 508
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs
  23. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs.meta
  24. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.Styles.cs.meta
  25. 13
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.cs.meta
  26. 171
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.cs
  27. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/FoliageSSSProfile.asset.meta
  28. 9
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SkinSSSProfile.asset.meta
  29. 116
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/FoliageSSSProfile.asset
  30. 116
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SkinSSSProfile.asset
  31. 12
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs.meta
  32. 637
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs
  33. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs

38
ScriptableRenderPipeline/Core/Editor/CoreEditorUtils.cs


using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using UnityEngine;
// Serialization helpers
public static string FindProperty<T, TValue>(Expression<Func<T, TValue>> expr)
{
// Get the field path as a string
MemberExpression me;
switch (expr.Body.NodeType)
{
case ExpressionType.MemberAccess:
me = expr.Body as MemberExpression;
break;
default:
throw new InvalidOperationException();
}
var members = new List<string>();
while (me != null)
{
members.Add(me.Member.Name);
me = me.Expression as MemberExpression;
}
var sb = new StringBuilder();
for (int i = members.Count - 1; i >= 0; i--)
{
sb.Append(members[i]);
if (i > 0) sb.Append('.');
}
return sb.ToString();
}
// UI Helpers
public static void DrawSplitter()
{

// Title
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel);
EditorGUILayout.Space();
}
public static bool DrawHeaderFoldout(string title, bool state)

58
ScriptableRenderPipeline/Core/Editor/PropertyFetcher.cs


using System;
using System.Collections.Generic;
using System.Text;
public class PropertyFetcher<T> : IDisposable
public sealed class PropertyFetcher<T> : IDisposable
{
public readonly SerializedObject obj;

this.obj = obj;
}
public SerializedProperty FindProperty(string str)
public SerializedProperty Find(string str)
public SerializedProperty FindProperty<TValue>(Expression<Func<T, TValue>> expr)
public SerializedProperty Find<TValue>(Expression<Func<T, TValue>> expr)
// Get the field path as a string
MemberExpression me;
switch (expr.Body.NodeType)
{
case ExpressionType.MemberAccess:
me = expr.Body as MemberExpression;
break;
default:
throw new InvalidOperationException();
}
string path = CoreEditorUtils.FindProperty(expr);
return obj.FindProperty(path);
}
var members = new List<string>();
while (me != null)
{
members.Add(me.Member.Name);
me = me.Expression as MemberExpression;
}
public void Dispose()
{
// Nothing to do here, still needed so we can rely on the using/IDisposable pattern
}
}
var sb = new StringBuilder();
for (int i = members.Count - 1; i >= 0; i--)
{
sb.Append(members[i]);
if (i > 0) sb.Append('.');
}
public sealed class RelativePropertyFetcher<T> : IDisposable
{
public readonly SerializedProperty obj;
public RelativePropertyFetcher(SerializedProperty obj)
{
Assert.IsNotNull(obj);
this.obj = obj;
}
var path = sb.ToString();
public SerializedProperty Find(string str)
{
return obj.FindPropertyRelative(str);
}
// Fetch the SerializedProperty using Unity's method
return obj.FindProperty(path);
public SerializedProperty Find<TValue>(Expression<Func<T, TValue>> expr)
{
string path = CoreEditorUtils.FindProperty(expr);
return obj.FindPropertyRelative(path);
}
public void Dispose()

250
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


using System;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
//using EditorGUIUtility=UnityEditor.EditorGUIUtility;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEngine.Experimental.Rendering.HDPipeline
namespace UnityEditor.Experimental.Rendering.HDPipeline
public class HDRenderPipelineInspector : Editor
public sealed partial class HDRenderPipelineInspector : HDBaseEditor<HDRenderPipelineAsset>
private class Styles
{
public static GUIContent defaults = new GUIContent("Defaults");
public static GUIContent defaultDiffuseMaterial = new GUIContent("Default Diffuse Material", "Material to use when creating objects");
public static GUIContent defaultShader = new GUIContent("Default Shader", "Shader to use when creating materials");
public readonly GUIContent settingsLabel = new GUIContent("Settings");
// Rendering Settings
public readonly GUIContent renderingSettingsLabel = new GUIContent("Rendering Settings");
public readonly GUIContent useForwardRenderingOnly = new GUIContent("Use Forward Rendering Only");
public readonly GUIContent useDepthPrepassWithDeferredRendering = new GUIContent("Use Depth Prepass with Deferred rendering");
public readonly GUIContent renderAlphaTestOnlyInDeferredPrepass = new GUIContent("Alpha Test only");
// Texture Settings
public readonly GUIContent textureSettings = new GUIContent("Texture Settings");
public readonly GUIContent spotCookieSize = new GUIContent("Spot cookie size");
public readonly GUIContent pointCookieSize = new GUIContent("Point cookie size");
public readonly GUIContent reflectionCubemapSize = new GUIContent("Reflection cubemap size");
public readonly GUIContent sssSettings = new GUIContent("Subsurface Scattering Settings");
// Shadow Settings
public readonly GUIContent shadowSettings = new GUIContent("Shadow Settings");
public readonly GUIContent shadowsAtlasWidth = new GUIContent("Atlas width");
public readonly GUIContent shadowsAtlasHeight = new GUIContent("Atlas height");
// Subsurface Scattering Settings
public readonly GUIContent[] sssProfiles = new GUIContent[SssConstants.SSS_N_PROFILES - 1] { new GUIContent("Profile #1"), new GUIContent("Profile #2"), new GUIContent("Profile #3"), new GUIContent("Profile #4"), new GUIContent("Profile #5"),
new GUIContent("Profile #6"), new GUIContent("Profile #7")/*, new GUIContent("Profile #8"), new GUIContent("Profile #9"), new GUIContent("Profile #10"),
new GUIContent("Profile #11"), new GUIContent("Profile #12"), new GUIContent("Profile #13"), new GUIContent("Profile #14"), new GUIContent("Profile #15")*/ };
public readonly GUIContent sssNumProfiles = new GUIContent("Number of profiles");
// Tile pass Settings
public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop Settings");
public readonly GUIContent enableTileAndCluster = new GUIContent("Enable tile/clustered");
public readonly GUIContent enableComputeLightEvaluation = new GUIContent("Enable Compute Light Evaluation");
public readonly GUIContent enableComputeLightVariants = new GUIContent("Enable Compute Light Variants");
public readonly GUIContent enableComputeMaterialVariants = new GUIContent("Enable Compute Material Variants");
public readonly GUIContent enableClustered = new GUIContent("Enable clustered");
public readonly GUIContent enableFptlForOpaqueWhenClustered = new GUIContent("Enable Fptl For Opaque When Clustered");
public readonly GUIContent enableBigTilePrepass = new GUIContent("Enable big tile prepass");
public readonly GUIContent tileDebugByCategory = new GUIContent("Enable Debug By Category");
// Sky Settings
public readonly GUIContent skyParams = new GUIContent("Sky Settings");
}
private static Styles s_Styles = null;
private static Styles styles
{
get
{
if (s_Styles == null)
s_Styles = new Styles();
return s_Styles;
}
}
private SerializedProperty m_DefaultDiffuseMaterial;
private SerializedProperty m_DefaultShader;
SerializedProperty m_DefaultDiffuseMaterial;
SerializedProperty m_DefaultShader;
// TilePass settings
SerializedProperty m_enableTileAndCluster;

SerializedProperty m_enableBigTilePrepass;
// Rendering Settings
SerializedProperty m_RenderingUseForwardOnly = null;
SerializedProperty m_RenderingUseDepthPrepass = null;
SerializedProperty m_RenderingUseDepthPrepassAlphaTestOnly = null;
SerializedProperty m_RenderingUseForwardOnly;
SerializedProperty m_RenderingUseDepthPrepass;
SerializedProperty m_RenderingUseDepthPrepassAlphaTestOnly;
// Old SSS Model >>>
SerializedProperty m_UseDisneySSS = null;
// <<< Old SSS Model
SerializedProperty m_Profiles = null;
SerializedProperty m_NumProfiles = null;
SerializedProperty m_SubsurfaceScatteringSettings;
SerializedProperty m_ShadowAtlasWidth = null;
SerializedProperty m_ShadowAtlasHeight = null;
SerializedProperty m_ShadowAtlasWidth;
SerializedProperty m_ShadowAtlasHeight;
SerializedProperty m_SpotCookieSize = null;
SerializedProperty m_PointCookieSize = null;
SerializedProperty m_ReflectionCubemapSize = null;
SerializedProperty m_SpotCookieSize;
SerializedProperty m_PointCookieSize;
SerializedProperty m_ReflectionCubemapSize;
using (var p = new PropertyFetcher<HDRenderPipelineAsset>(serializedObject))
{
m_DefaultDiffuseMaterial = p.FindProperty("m_DefaultDiffuseMaterial");
m_DefaultShader = p.FindProperty("m_DefaultShader");
m_DefaultDiffuseMaterial = properties.Find("m_DefaultDiffuseMaterial");
m_DefaultShader = properties.Find("m_DefaultShader");
// Tile settings
m_enableTileAndCluster = p.FindProperty(x => x.tileSettings.enableTileAndCluster);
m_enableComputeLightEvaluation = p.FindProperty(x => x.tileSettings.enableComputeLightEvaluation);
m_enableComputeLightVariants = p.FindProperty(x => x.tileSettings.enableComputeLightVariants);
m_enableComputeMaterialVariants = p.FindProperty(x => x.tileSettings.enableComputeMaterialVariants);
m_enableClustered = p.FindProperty(x => x.tileSettings.enableClustered);
m_enableFptlForOpaqueWhenClustered = p.FindProperty(x => x.tileSettings.enableFptlForOpaqueWhenClustered);
m_enableBigTilePrepass = p.FindProperty(x => x.tileSettings.enableBigTilePrepass);
// Tile settings
m_enableTileAndCluster = properties.Find(x => x.tileSettings.enableTileAndCluster);
m_enableComputeLightEvaluation = properties.Find(x => x.tileSettings.enableComputeLightEvaluation);
m_enableComputeLightVariants = properties.Find(x => x.tileSettings.enableComputeLightVariants);
m_enableComputeMaterialVariants = properties.Find(x => x.tileSettings.enableComputeMaterialVariants);
m_enableClustered = properties.Find(x => x.tileSettings.enableClustered);
m_enableFptlForOpaqueWhenClustered = properties.Find(x => x.tileSettings.enableFptlForOpaqueWhenClustered);
m_enableBigTilePrepass = properties.Find(x => x.tileSettings.enableBigTilePrepass);
// Shadow settings
m_ShadowAtlasWidth = p.FindProperty(x => x.shadowInitParams.shadowAtlasWidth);
m_ShadowAtlasHeight = p.FindProperty(x => x.shadowInitParams.shadowAtlasHeight);
// Shadow settings
m_ShadowAtlasWidth = properties.Find(x => x.shadowInitParams.shadowAtlasWidth);
m_ShadowAtlasHeight = properties.Find(x => x.shadowInitParams.shadowAtlasHeight);
// Texture settings
m_SpotCookieSize = p.FindProperty(x => x.textureSettings.spotCookieSize);
m_PointCookieSize = p.FindProperty(x => x.textureSettings.pointCookieSize);
m_ReflectionCubemapSize = p.FindProperty(x => x.textureSettings.reflectionCubemapSize);
// Texture settings
m_SpotCookieSize = properties.Find(x => x.textureSettings.spotCookieSize);
m_PointCookieSize = properties.Find(x => x.textureSettings.pointCookieSize);
m_ReflectionCubemapSize = properties.Find(x => x.textureSettings.reflectionCubemapSize);
// Rendering settings
m_RenderingUseForwardOnly = p.FindProperty(x => x.renderingSettings.useForwardRenderingOnly);
m_RenderingUseDepthPrepass = p.FindProperty(x => x.renderingSettings.useDepthPrepassWithDeferredRendering);
m_RenderingUseDepthPrepassAlphaTestOnly = p.FindProperty(x => x.renderingSettings.renderAlphaTestOnlyInDeferredPrepass);
// Rendering settings
m_RenderingUseForwardOnly = properties.Find(x => x.renderingSettings.useForwardRenderingOnly);
m_RenderingUseDepthPrepass = properties.Find(x => x.renderingSettings.useDepthPrepassWithDeferredRendering);
m_RenderingUseDepthPrepassAlphaTestOnly = properties.Find(x => x.renderingSettings.renderAlphaTestOnlyInDeferredPrepass);
// Subsurface Scattering Settings
// Old SSS Model >>>
m_UseDisneySSS = p.FindProperty(x => x.sssSettings.useDisneySSS);
// <<< Old SSS Model
m_Profiles = p.FindProperty(x => x.sssSettings.profiles);
m_NumProfiles = m_Profiles.FindPropertyRelative("Array.size");
}
// Subsurface Scattering Settings
m_SubsurfaceScatteringSettings = properties.Find(x => x.sssSettings);
}
static void HackSetDirty(RenderPipelineAsset asset)

method.Invoke(asset, new object[0]);
}
private void TileSettingsUI(HDRenderPipelineAsset renderContext)
void TileSettingsUI(HDRenderPipelineAsset renderContext)
EditorGUILayout.LabelField(styles.tileLightLoopSettings);
EditorGUILayout.LabelField(s_Styles.tileLightLoopSettings);
EditorGUILayout.PropertyField(m_enableTileAndCluster, styles.enableTileAndCluster);
EditorGUILayout.PropertyField(m_enableTileAndCluster, s_Styles.enableTileAndCluster);
EditorGUILayout.PropertyField(m_enableBigTilePrepass, styles.enableBigTilePrepass);
EditorGUILayout.PropertyField(m_enableClustered, styles.enableClustered);
EditorGUILayout.PropertyField(m_enableBigTilePrepass, s_Styles.enableBigTilePrepass);
EditorGUILayout.PropertyField(m_enableClustered, s_Styles.enableClustered);
// Tag: SUPPORT_COMPUTE_CLUSTER_OPAQUE - Uncomment this if you want to do cluster opaque with compute shader (by default we support only fptl on opaque)
// if (m_enableClustered.boolValue)

EditorGUILayout.PropertyField(m_enableFptlForOpaqueWhenClustered, styles.enableFptlForOpaqueWhenClustered);
EditorGUILayout.PropertyField(m_enableFptlForOpaqueWhenClustered, s_Styles.enableFptlForOpaqueWhenClustered);
EditorGUILayout.PropertyField(m_enableComputeLightEvaluation, styles.enableComputeLightEvaluation);
EditorGUILayout.PropertyField(m_enableComputeLightEvaluation, s_Styles.enableComputeLightEvaluation);
if (m_enableComputeLightEvaluation.boolValue)
{
// Tag: SUPPORT_COMPUTE_CLUSTER_OPAQUE - Uncomment this if you want to do cluster opaque with compute shader (by default we support only fptl on opaque)

EditorGUILayout.PropertyField(m_enableComputeLightVariants, styles.enableComputeLightVariants);
EditorGUILayout.PropertyField(m_enableComputeMaterialVariants, styles.enableComputeMaterialVariants);
EditorGUILayout.PropertyField(m_enableComputeLightVariants, s_Styles.enableComputeLightVariants);
EditorGUILayout.PropertyField(m_enableComputeMaterialVariants, s_Styles.enableComputeMaterialVariants);
if (EditorGUI.EndChangeCheck())
{

}
private void SssSettingsUI(HDRenderPipelineAsset renderContext)
void SssSettingsUI(HDRenderPipelineAsset renderContext)
EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.sssSettings);
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
// Old SSS Model >>>
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_UseDisneySSS);
if (EditorGUI.EndChangeCheck())
{
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
hdPipeline.CreateSssMaterials(m_UseDisneySSS.boolValue);
}
// <<< Old SSS Model
EditorGUILayout.PropertyField(m_NumProfiles, styles.sssNumProfiles);
for (int i = 0, n = m_Profiles.arraySize; i < n; i++)
{
SerializedProperty profile = m_Profiles.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(profile, styles.sssProfiles[i]);
}
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(m_SubsurfaceScatteringSettings, s_Styles.sssSettings);
private void SettingsUI(HDRenderPipelineAsset renderContext)
void SettingsUI(HDRenderPipelineAsset renderContext)
EditorGUILayout.LabelField(styles.settingsLabel);
EditorGUILayout.LabelField(s_Styles.settingsLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
SssSettingsUI(renderContext);

EditorGUI.indentLevel--;
}
private void ShadowSettingsUI(HDRenderPipelineAsset renderContext)
void ShadowSettingsUI(HDRenderPipelineAsset renderContext)
EditorGUILayout.LabelField(styles.shadowSettings);
EditorGUILayout.LabelField(s_Styles.shadowSettings);
EditorGUILayout.PropertyField(m_ShadowAtlasWidth, styles.shadowsAtlasWidth);
EditorGUILayout.PropertyField(m_ShadowAtlasHeight, styles.shadowsAtlasHeight);
EditorGUILayout.PropertyField(m_ShadowAtlasWidth, s_Styles.shadowsAtlasWidth);
EditorGUILayout.PropertyField(m_ShadowAtlasHeight, s_Styles.shadowsAtlasHeight);
if (EditorGUI.EndChangeCheck())
{

}
private void RendereringSettingsUI(HDRenderPipelineAsset renderContext)
void RendereringSettingsUI(HDRenderPipelineAsset renderContext)
EditorGUILayout.LabelField(styles.renderingSettingsLabel);
EditorGUILayout.LabelField(s_Styles.renderingSettingsLabel);
EditorGUILayout.PropertyField(m_RenderingUseForwardOnly, styles.useForwardRenderingOnly);
EditorGUILayout.PropertyField(m_RenderingUseForwardOnly, s_Styles.useForwardRenderingOnly);
EditorGUILayout.PropertyField(m_RenderingUseDepthPrepass, styles.useDepthPrepassWithDeferredRendering);
EditorGUILayout.PropertyField(m_RenderingUseDepthPrepass, s_Styles.useDepthPrepassWithDeferredRendering);
EditorGUILayout.PropertyField(m_RenderingUseDepthPrepassAlphaTestOnly, styles.renderAlphaTestOnlyInDeferredPrepass);
EditorGUILayout.PropertyField(m_RenderingUseDepthPrepassAlphaTestOnly, s_Styles.renderAlphaTestOnlyInDeferredPrepass);
EditorGUI.indentLevel--;
}
}

private void TextureSettingsUI(HDRenderPipelineAsset renderContext)
void TextureSettingsUI(HDRenderPipelineAsset renderContext)
EditorGUILayout.LabelField(styles.textureSettings);
EditorGUILayout.LabelField(s_Styles.textureSettings);
EditorGUILayout.PropertyField(m_SpotCookieSize, styles.spotCookieSize);
EditorGUILayout.PropertyField(m_PointCookieSize, styles.pointCookieSize);
EditorGUILayout.PropertyField(m_ReflectionCubemapSize, styles.reflectionCubemapSize);
EditorGUILayout.PropertyField(m_SpotCookieSize, s_Styles.spotCookieSize);
EditorGUILayout.PropertyField(m_PointCookieSize, s_Styles.pointCookieSize);
EditorGUILayout.PropertyField(m_ReflectionCubemapSize, s_Styles.reflectionCubemapSize);
if (EditorGUI.EndChangeCheck())
{

}
public void OnEnable()
protected override void OnEnable()
base.OnEnable();
var renderContext = target as HDRenderPipelineAsset;
HDRenderPipeline renderpipeline = UnityEngine.Experimental.Rendering.RenderPipelineManager.currentPipeline as HDRenderPipeline;
if (!renderContext || renderpipeline == null)
if (!m_Target || m_HDPipeline == null)
CheckStyles();
EditorGUILayout.LabelField(Styles.defaults, EditorStyles.boldLabel);
EditorGUILayout.LabelField(s_Styles.defaults, EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_DefaultDiffuseMaterial, Styles.defaultDiffuseMaterial);
EditorGUILayout.PropertyField(m_DefaultShader, Styles.defaultShader);
EditorGUILayout.PropertyField(m_DefaultDiffuseMaterial, s_Styles.defaultDiffuseMaterial);
EditorGUILayout.PropertyField(m_DefaultShader, s_Styles.defaultShader);
EditorGUILayout.Space();
SettingsUI(renderContext);
SettingsUI(m_Target);
serializedObject.ApplyModifiedProperties();
}

16
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


}
}
class DoCreateNewAssetSSSProfile : DoCreateNewAsset<SubsurfaceScatteringProfile> {}
[MenuItem("Assets/Create/HDRenderPipeline/Subsurface Scattering Profile", priority = 666)]
static void MenuCreateSubsurfaceScatteringProfile()
{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSSSProfile>(), "New SSS Profile.asset", icon, null);
}
class DoCreateNewAssetSubsurfaceScatteringSettings : DoCreateNewAsset<SubsurfaceScatteringSettings> {}
[MenuItem("Assets/Create/HDRenderPipeline/Common Settings", priority = 677)]
static void MenuCreateCommonSettings()

{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSSAOSettings>(), "New AmbientOcclusionSettings.asset", icon, null);
}
[MenuItem("Assets/Create/HDRenderPipeline/Subsurface Scattering Settings", priority = 681)]
static void MenuCreateSubsurfaceScatteringSettings()
{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSubsurfaceScatteringSettings>(), "New SSS Settings.asset", icon, null);
}
}
}

26
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


int m_DebugFullScreenTempRT;
bool m_FullScreenDebugPushed;
SubsurfaceScatteringSettings m_InternalSSSAsset;
get { return m_Asset.sssSettings; }
get
{
// If no SSS asset is set, build / reuse an internal one for simplicity
var asset = m_Asset.sssSettings;
if (asset == null)
{
if (m_InternalSSSAsset == null)
m_InternalSSSAsset = ScriptableObject.CreateInstance<SubsurfaceScatteringSettings>();
asset = m_InternalSSSAsset;
}
return asset;
}
}
CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;

m_CameraFilteringBuffer = HDShaderIDs._CameraFilteringBuffer;
m_CameraFilteringBufferRT = new RenderTargetIdentifier(m_CameraFilteringBuffer);
CreateSssMaterials(sssSettings.useDisneySSS);
CreateSssMaterials();
m_CopyStencilForSplitLighting = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/CopyStencilBuffer");
m_CopyStencilForSplitLighting.EnableKeyword("EXPORT_HTILE");

m_ErrorMaterial = CoreUtils.CreateEngineMaterial("Hidden/InternalErrorShader");
}
public void CreateSssMaterials(bool useDisneySSS)
public void CreateSssMaterials()
{
m_SubsurfaceScatteringKernel = m_SubsurfaceScatteringCS.FindKernel("SubsurfaceScattering");

CoreUtils.Destroy(m_DebugDisplayLatlong);
CoreUtils.Destroy(m_DebugFullScreen);
CoreUtils.Destroy(m_ErrorMaterial);
CoreUtils.Destroy(m_InternalSSSAsset);
m_SkyManager.Cleanup();

var postProcessLayer = camera.GetComponent<PostProcessLayer>();
var hdCamera = HDCamera.Get(camera, postProcessLayer);
PushGlobalParams(hdCamera, cmd, m_Asset.sssSettings);
PushGlobalParams(hdCamera, cmd, sssSettings);
// TODO: Find a correct place to bind these material textures
// We have to bind the material specific global parameters in this mode

// 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.
SubsurfaceScatteringPass(hdCamera, cmd, m_Asset.sssSettings);
SubsurfaceScatteringPass(hdCamera, cmd, sssSettings);
RenderForward(m_CullResults, camera, renderContext, cmd, true);
RenderForwardError(m_CullResults, camera, renderContext, cmd, true);

601
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset


useForwardRenderingOnly: 0
useDepthPrepassWithDeferredRendering: 0
renderAlphaTestOnlyInDeferredPrepass: 0
sssSettings:
numProfiles: 2
profiles:
- {fileID: 11400000, guid: 906339bac2066fc4aa22a3652e1283ef, type: 2}
- {fileID: 11400000, guid: d6ee4403015766f4093158d69216c0bf, type: 2}
texturingModeFlags: 0
transmissionFlags: 5462
thicknessRemaps:
- {x: 0, y: 8.152544, z: 0, w: 0}
- {x: 0, y: 0.2873168, z: 0, w: 0}
- {x: 0, y: 5, z: 0, w: 0}
- {x: 0, y: 12.031147, z: 0, w: 0}
- {x: 0, y: 12.031147, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
worldScales:
- {x: 1, y: 0, z: 0, w: 0}
- {x: 1, y: 0, z: 0, w: 0}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
shapeParams:
- {x: 1.3192612, y: 3.1152647, z: 4.9751244, w: 7.84603}
- {x: 1.3203883, y: 1.4268992, z: 4.0812, w: 7.839332}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
transmissionTints:
- {x: 0.1892157, y: 0.08039216, z: 0.050000004, w: 0.25}
- {x: 0.25, y: 0.25, z: 0.25, w: 0.25}
- {x: 100, y: 0, z: 100, w: 1}
- {x: 100, y: 0, z: 100, w: 1}
- {x: 100, y: 0, z: 100, w: 1}
- {x: 100, y: 0, z: 100, w: 1}
- {x: 100, y: 0, z: 100, w: 1}
- {x: 0, y: 0, z: 0, w: 0}
filterKernels:
- {x: 0.013865918, y: 1.5345725, z: 0.03667902, w: 1.5654991}
- {x: 0.04211352, y: 1.5729346, z: 0.11374626, w: 1.6734134}
- {x: 0.07107388, y: 1.6130018, z: 0.19626758, w: 1.7949444}
- {x: 0.100779116, y: 1.6548817, z: 0.28494877, w: 1.9325867}
- {x: 0.13126306, y: 1.6986896, z: 0.38062802, w: 2.0894418}
- {x: 0.16256203, y: 1.7445502, z: 0.48430943, w: 2.2694077}
- {x: 0.1947145, y: 1.7925992, z: 0.59720695, w: 2.4774427}
- {x: 0.22776169, y: 1.8429838, z: 0.72080237, w: 2.7199378}
- {x: 0.26174724, y: 1.8958628, z: 0.8569269, w: 3.005264}
- {x: 0.29671827, y: 1.9514104, z: 1.007873, w: 3.3445888}
- {x: 0.33272493, y: 2.0098157, z: 1.1765549, w: 3.7531407}
- {x: 0.369821, y: 2.0712852, z: 1.3667475, w: 4.252257}
- {x: 0.40806437, y: 2.1360447, z: 1.5834517, w: 4.872841}
- {x: 0.44751683, y: 2.2043417, z: 1.8334827, w: 5.6615734}
- {x: 0.48824534, y: 2.276447, z: 2.126473, w: 6.692844}
- {x: 0.5303216, y: 2.3526597, z: 2.4767098, w: 8.093767}
- {x: 0.5738235, y: 2.433308, z: 2.9068332, w: 10.102725}
- {x: 0.61883456, y: 2.5187542, z: 3.4562516, w: 13.228675}
- {x: 0.665446, y: 2.609401, z: 4.2041187, w: 18.793621}
- {x: 0.713756, y: 2.7056925, z: 5.3538504, w: 31.646347}
- {x: 0.763872, y: 2.808125, z: 7.84603, w: 95.44374}
- {x: 0.8159103, y: 2.91725, z: 0, w: 1}
- {x: 0.8699981, y: 3.0336854, z: 0, w: 1}
- {x: 0.9262747, y: 3.1581244, z: 0, w: 1}
- {x: 0.98489225, y: 3.2913465, z: 0, w: 1}
- {x: 1.0460185, y: 3.434234, z: 0, w: 1}
- {x: 1.1098381, y: 3.5877857, z: 0, w: 1}
- {x: 1.1765549, y: 3.7531407, z: 0, w: 1}
- {x: 1.2463952, y: 3.9316032, z: 0, w: 1}
- {x: 1.319611, y: 4.124672, z: 0, w: 1}
- {x: 1.3964823, y: 4.3340797, z: 0, w: 1}
- {x: 1.4773248, y: 4.561845, z: 0, w: 1}
- {x: 1.5624928, y: 4.810328, z: 0, w: 1}
- {x: 1.6523882, y: 5.082317, z: 0, w: 1}
- {x: 1.747467, y: 5.381122, z: 0, w: 1}
- {x: 1.8482518, y: 5.710715, z: 0, w: 1}
- {x: 1.9553448, y: 6.0759025, z: 0, w: 1}
- {x: 2.069445, y: 6.482568, z: 0, w: 1}
- {x: 2.1913698, y: 6.9379897, z: 0, w: 1}
- {x: 2.3220856, y: 7.4513016, z: 0, w: 1}
- {x: 2.4627466, y: 8.0341215, z: 0, w: 1}
- {x: 2.614747, y: 8.701484, z: 0, w: 1}
- {x: 2.7797952, y: 9.473195, z: 0, w: 1}
- {x: 2.9600194, y: 10.375936, z: 0, w: 1}
- {x: 3.1581159, y: 11.446505, z: 0, w: 1}
- {x: 3.3775842, y: 12.737201, z: 0, w: 1}
- {x: 3.6230793, y: 14.324919, z: 0, w: 1}
- {x: 3.9009922, y: 16.327562, z: 0, w: 1}
- {x: 4.220452, y: 18.935623, z: 0, w: 1}
- {x: 4.5951686, y: 22.478209, z: 0, w: 1}
- {x: 5.047148, y: 27.57712, z: 0, w: 1}
- {x: 5.615129, y: 35.564823, z: 0, w: 1}
- {x: 6.3776174, y: 49.90625, z: 0, w: 1}
- {x: 7.5374603, y: 83.30668, z: 0, w: 1}
- {x: 10.03481, y: 250.11497, z: 0, w: 1}
- {x: 0.013854082, y: 1.5332626, z: 0.036647703, w: 1.5641627}
- {x: 0.04207757, y: 1.5715919, z: 0.113649175, w: 1.671985}
- {x: 0.07101321, y: 1.611625, z: 0.19610003, w: 1.7934121}
- {x: 0.10069309, y: 1.653469, z: 0.28470552, w: 1.9309369}
- {x: 0.13115102, y: 1.6972395, z: 0.38030306, w: 2.0876582}
- {x: 0.16242325, y: 1.743061, z: 0.48389605, w: 2.2674706}
- {x: 0.19454831, y: 1.791069, z: 0.5966971, w: 2.4753277}
- {x: 0.22756726, y: 1.8414105, z: 0.72018707, w: 2.717616}
- {x: 0.2615238, y: 1.8942443, z: 0.85619545, w: 3.0026984}
- {x: 0.29646498, y: 1.9497447, z: 1.0070126, w: 3.3417335}
- {x: 0.33244094, y: 2.0081, z: 1.1755506, w: 3.749937}
- {x: 0.36950532, y: 2.069517, z: 1.3655809, w: 4.248627}
- {x: 0.40771604, y: 2.1342213, z: 1.5821002, w: 4.868682}
- {x: 0.44713485, y: 2.2024598, z: 1.8319175, w: 5.6567397}
- {x: 0.48782852, y: 2.274504, z: 2.1246579, w: 6.6871305}
- {x: 0.5298689, y: 2.3506513, z: 2.4745958, w: 8.086858}
- {x: 0.5733336, y: 2.4312308, z: 2.9043517, w: 10.094101}
- {x: 0.6183063, y: 2.5166042, z: 3.4533012, w: 13.217383}
- {x: 0.66487795, y: 2.6071734, z: 4.20053, w: 18.777578}
- {x: 0.71314675, y: 2.703383, z: 5.349281, w: 31.61934}
- {x: 0.76321995, y: 2.805728, z: 7.839332, w: 95.36225}
- {x: 0.81521386, y: 2.9147599, z: 0, w: 1}
- {x: 0.86925554, y: 3.031096, z: 0, w: 1}
- {x: 0.92548406, y: 3.1554284, z: 0, w: 1}
- {x: 0.9840515, y: 3.288537, z: 0, w: 1}
- {x: 1.0451256, y: 3.431302, z: 0, w: 1}
- {x: 1.1088905, y: 3.5847225, z: 0, w: 1}
- {x: 1.1755506, y: 3.749937, z: 0, w: 1}
- {x: 1.2453312, y: 3.9282467, z: 0, w: 1}
- {x: 1.3184844, y: 4.1211514, z: 0, w: 1}
- {x: 1.3952904, y: 4.3303804, z: 0, w: 1}
- {x: 1.4760638, y: 4.5579505, z: 0, w: 1}
- {x: 1.5611593, y: 4.8062224, z: 0, w: 1}
- {x: 1.650978, y: 5.0779796, z: 0, w: 1}
- {x: 1.7459753, y: 5.3765287, z: 0, w: 1}
- {x: 1.8466738, y: 5.7058387, z: 0, w: 1}
- {x: 1.9536757, y: 6.070716, z: 0, w: 1}
- {x: 2.0676782, y: 6.4770336, z: 0, w: 1}
- {x: 2.189499, y: 6.9320674, z: 0, w: 1}
- {x: 2.3201032, y: 7.4449396, z: 0, w: 1}
- {x: 2.4606442, y: 8.027264, z: 0, w: 1}
- {x: 2.612515, y: 8.694056, z: 0, w: 1}
- {x: 2.777422, y: 9.465107, z: 0, w: 1}
- {x: 2.9574924, y: 10.367077, z: 0, w: 1}
- {x: 3.1554203, y: 11.436736, z: 0, w: 1}
- {x: 3.3747015, y: 12.726331, z: 0, w: 1}
- {x: 3.6199868, y: 14.312694, z: 0, w: 1}
- {x: 3.897662, y: 16.313623, z: 0, w: 1}
- {x: 4.2168484, y: 18.919455, z: 0, w: 1}
- {x: 4.5912457, y: 22.459015, z: 0, w: 1}
- {x: 5.042839, y: 27.553566, z: 0, w: 1}
- {x: 5.610336, y: 35.534466, z: 0, w: 1}
- {x: 6.3721733, y: 49.863647, z: 0, w: 1}
- {x: 7.53103, y: 83.235695, z: 0, w: 1}
- {x: 10.026244, y: 249.90146, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
- {x: 0, y: 1, z: 0, w: 1}
useDisneySSS: 1
halfRcpWeightedVariances:
- {x: 2.4691355, y: 12.5, z: 12.5, w: 2.4691355}
- {x: 2.4691355, y: 2.4691355, z: 2.4691355, w: 2.4691355}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
halfRcpVariancesAndWeights:
- {x: 0.5, y: 1.125, z: 1.125, w: 2}
- {x: 0.125, y: 1.125, z: 1.125, w: 2}
- {x: 0.5, y: 0.5, z: 0.5, w: 2}
- {x: 0.125, y: 0.125, z: 0.125, w: 2}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 1, y: 1, z: 1, w: 1}
- {x: 0, y: 0, z: 0, w: 0}
- {x: 0, y: 0, z: 0, w: 0}
filterKernelsBasic:
- {x: 0.09090909, y: 0.21162307, z: 0.21162307, w: -0.000000048879357}
- {x: 0.09090909, y: 0.18990478, z: 0.18990478, w: -0.11381993}
- {x: 0.09090909, y: 0.13233659, z: 0.13233659, w: -0.23580086}
- {x: 0.09090909, y: 0.061445467, z: 0.061445467, w: -0.37865555}
- {x: 0.09090909, y: 0.010501689, z: 0.010501689, w: -0.57677805}
- {x: 0.09090909, y: 2.9458339e-10, z: 2.9458339e-10, w: -1.3907351}
- {x: 0.09090909, y: 0.18990476, z: 0.18990476, w: 0.11382001}
- {x: 0.09090909, y: 0.13233659, z: 0.13233659, w: 0.23580086}
- {x: 0.09090909, y: 0.061445467, z: 0.061445467, w: 0.37865555}
- {x: 0.09090909, y: 0.010501689, z: 0.010501689, w: 0.57677805}
- {x: 0.09090909, y: 2.9456845e-10, z: 2.9456845e-10, w: 1.3907368}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.000000048879357}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.11381993}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.23580086}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.37865555}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.57677805}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -1.3907351}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.11382001}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.23580086}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.37865555}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.57677805}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 1.3907368}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
- {x: 1, y: 1, z: 1, w: 0}
sssSettings: {fileID: 11400000, guid: 873499ce7a6f749408981f512a9683f7, type: 2}
tileSettings:
enableTileAndCluster: 1
enableComputeLightEvaluation: 1

3
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs


// Renderer Settings
public RenderingSettings renderingSettings = new RenderingSettings();
public SubsurfaceScatteringSettings sssSettings = new SubsurfaceScatteringSettings();
public SubsurfaceScatteringSettings sssSettings;
public TileSettings tileSettings = new TileSettings();
// Shadow Settings

public void OnValidate()
{
sssSettings.OnValidate();
}
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDStringConstants.cs


public static readonly int _InputCubemap = Shader.PropertyToID("_InputCubemap");
public static readonly int _Mipmap = Shader.PropertyToID("_Mipmap");
public static readonly int _SubsurfaceProfile = Shader.PropertyToID("_SubsurfaceProfile");
public static readonly int _MaxRadius = Shader.PropertyToID("_MaxRadius");
public static readonly int _ShapeParam = Shader.PropertyToID("_ShapeParam");
public static readonly int _StdDev1 = Shader.PropertyToID("_StdDev1");

42
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs


using (var o = new PropertyFetcher<HDAdditionalLightData>(m_SerializedAdditionalLightData))
m_AdditionalLightData = new SerializedLightData
{
spotInnerPercent = o.FindProperty(x => x.m_InnerSpotPercent),
lightDimmer = o.FindProperty(x => x.lightDimmer),
fadeDistance = o.FindProperty(x => x.fadeDistance),
affectDiffuse = o.FindProperty(x => x.affectDiffuse),
affectSpecular = o.FindProperty(x => x.affectSpecular),
lightTypeExtent = o.FindProperty(x => x.lightTypeExtent),
spotLightShape = o.FindProperty(x => x.spotLightShape),
shapeLength = o.FindProperty(x => x.shapeLength),
shapeWidth = o.FindProperty(x => x.shapeWidth),
shapeRadius = o.FindProperty(x => x.shapeRadius),
maxSmoothness = o.FindProperty(x => x.maxSmoothness),
applyRangeAttenuation = o.FindProperty(x => x.applyRangeAttenuation),
spotInnerPercent = o.Find(x => x.m_InnerSpotPercent),
lightDimmer = o.Find(x => x.lightDimmer),
fadeDistance = o.Find(x => x.fadeDistance),
affectDiffuse = o.Find(x => x.affectDiffuse),
affectSpecular = o.Find(x => x.affectSpecular),
lightTypeExtent = o.Find(x => x.lightTypeExtent),
spotLightShape = o.Find(x => x.spotLightShape),
shapeLength = o.Find(x => x.shapeLength),
shapeWidth = o.Find(x => x.shapeWidth),
shapeRadius = o.Find(x => x.shapeRadius),
maxSmoothness = o.Find(x => x.maxSmoothness),
applyRangeAttenuation = o.Find(x => x.applyRangeAttenuation),
useOldInspector = o.FindProperty(x => x.useOldInspector),
showFeatures = o.FindProperty(x => x.featuresFoldout),
showAdditionalSettings = o.FindProperty(x => x.showAdditionalSettings)
useOldInspector = o.Find(x => x.useOldInspector),
showFeatures = o.Find(x => x.featuresFoldout),
showAdditionalSettings = o.Find(x => x.showAdditionalSettings)
};
// TODO: Review this once AdditionalShadowData is refactored

dimmer = o.FindProperty(x => x.shadowDimmer),
fadeDistance = o.FindProperty(x => x.shadowFadeDistance),
cascadeCount = o.FindProperty("shadowCascadeCount"),
cascadeRatios = o.FindProperty("shadowCascadeRatios"),
cascadeBorders = o.FindProperty("shadowCascadeBorders"),
resolution = o.FindProperty(x => x.shadowResolution)
dimmer = o.Find(x => x.shadowDimmer),
fadeDistance = o.Find(x => x.shadowFadeDistance),
cascadeCount = o.Find("shadowCascadeCount"),
cascadeRatios = o.Find("shadowCascadeRatios"),
cascadeBorders = o.Find("shadowCascadeBorders"),
resolution = o.Find(x => x.shadowResolution)
};
}

64
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


using System;
using UnityEngine;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;

protected MaterialProperty anisotropyMap = null;
protected const string kAnisotropyMap = "_AnisotropyMap";
protected SubsurfaceScatteringProfile subsurfaceProfile = null;
protected MaterialProperty subsurfaceProfileID = null;
protected const string kSubsurfaceProfileID = "_SubsurfaceProfile";
protected MaterialProperty subsurfaceRadius = null;

protected void ShaderSSSInputGUI(Material material)
{
HDRenderPipeline hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
var sssSettings = hdPipeline.sssSettings;
if (subsurfaceProfile == null)
if (sssSettings == null)
// Attempt to load the profile from the SSS Settings.
int profileID = (int)subsurfaceProfileID.floatValue;
if (0 <= profileID && profileID < hdPipeline.sssSettings.profiles.Length &&
hdPipeline.sssSettings.profiles[profileID] != null)
{
// This is a valid profile ID.
subsurfaceProfile = hdPipeline.sssSettings.profiles[profileID];
// Refresh the ID of the profile.
hdPipeline.sssSettings.OnValidate();
}
EditorGUILayout.HelpBox("No Subsurface Scattering Settings have been assigned to the render pipeline asset.", MessageType.Warning);
return;
subsurfaceProfile = EditorGUILayout.ObjectField(Styles.subsurfaceProfileText, subsurfaceProfile, typeof(SubsurfaceScatteringProfile), false) as SubsurfaceScatteringProfile;
// TODO: Optimize me
var profiles = hdPipeline.sssSettings.profiles;
var names = new GUIContent[profiles.Length + 1];
names[0] = new GUIContent("None");
bool validProfile = false;
var values = new int[names.Length];
values[0] = SssConstants.SSS_NEUTRAL_PROFILE_ID;
// Set the profile ID.
if (subsurfaceProfile != null)
for (int i = 0; i < profiles.Length; i++)
// Load the profile from the GUI field.
int profileID = subsurfaceProfile.settingsIndex;
if (0 <= profileID && profileID < hdPipeline.sssSettings.profiles.Length &&
hdPipeline.sssSettings.profiles[profileID] != null &&
hdPipeline.sssSettings.profiles[profileID] == subsurfaceProfile)
{
validProfile = true;
material.SetInt("_SubsurfaceProfile", profileID);
}
else
{
subsurfaceProfile = null;
Debug.LogError("The SSS Profile assigned to the material has an invalid index. First, add the Profile to the SSS Settings, and then reassign it to the material.");
}
names[i + 1] = new GUIContent(profiles[i].name);
values[i + 1] = i;
if (!validProfile)
using (var scope = new EditorGUI.ChangeCheckScope())
// Disable SSS for this object.
material.SetInt("_SubsurfaceProfile", SssConstants.SSS_NEUTRAL_PROFILE_ID);
int profileID = (int)subsurfaceProfileID.floatValue;
profileID = EditorGUILayout.IntPopup(Styles.subsurfaceProfileText, profileID, names, values);
if (scope.changed)
subsurfaceProfileID.floatValue = profileID;
}
m_MaterialEditor.ShaderProperty(subsurfaceRadius, Styles.subsurfaceRadiusText);

// TODO: display warning if we don't have bent normal (either OS or TS) and ambient occlusion
//if (enableSpecularOcclusion.floatValue > 0.0f)
{
//EditorGUILayout.HelpBox(Styles.specularOcclusionWarning.text, MessageType.Error);
//EditorGUILayout.HelpBox(Styles.specularOcclusionWarning.text, MessageType.Error);
EditorGUI.indentLevel++;
EditorGUI.indentLevel++;
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveText, emissiveColorMap, emissiveColor);
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
m_MaterialEditor.ShaderProperty(albedoAffectEmissive, Styles.albedoAffectEmissiveText);

5
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs


namespace UnityEditor.Experimental.Rendering.HDPipeline
{
partial class SubsurfaceScatteringProfileEditor
public sealed partial class SubsurfaceScatteringSettingsEditor
// TODO: missing tooltips
public readonly GUIContent useDisneySSS = new GUIContent("Use Disney SSS");
public readonly GUIContent profilePreview0 = new GUIContent("Profile Preview");
public readonly GUIContent profilePreview1 = new GUIContent("Shows the fraction of light scattered from the source (center).");
public readonly GUIContent profilePreview2 = new GUIContent("The distance to the boundary of the image corresponds to the Max Radius.");

4
ScriptableRenderPipeline/LightweightPipeline/Editor/ShaderGUI/LightweightStandardGUI.cs


public static readonly string[] specularSmoothnessChannelNames = {"Specular Alpha", "Albedo Alpha"};
}
#pragma warning disable CS0414
#pragma warning disable 0414
private MaterialProperty workflowMode = null;
private MaterialProperty blendMode = null;

private ColorPickerHDRConfig m_ColorPickerHDRConfig = new ColorPickerHDRConfig(0f, kMaxfp16, 1 / kMaxfp16, 3f);
private bool m_FirstTimeApply = true;
#pragma warning restore CS0414
#pragma warning restore 0414
public void FindProperties(MaterialProperty[] props)
{

53
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDBaseEditor.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
using UnityObject = UnityEngine.Object;
//
// Sample use:
//
// [CustomEditor(typeof(TestComponent)]
// class TestEditor : HDBaseEditor<TestComponent>
// {
// SerializedProperty m_MyFloat;
//
// protected override void OnEnable()
// {
// base.OnEnable();
// m_MyFloat = properties.Find(x => x.myFloat);
// }
//
// public override void OnInspectorGUI()
// {
// EditorGUILayout.PropertyField(m_MyFloat);
// }
// }
//
public class HDBaseEditor<T> : Editor
where T : UnityObject
{
internal PropertyFetcher<T> properties { get; private set; }
protected T m_Target
{
get { return target as T; }
}
protected T[] m_Targets
{
get { return targets as T[]; }
}
protected HDRenderPipeline m_HDPipeline
{
get { return RenderPipelineManager.currentPipeline as HDRenderPipeline; }
}
protected virtual void OnEnable()
{
properties = new PropertyFetcher<T>(serializedObject);
}
}
}

13
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDBaseEditor.cs.meta


fileFormatVersion: 2
guid: 4db007e1d2c155d4a80e2a38f39b39ff
timeCreated: 1507624455
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

56
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.Styles.cs


using UnityEngine;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public sealed partial class HDRenderPipelineInspector
{
// TODO: missing tooltips
sealed class Styles
{
public readonly GUIContent defaults = new GUIContent("Defaults");
public readonly GUIContent defaultDiffuseMaterial = new GUIContent("Default Diffuse Material", "Material to use when creating objects");
public readonly GUIContent defaultShader = new GUIContent("Default Shader", "Shader to use when creating materials");
public readonly GUIContent settingsLabel = new GUIContent("Settings");
// Rendering Settings
public readonly GUIContent renderingSettingsLabel = new GUIContent("Rendering Settings");
public readonly GUIContent useForwardRenderingOnly = new GUIContent("Use Forward Rendering Only");
public readonly GUIContent useDepthPrepassWithDeferredRendering = new GUIContent("Use Depth Prepass with Deferred rendering");
public readonly GUIContent renderAlphaTestOnlyInDeferredPrepass = new GUIContent("Alpha Test Only");
// Texture Settings
public readonly GUIContent textureSettings = new GUIContent("Texture Settings");
public readonly GUIContent spotCookieSize = new GUIContent("Spot Cookie Size");
public readonly GUIContent pointCookieSize = new GUIContent("Point Cookie Size");
public readonly GUIContent reflectionCubemapSize = new GUIContent("Reflection Cubemap Size");
public readonly GUIContent sssSettings = new GUIContent("Subsurface Scattering Settings");
// Shadow Settings
public readonly GUIContent shadowSettings = new GUIContent("Shadow Settings");
public readonly GUIContent shadowsAtlasWidth = new GUIContent("Atlas Width");
public readonly GUIContent shadowsAtlasHeight = new GUIContent("Atlas Height");
// Tile pass Settings
public readonly GUIContent tileLightLoopSettings = new GUIContent("Tile Light Loop Settings");
public readonly GUIContent enableTileAndCluster = new GUIContent("Tile/Clustered");
public readonly GUIContent enableComputeLightEvaluation = new GUIContent("Compute Light Evaluation");
public readonly GUIContent enableComputeLightVariants = new GUIContent("Compute Light Variants");
public readonly GUIContent enableComputeMaterialVariants = new GUIContent("Compute Material Variants");
public readonly GUIContent enableClustered = new GUIContent("Clustered");
public readonly GUIContent enableFptlForOpaqueWhenClustered = new GUIContent("Fptl For Opaque When Clustered");
public readonly GUIContent enableBigTilePrepass = new GUIContent("Big tile prepass");
}
static Styles s_Styles;
// Can't use a static initializer in case we need to create GUIStyle in the Styles class as
// these can only be created with an active GUI rendering context
void CheckStyles()
{
if (s_Styles == null)
s_Styles = new Styles();
}
}
}

13
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.Styles.cs.meta


fileFormatVersion: 2
guid: eaef7e9439aa2fb4093fa259575623d4
timeCreated: 1507717754
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs.meta


fileFormatVersion: 2
guid: 95517c3b2f4a014468289c3f5eb6d03c
timeCreated: 1507562538
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

258
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[CustomEditor(typeof(SubsurfaceScatteringSettings))]
public sealed partial class SubsurfaceScatteringSettingsEditor : HDBaseEditor<SubsurfaceScatteringSettings>
{
sealed class Profile
{
internal SerializedProperty self;
internal SubsurfaceScatteringProfile objReference;
internal SerializedProperty name;
internal SerializedProperty scatteringDistance;
internal SerializedProperty transmissionTint;
internal SerializedProperty texturingMode;
internal SerializedProperty transmissionMode;
internal SerializedProperty thicknessRemap;
internal SerializedProperty worldScale;
// Old SSS Model >>>
internal SerializedProperty scatterDistance1;
internal SerializedProperty scatterDistance2;
internal SerializedProperty lerpWeight;
// <<< Old SSS Model
// Render preview
internal RenderTexture profileRT;
internal RenderTexture transmittanceRT;
internal Profile()
{
profileRT = new RenderTexture(256, 256, 0, RenderTextureFormat.DefaultHDR);
transmittanceRT = new RenderTexture( 16, 256, 0, RenderTextureFormat.DefaultHDR);
}
internal void Release()
{
CoreUtils.Destroy(profileRT);
CoreUtils.Destroy(transmittanceRT);
}
}
SerializedProperty m_UseDisneySSS;
List<Profile> m_Profiles;
Material m_ProfileMaterial;
Material m_TransmittanceMaterial;
protected override void OnEnable()
{
base.OnEnable();
// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime
m_ProfileMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawSssProfile");
m_TransmittanceMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawTransmittanceGraph");
int count = SssConstants.SSS_N_PROFILES - 1;
m_Profiles = new List<Profile>();
m_UseDisneySSS = properties.Find(x => x.useDisneySSS);
var serializedProfiles = properties.Find(x => x.profiles);
for (int i = 0; i < count; i++)
{
var serializedProfile = serializedProfiles.GetArrayElementAtIndex(i);
var rp = new RelativePropertyFetcher<SubsurfaceScatteringProfile>(serializedProfile);
var profile = new Profile
{
self = serializedProfile,
objReference = m_Target.profiles[i],
name = rp.Find(x => x.name),
scatteringDistance = rp.Find(x => x.scatteringDistance),
transmissionTint = rp.Find(x => x.transmissionTint),
texturingMode = rp.Find(x => x.texturingMode),
transmissionMode = rp.Find(x => x.transmissionMode),
thicknessRemap = rp.Find(x => x.thicknessRemap),
worldScale = rp.Find(x => x.worldScale),
scatterDistance1 = rp.Find(x => x.scatterDistance1),
scatterDistance2 = rp.Find(x => x.scatterDistance2),
lerpWeight = rp.Find(x => x.lerpWeight)
};
m_Profiles.Add(profile);
}
}
void OnDisable()
{
CoreUtils.Destroy(m_ProfileMaterial);
CoreUtils.Destroy(m_TransmittanceMaterial);
foreach (var profile in m_Profiles)
profile.Release();
m_Profiles = null;
}
public override void OnInspectorGUI()
{
CheckStyles();
// Display a warning if this settings asset is not currently in use
if (m_HDPipeline == null || m_HDPipeline.sssSettings != m_Target)
EditorGUILayout.HelpBox("These profiles aren't currently in use, assign this asset to the HD render pipeline asset to use them.", MessageType.Warning);
serializedObject.Update();
using (var scope = new EditorGUI.ChangeCheckScope())
{
EditorGUILayout.PropertyField(m_UseDisneySSS, s_Styles.useDisneySSS);
if (scope.changed && m_HDPipeline != null)
m_HDPipeline.CreateSssMaterials();
}
EditorGUILayout.Space();
if (m_Profiles == null || m_Profiles.Count == 0)
return;
bool useDisneySSS = m_UseDisneySSS.boolValue;
for (int i = 0; i < m_Profiles.Count; i++)
{
var profile = m_Profiles[i];
CoreEditorUtils.DrawSplitter();
bool state = profile.self.isExpanded;
state = CoreEditorUtils.DrawHeaderFoldout(profile.name.stringValue, state);
if (state)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(profile.name);
using (var scope = new EditorGUI.ChangeCheckScope())
{
if (useDisneySSS)
{
EditorGUILayout.PropertyField(profile.scatteringDistance, s_Styles.profileScatteringDistance);
using (new EditorGUI.DisabledScope(true))
EditorGUILayout.FloatField(s_Styles.profileMaxRadius, profile.objReference.maxRadius);
}
else
{
EditorGUILayout.PropertyField(profile.scatterDistance1, s_Styles.profileScatterDistance1);
EditorGUILayout.PropertyField(profile.scatterDistance2, s_Styles.profileScatterDistance2);
EditorGUILayout.PropertyField(profile.lerpWeight, s_Styles.profileLerpWeight);
}
profile.texturingMode.intValue = EditorGUILayout.Popup(s_Styles.texturingMode, profile.texturingMode.intValue, s_Styles.texturingModeOptions);
profile.transmissionMode.intValue = EditorGUILayout.Popup(s_Styles.profileTransmissionMode, profile.transmissionMode.intValue, s_Styles.transmissionModeOptions);
EditorGUILayout.PropertyField(profile.transmissionTint, s_Styles.profileTransmissionTint);
EditorGUILayout.PropertyField(profile.thicknessRemap, s_Styles.profileMinMaxThickness);
var thicknessRemap = profile.thicknessRemap.vector2Value;
EditorGUILayout.MinMaxSlider(s_Styles.profileThicknessRemap, ref thicknessRemap.x, ref thicknessRemap.y, 0f, 50f);
profile.thicknessRemap.vector2Value = thicknessRemap;
EditorGUILayout.PropertyField(profile.worldScale, s_Styles.profileWorldScale);
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.profilePreview0, s_Styles.centeredMiniBoldLabel);
EditorGUILayout.LabelField(s_Styles.profilePreview1, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(s_Styles.profilePreview2, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(s_Styles.profilePreview3, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space();
serializedObject.ApplyModifiedProperties();
if (scope.changed)
{
// Validate and update the cache for this profile only
profile.objReference.Validate();
m_Target.UpdateCache(i);
}
}
RenderPreview(profile, useDisneySSS);
EditorGUILayout.Space();
EditorGUI.indentLevel--;
}
profile.self.isExpanded = state;
}
CoreEditorUtils.DrawSplitter();
serializedObject.ApplyModifiedProperties();
}
void RenderPreview(Profile profile, bool useDisneySSS)
{
var obj = profile.objReference;
float r = obj.maxRadius;
var S = obj.shapeParam;
var T = (Vector4)profile.transmissionTint.colorValue;
var R = profile.thicknessRemap.vector2Value;
bool transmissionEnabled = profile.transmissionMode.intValue != (int)SubsurfaceScatteringProfile.TransmissionMode.None;
m_ProfileMaterial.SetFloat(HDShaderIDs._MaxRadius, r);
m_ProfileMaterial.SetVector(HDShaderIDs._ShapeParam, S);
// Old SSS Model >>>
CoreUtils.SelectKeyword(m_ProfileMaterial, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", useDisneySSS);
// Apply the three-sigma rule, and rescale.
float s = (1f / 3f) * SssConstants.SSS_BASIC_DISTANCE_SCALE;
var scatterDist1 = profile.scatterDistance1.colorValue;
var scatterDist2 = profile.scatterDistance2.colorValue;
float rMax = Mathf.Max(scatterDist1.r, scatterDist1.g, scatterDist1.b,
scatterDist2.r, scatterDist2.g, scatterDist2.b);
var stdDev1 = s * (Vector4)scatterDist1;
var stdDev2 = s * (Vector4)scatterDist2;
m_ProfileMaterial.SetVector(HDShaderIDs._StdDev1, stdDev1);
m_ProfileMaterial.SetVector(HDShaderIDs._StdDev2, stdDev2);
m_ProfileMaterial.SetFloat(HDShaderIDs._LerpWeight, profile.lerpWeight.floatValue);
m_ProfileMaterial.SetFloat(HDShaderIDs._MaxRadius, rMax);
// <<< Old SSS Model
// Draw the profile.
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(256f, 256f), profile.profileRT, m_ProfileMaterial, ScaleMode.ScaleToFit, 1f);
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.transmittancePreview0, s_Styles.centeredMiniBoldLabel);
EditorGUILayout.LabelField(s_Styles.transmittancePreview1, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(s_Styles.transmittancePreview2, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space();
// Old SSS Model >>>
// Multiply by 0.1 to convert from millimeters to centimeters. Apply the distance scale.
float a = 0.1f * SssConstants.SSS_BASIC_DISTANCE_SCALE;
var halfRcpVarianceAndWeight1 = new Vector4(a * a * 0.5f / (stdDev1.x * stdDev1.x), a * a * 0.5f / (stdDev1.y * stdDev1.y), a * a * 0.5f / (stdDev1.z * stdDev1.z), 4f * (1f - profile.lerpWeight.floatValue));
var halfRcpVarianceAndWeight2 = new Vector4(a * a * 0.5f / (stdDev2.x * stdDev2.x), a * a * 0.5f / (stdDev2.y * stdDev2.y), a * a * 0.5f / (stdDev2.z * stdDev2.z), 4f * profile.lerpWeight.floatValue);
m_TransmittanceMaterial.SetVector(HDShaderIDs._HalfRcpVarianceAndWeight1, halfRcpVarianceAndWeight1);
m_TransmittanceMaterial.SetVector(HDShaderIDs._HalfRcpVarianceAndWeight2, halfRcpVarianceAndWeight2);
// <<< Old SSS Model
m_TransmittanceMaterial.SetVector(HDShaderIDs._ShapeParam, S);
m_TransmittanceMaterial.SetVector(HDShaderIDs._TransmissionTint, transmissionEnabled ? T : Vector4.zero);
m_TransmittanceMaterial.SetVector(HDShaderIDs._ThicknessRemap, R);
// Draw the transmittance graph.
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(16f, 16f), profile.transmittanceRT, m_TransmittanceMaterial, ScaleMode.ScaleToFit, 16f);
}
}
}

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.cs.meta


fileFormatVersion: 2
guid: a61a2437dcee4e54393f8f65ccf726ab
timeCreated: 1507562486
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

85
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SSS Settings.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3418a08abd15e9a49af3ccbc9e15b5ea, type: 3}
m_Name: SSS Settings
m_EditorClassIdentifier:
useDisneySSS: 1
profiles:
- name: Skin
scatteringDistance: {r: 0.7568628, g: 0.32156864, b: 0.20000002, a: 1}
transmissionTint: {r: 0.7568628, g: 0.32156864, b: 0.20000002, a: 1}
texturingMode: 0
transmissionMode: 2
thicknessRemap: {x: 0, y: 8.152544}
worldScale: 1
scatterDistance1: {r: 0.3019608, g: 0.20000002, b: 0.20000002, a: 0}
scatterDistance2: {r: 0.6, g: 0.20000002, b: 0.20000002, a: 0}
lerpWeight: 0.5
- name: Foliage
scatteringDistance: {r: 0.7568628, g: 0.7019608, b: 0.24313727, a: 1}
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
texturingMode: 0
transmissionMode: 1
thicknessRemap: {x: 0, y: 0.2873168}
worldScale: 1
scatterDistance1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
scatterDistance2: {r: 0.5, g: 0.5, b: 0.5, a: 0}
lerpWeight: 0.5
- name: Profile 2
scatteringDistance: {r: 0.5, g: 0.5, b: 0.5, a: 1}
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
texturingMode: 0
transmissionMode: 0
thicknessRemap: {x: 0, y: 5}
worldScale: 1
scatterDistance1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
scatterDistance2: {r: 0.5, g: 0.5, b: 0.5, a: 0}
lerpWeight: 1
- name: Profile 3
scatteringDistance: {r: 0.5, g: 0.5, b: 0.5, a: 1}
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
texturingMode: 0
transmissionMode: 0
thicknessRemap: {x: 0, y: 5}
worldScale: 1
scatterDistance1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
scatterDistance2: {r: 0.5, g: 0.5, b: 0.5, a: 0}
lerpWeight: 1
- name: Profile 4
scatteringDistance: {r: 0.5, g: 0.5, b: 0.5, a: 1}
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
texturingMode: 0
transmissionMode: 0
thicknessRemap: {x: 0, y: 5}
worldScale: 1
scatterDistance1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
scatterDistance2: {r: 0.5, g: 0.5, b: 0.5, a: 0}
lerpWeight: 1
- name: Profile 5
scatteringDistance: {r: 0.5, g: 0.5, b: 0.5, a: 1}
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
texturingMode: 0
transmissionMode: 0
thicknessRemap: {x: 0, y: 5}
worldScale: 1
scatterDistance1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
scatterDistance2: {r: 0.5, g: 0.5, b: 0.5, a: 0}
lerpWeight: 1
- name: Profile 6
scatteringDistance: {r: 0.5, g: 0.5, b: 0.5, a: 1}
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
texturingMode: 0
transmissionMode: 0
thicknessRemap: {x: 0, y: 5}
worldScale: 1
scatterDistance1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
scatterDistance2: {r: 0.5, g: 0.5, b: 0.5, a: 0}
lerpWeight: 1

10
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SSS Settings.asset.meta


fileFormatVersion: 2
guid: 873499ce7a6f749408981f512a9683f7
timeCreated: 1507649491
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

508
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs


using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[GenerateHLSL]
public class SssConstants
{
public const int SSS_N_PROFILES = 8; // Max. number of profiles, including the slot taken by the neutral profile
public const int SSS_NEUTRAL_PROFILE_ID = SSS_N_PROFILES - 1; // Does not result in blurring
public const int SSS_N_SAMPLES_NEAR_FIELD = 55; // Used for extreme close ups; must be a Fibonacci number
public const int SSS_N_SAMPLES_FAR_FIELD = 21; // Used at a regular distance; must be a Fibonacci number
public const int SSS_LOD_THRESHOLD = 4; // The LoD threshold of the near-field kernel (in pixels)
public const int SSS_TRSM_MODE_NONE = 0;
public const int SSS_TRSM_MODE_THIN = 1;
// Old SSS Model >>>
public const int SSS_BASIC_N_SAMPLES = 11; // Must be an odd number
public const int SSS_BASIC_DISTANCE_SCALE = 3; // SSS distance units per centimeter
// <<< Old SSS Model
}
[Serializable]
public sealed class SubsurfaceScatteringProfile
{
public enum TexturingMode : uint
{
PreAndPostScatter = 0,
PostScatter = 1
}
public enum TransmissionMode : uint
{
None = SssConstants.SSS_TRSM_MODE_NONE,
ThinObject = SssConstants.SSS_TRSM_MODE_THIN,
Regular
}
public string name;
[ColorUsage(false, true, 0f, 8f, 0.125f, 3f)]
public Color scatteringDistance; // Per color channel (no meaningful units)
[ColorUsage(false)]
public Color transmissionTint; // Color, 0 to 1
public TexturingMode texturingMode;
public TransmissionMode transmissionMode;
public Vector2 thicknessRemap; // X = min, Y = max (in millimeters)
public float worldScale; // Size of the world unit in meters
// Old SSS Model >>>
[ColorUsage(false, true, 0f, 8f, 0.125f, 3f)]
public Color scatterDistance1;
[ColorUsage(false, true, 0f, 8f, 0.125f, 3f)]
public Color scatterDistance2;
[Range(0f, 1f)]
public float lerpWeight;
// <<< Old SSS Model
public Vector3 shapeParam { get; private set; } // RGB = shape parameter: S = 1 / D
public float maxRadius { get; private set; } // In millimeters
public Vector2[] filterKernelNearField { get; private set; } // X = radius, Y = reciprocal of the PDF
public Vector2[] filterKernelFarField { get; private set; } // X = radius, Y = reciprocal of the PDF
public Vector4 halfRcpWeightedVariances { get; private set; }
public Vector4[] filterKernelBasic { get; private set; }
public SubsurfaceScatteringProfile(string name)
{
this.name = name;
scatteringDistance = Color.grey;
transmissionTint = Color.white;
texturingMode = TexturingMode.PreAndPostScatter;
transmissionMode = TransmissionMode.None;
thicknessRemap = new Vector2(0f, 5f);
worldScale = 1f;
// Old SSS Model >>>
scatterDistance1 = new Color(0.3f, 0.3f, 0.3f, 0f);
scatterDistance2 = new Color(0.5f, 0.5f, 0.5f, 0f);
lerpWeight = 1f;
// <<< Old SSS Model
}
public void Validate()
{
thicknessRemap.y = Mathf.Max(thicknessRemap.y, 0f);
thicknessRemap.x = Mathf.Clamp(thicknessRemap.x, 0f, thicknessRemap.y);
worldScale = Mathf.Max(worldScale, 0.001f);
// Old SSS Model >>>
scatterDistance1 = new Color
{
r = Mathf.Max(0.05f, scatterDistance1.r),
g = Mathf.Max(0.05f, scatterDistance1.g),
b = Mathf.Max(0.05f, scatterDistance1.b),
a = 0.0f
};
scatterDistance2 = new Color
{
r = Mathf.Max(0.05f, scatterDistance2.r),
g = Mathf.Max(0.05f, scatterDistance2.g),
b = Mathf.Max(0.05f, scatterDistance2.b),
a = 0f
};
// <<< Old SSS Model
UpdateKernel();
}
// Ref: Approximate Reflectance Profiles for Efficient Subsurface Scattering by Pixar.
public void UpdateKernel()
{
if (filterKernelNearField == null || filterKernelNearField.Length != SssConstants.SSS_N_SAMPLES_NEAR_FIELD)
filterKernelNearField = new Vector2[SssConstants.SSS_N_SAMPLES_NEAR_FIELD];
if (filterKernelFarField == null || filterKernelFarField.Length != SssConstants.SSS_N_SAMPLES_FAR_FIELD)
filterKernelFarField = new Vector2[SssConstants.SSS_N_SAMPLES_FAR_FIELD];
// Clamp to avoid artifacts.
shapeParam = new Vector3(
1f / Mathf.Max(0.001f, scatteringDistance.r),
1f / Mathf.Max(0.001f, scatteringDistance.g),
1f / Mathf.Max(0.001f, scatteringDistance.b)
);
// We importance sample the color channel with the widest scattering distance.
float s = Mathf.Min(shapeParam.x, shapeParam.y, shapeParam.z);
// Importance sample the normalized diffusion profile for the computed value of 's'.
// ------------------------------------------------------------------------------------
// R(r, s) = s * (Exp[-r * s] + Exp[-r * s / 3]) / (8 * Pi * r)
// PDF(r, s) = s * (Exp[-r * s] + Exp[-r * s / 3]) / 4
// CDF(r, s) = 1 - 1/4 * Exp[-r * s] - 3/4 * Exp[-r * s / 3]
// ------------------------------------------------------------------------------------
// Importance sample the near field kernel.
for (int i = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; i < n; i++)
{
float p = (i + 0.5f) * (1f / n);
float r = KernelCdfInverse(p, s);
// N.b.: computation of normalized weights, and multiplication by the surface albedo
// of the actual geometry is performed at runtime (in the shader).
filterKernelNearField[i].x = r;
filterKernelNearField[i].y = 1f / KernelPdf(r, s);
}
// Importance sample the far field kernel.
for (int i = 0, n = SssConstants.SSS_N_SAMPLES_FAR_FIELD; i < n; i++)
{
float p = (i + 0.5f) * (1f / n);
float r = KernelCdfInverse(p, s);
// N.b.: computation of normalized weights, and multiplication by the surface albedo
// of the actual geometry is performed at runtime (in the shader).
filterKernelFarField[i].x = r;
filterKernelFarField[i].y = 1f / KernelPdf(r, s);
}
maxRadius = filterKernelFarField[SssConstants.SSS_N_SAMPLES_FAR_FIELD - 1].x;
// Old SSS Model >>>
UpdateKernelAndVarianceData();
// <<< Old SSS Model
}
// Old SSS Model >>>
public void UpdateKernelAndVarianceData()
{
const int kNumSamples = SssConstants.SSS_BASIC_N_SAMPLES;
const int kDistanceScale = SssConstants.SSS_BASIC_DISTANCE_SCALE;
if (filterKernelBasic == null || filterKernelBasic.Length != kNumSamples)
filterKernelBasic = new Vector4[kNumSamples];
// Apply the three-sigma rule, and rescale.
var stdDev1 = ((1f / 3f) * kDistanceScale) * scatterDistance1;
var stdDev2 = ((1f / 3f) * kDistanceScale) * scatterDistance2;
// Our goal is to blur the image using a filter which is represented
// as a product of a linear combination of two normalized 1D Gaussians
// as suggested by Jimenez et al. in "Separable Subsurface Scattering".
// A normalized (i.e. energy-preserving) 1D Gaussian with the mean of 0
// is defined as follows: G1(x, v) = exp(-x * x / (2 * v)) / sqrt(2 * Pi * v),
// where 'v' is variance and 'x' is the radial distance from the origin.
// Using the weight 'w', our 1D and the resulting 2D filters are given as:
// A1(v1, v2, w, x) = G1(x, v1) * (1 - w) + G1(r, v2) * w,
// A2(v1, v2, w, x, y) = A1(v1, v2, w, x) * A1(v1, v2, w, y).
// The resulting filter function is a non-Gaussian PDF.
// It is separable by design, but generally not radially symmetric.
// N.b.: our scattering distance is rather limited. Therefore, in order to allow
// for a greater range of standard deviation values for flatter profiles,
// we rescale the world using 'distanceScale', effectively reducing the SSS
// distance units from centimeters to (1 / distanceScale).
// Find the widest Gaussian across 3 color channels.
float maxStdDev1 = Mathf.Max(stdDev1.r, stdDev1.g, stdDev1.b);
float maxStdDev2 = Mathf.Max(stdDev2.r, stdDev2.g, stdDev2.b);
var weightSum = Vector3.zero;
float step = 1f / (kNumSamples - 1);
// Importance sample the linear combination of two Gaussians.
for (int i = 0; i < kNumSamples; i++)
{
// Generate 'u' on (0, 0.5] and (0.5, 1).
float u = (i <= kNumSamples / 2) ? 0.5f - i * step // The center and to the left
: i * step; // From the center to the right
u = Mathf.Clamp(u, 0.001f, 0.999f);
float pos = GaussianCombinationCdfInverse(u, maxStdDev1, maxStdDev2, lerpWeight);
float pdf = GaussianCombination(pos, maxStdDev1, maxStdDev2, lerpWeight);
Vector3 val;
val.x = GaussianCombination(pos, stdDev1.r, stdDev2.r, lerpWeight);
val.y = GaussianCombination(pos, stdDev1.g, stdDev2.g, lerpWeight);
val.z = GaussianCombination(pos, stdDev1.b, stdDev2.b, lerpWeight);
// We do not divide by 'numSamples' since we will renormalize, anyway.
filterKernelBasic[i].x = val.x * (1 / pdf);
filterKernelBasic[i].y = val.y * (1 / pdf);
filterKernelBasic[i].z = val.z * (1 / pdf);
filterKernelBasic[i].w = pos;
weightSum.x += filterKernelBasic[i].x;
weightSum.y += filterKernelBasic[i].y;
weightSum.z += filterKernelBasic[i].z;
}
// Renormalize the weights to conserve energy.
for (int i = 0; i < kNumSamples; i++)
{
filterKernelBasic[i].x *= 1 / weightSum.x;
filterKernelBasic[i].y *= 1 / weightSum.y;
filterKernelBasic[i].z *= 1 / weightSum.z;
}
Vector4 weightedStdDev;
weightedStdDev.x = Mathf.Lerp(stdDev1.r, stdDev2.r, lerpWeight);
weightedStdDev.y = Mathf.Lerp(stdDev1.g, stdDev2.g, lerpWeight);
weightedStdDev.z = Mathf.Lerp(stdDev1.b, stdDev2.b, lerpWeight);
weightedStdDev.w = Mathf.Lerp(maxStdDev1, maxStdDev2, lerpWeight);
// Store (1 / (2 * WeightedVariance)) per color channel.
halfRcpWeightedVariances.Set(
0.5f / (weightedStdDev.x * weightedStdDev.x),
0.5f / (weightedStdDev.y * weightedStdDev.y),
0.5f / (weightedStdDev.z * weightedStdDev.z),
0.5f / (weightedStdDev.w * weightedStdDev.w)
);
}
// <<< Old SSS Model
static float KernelVal(float r, float s)
{
return s * (Mathf.Exp(-r * s) + Mathf.Exp(-r * s * (1.0f / 3.0f))) / (8.0f * Mathf.PI * r);
}
// Computes the value of the integrand over a disk: (2 * PI * r) * KernelVal().
static float KernelValCircle(float r, float s)
{
return 0.25f * s * (Mathf.Exp(-r * s) + Mathf.Exp(-r * s * (1.0f / 3.0f)));
}
static float KernelPdf(float r, float s)
{
return KernelValCircle(r, s);
}
static float KernelCdf(float r, float s)
{
return 1.0f - 0.25f * Mathf.Exp(-r * s) - 0.75f * Mathf.Exp(-r * s * (1.0f / 3.0f));
}
static float KernelCdfDerivative1(float r, float s)
{
return 0.25f * s * Mathf.Exp(-r * s) * (1.0f + Mathf.Exp(r * s * (2.0f / 3.0f)));
}
static float KernelCdfDerivative2(float r, float s)
{
return (-1.0f / 12.0f) * s * s * Mathf.Exp(-r * s) * (3.0f + Mathf.Exp(r * s * (2.0f / 3.0f)));
}
// The CDF is not analytically invertible, so we use Halley's Method of root finding.
// { f(r, s, p) = CDF(r, s) - p = 0 } with the initial guess { r = (10^p - 1) / s }.
static float KernelCdfInverse(float p, float s)
{
// Supply the initial guess.
float r = (Mathf.Pow(10f, p) - 1f) / s;
float t = float.MaxValue;
while (true)
{
float f0 = KernelCdf(r, s) - p;
float f1 = KernelCdfDerivative1(r, s);
float f2 = KernelCdfDerivative2(r, s);
float dr = f0 / (f1 * (1f - f0 * f2 / (2f * f1 * f1)));
if (Mathf.Abs(dr) < t)
{
r = r - dr;
t = Mathf.Abs(dr);
}
else
{
// Converged to the best result.
break;
}
}
return r;
}
// Old SSS Model >>>
static float Gaussian(float x, float stdDev)
{
float variance = stdDev * stdDev;
return Mathf.Exp(-x * x / (2 * variance)) / Mathf.Sqrt(2 * Mathf.PI * variance);
}
static float GaussianCombination(float x, float stdDev1, float stdDev2, float lerpWeight)
{
return Mathf.Lerp(Gaussian(x, stdDev1), Gaussian(x, stdDev2), lerpWeight);
}
static float RationalApproximation(float t)
{
// Abramowitz and Stegun formula 26.2.23.
// The absolute value of the error should be less than 4.5 e-4.
float[] c = { 2.515517f, 0.802853f, 0.010328f };
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)
{
float x;
if (p < 0.5)
{
// F^-1(p) = - G^-1(p)
x = -RationalApproximation(Mathf.Sqrt(-2f * Mathf.Log(p)));
}
else
{
// F^-1(p) = G^-1(1-p)
x = RationalApproximation(Mathf.Sqrt(-2f * Mathf.Log(1f - p)));
}
return x * stdDev;
}
static float GaussianCombinationCdfInverse(float p, float stdDev1, float stdDev2, float lerpWeight)
{
return Mathf.Lerp(NormalCdfInverse(p, stdDev1), NormalCdfInverse(p, stdDev2), lerpWeight);
}
// <<< Old SSS Model
}
public sealed class SubsurfaceScatteringSettings : ScriptableObject
{
public bool useDisneySSS = true;
public SubsurfaceScatteringProfile[] profiles;
[NonSerialized] public int texturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
[NonSerialized] public int transmissionFlags; // 2 bit/profile; 0 = inf. thick, 1 = thin, 2 = regular
[NonSerialized] public Vector4[] thicknessRemaps; // Remap: 0 = start, 1 = end - start
[NonSerialized] public Vector4[] worldScales; // Size of the world unit in meters (only the X component is used)
[NonSerialized] public Vector4[] shapeParams; // RGB = S = 1 / D, A = filter radius
[NonSerialized] public Vector4[] transmissionTints; // RGB = color, A = unused
[NonSerialized] public Vector4[] filterKernels; // XY = near field, ZW = far field; 0 = radius, 1 = reciprocal of the PDF
// Old SSS Model >>>
[NonSerialized] public Vector4[] halfRcpWeightedVariances;
[NonSerialized] public Vector4[] halfRcpVariancesAndWeights;
[NonSerialized] public Vector4[] filterKernelsBasic;
// <<< Old SSS Model
public SubsurfaceScatteringProfile this[int index]
{
get
{
if (index >= SssConstants.SSS_N_PROFILES - 1)
throw new IndexOutOfRangeException("index");
return profiles[index];
}
}
void OnEnable()
{
if (profiles != null && profiles.Length != SssConstants.SSS_NEUTRAL_PROFILE_ID)
Array.Resize(ref profiles, SssConstants.SSS_NEUTRAL_PROFILE_ID);
if (profiles == null)
profiles = new SubsurfaceScatteringProfile[SssConstants.SSS_NEUTRAL_PROFILE_ID];
for (int i = 0; i < SssConstants.SSS_NEUTRAL_PROFILE_ID; i++)
{
if (profiles[i] == null)
profiles[i] = new SubsurfaceScatteringProfile("Profile " + i);
profiles[i].Validate();
}
ValidateArray(ref thicknessRemaps, SssConstants.SSS_N_PROFILES);
ValidateArray(ref worldScales, SssConstants.SSS_N_PROFILES);
ValidateArray(ref shapeParams, SssConstants.SSS_N_PROFILES);
ValidateArray(ref transmissionTints, SssConstants.SSS_N_PROFILES);
ValidateArray(ref filterKernels, SssConstants.SSS_N_PROFILES * SssConstants.SSS_N_SAMPLES_NEAR_FIELD);
// Old SSS Model >>>
ValidateArray(ref halfRcpWeightedVariances, SssConstants.SSS_N_PROFILES);
ValidateArray(ref halfRcpVariancesAndWeights, SssConstants.SSS_N_PROFILES * 2);
ValidateArray(ref filterKernelsBasic, SssConstants.SSS_N_PROFILES * SssConstants.SSS_BASIC_N_SAMPLES);
Debug.Assert(SssConstants.SSS_NEUTRAL_PROFILE_ID < 16, "Transmission flags (32-bit integer) cannot support more than 16 profiles.");
UpdateCache();
}
static void ValidateArray<T>(ref T[] array, int len)
{
if (array == null || array.Length != len)
array = new T[len];
}
public void UpdateCache()
{
texturingModeFlags = transmissionFlags = 0;
for (int i = 0; i < SssConstants.SSS_N_PROFILES - 1; i++)
{
UpdateCache(i);
}
// Fill the neutral profile.
int neutralId = SssConstants.SSS_NEUTRAL_PROFILE_ID;
worldScales[neutralId] = Vector4.one;
shapeParams[neutralId] = Vector4.zero;
for (int j = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; j < n; j++)
{
filterKernels[n * neutralId + j].x = 0f;
filterKernels[n * neutralId + j].y = 1f;
filterKernels[n * neutralId + j].z = 0f;
filterKernels[n * neutralId + j].w = 1f;
}
// Old SSS Model >>>
halfRcpWeightedVariances[neutralId] = Vector4.one;
for (int j = 0, n = SssConstants.SSS_BASIC_N_SAMPLES; j < n; j++)
{
filterKernelsBasic[n * neutralId + j] = Vector4.one;
filterKernelsBasic[n * neutralId + j].w = 0f;
}
// <<< Old SSS Model
}
public void UpdateCache(int i)
{
texturingModeFlags |= (int)profiles[i].texturingMode << i;
transmissionFlags |= (int)profiles[i].transmissionMode << i * 2;
thicknessRemaps[i] = new Vector4(profiles[i].thicknessRemap.x, profiles[i].thicknessRemap.y - profiles[i].thicknessRemap.x, 0f, 0f);
worldScales[i] = new Vector4(profiles[i].worldScale, 0f, 0f, 0f);
shapeParams[i] = profiles[i].shapeParam;
shapeParams[i].w = profiles[i].maxRadius;
transmissionTints[i] = profiles[i].transmissionTint * 0.25f; // Premultiplied
for (int j = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; j < n; j++)
{
filterKernels[n * i + j].x = profiles[i].filterKernelNearField[j].x;
filterKernels[n * i + j].y = profiles[i].filterKernelNearField[j].y;
if (j < SssConstants.SSS_N_SAMPLES_FAR_FIELD)
{
filterKernels[n * i + j].z = profiles[i].filterKernelFarField[j].x;
filterKernels[n * i + j].w = profiles[i].filterKernelFarField[j].y;
}
}
// Old SSS Model >>>
halfRcpWeightedVariances[i] = profiles[i].halfRcpWeightedVariances;
var stdDev1 = ((1f / 3f) * SssConstants.SSS_BASIC_DISTANCE_SCALE) * (Vector4)profiles[i].scatterDistance1;
var stdDev2 = ((1f / 3f) * SssConstants.SSS_BASIC_DISTANCE_SCALE) * (Vector4)profiles[i].scatterDistance2;
// Multiply by 0.1 to convert from millimeters to centimeters. Apply the distance scale.
// Rescale by 4 to counter rescaling of transmission tints.
float a = 0.1f * SssConstants.SSS_BASIC_DISTANCE_SCALE;
halfRcpVariancesAndWeights[2 * i + 0] = new Vector4(a * a * 0.5f / (stdDev1.x * stdDev1.x), a * a * 0.5f / (stdDev1.y * stdDev1.y), a * a * 0.5f / (stdDev1.z * stdDev1.z), 4f * (1f - profiles[i].lerpWeight));
halfRcpVariancesAndWeights[2 * i + 1] = new Vector4(a * a * 0.5f / (stdDev2.x * stdDev2.x), a * a * 0.5f / (stdDev2.y * stdDev2.y), a * a * 0.5f / (stdDev2.z * stdDev2.z), 4f * profiles[i].lerpWeight);
for (int j = 0, n = SssConstants.SSS_BASIC_N_SAMPLES; j < n; j++)
{
filterKernelsBasic[n * i + j] = profiles[i].filterKernelBasic[j];
}
// <<< Old SSS Model
}
}
}

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringSettings.cs.meta


fileFormatVersion: 2
guid: 3418a08abd15e9a49af3ccbc9e15b5ea
timeCreated: 1507538042
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.Styles.cs.meta


fileFormatVersion: 2
guid: fcb1bb4049093ff41855e3951f22e9cf
timeCreated: 1507119569
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.cs.meta


fileFormatVersion: 2
guid: 4e87e719e85a91846ad1d5aa15793685
timeCreated: 1507118957
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

171
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[CustomEditor(typeof(SubsurfaceScatteringProfile))]
public partial class SubsurfaceScatteringProfileEditor : Editor
{
RenderTexture m_ProfileImage;
RenderTexture m_TransmittanceImage;
Material m_ProfileMaterial;
Material m_TransmittanceMaterial;
SerializedProperty m_ScatteringDistance;
SerializedProperty m_MaxRadius;
SerializedProperty m_ShapeParam;
SerializedProperty m_TransmissionTint;
SerializedProperty m_TexturingMode;
SerializedProperty m_TransmissionMode;
SerializedProperty m_ThicknessRemap;
SerializedProperty m_WorldScale;
// Old SSS Model >>>
SerializedProperty m_ScatterDistance1;
SerializedProperty m_ScatterDistance2;
SerializedProperty m_LerpWeight;
// <<< Old SSS Model
void OnEnable()
{
using (var o = new PropertyFetcher<SubsurfaceScatteringProfile>(serializedObject))
{
m_ScatteringDistance = o.FindProperty(x => x.scatteringDistance);
m_MaxRadius = o.FindProperty("m_MaxRadius");
m_ShapeParam = o.FindProperty("m_ShapeParam");
m_TransmissionTint = o.FindProperty(x => x.transmissionTint);
m_TexturingMode = o.FindProperty(x => x.texturingMode);
m_TransmissionMode = o.FindProperty(x => x.transmissionMode);
m_ThicknessRemap = o.FindProperty(x => x.thicknessRemap);
m_WorldScale = o.FindProperty(x => x.worldScale);
// Old SSS Model >>>
m_ScatterDistance1 = o.FindProperty(x => x.scatterDistance1);
m_ScatterDistance2 = o.FindProperty(x => x.scatterDistance2);
m_LerpWeight = o.FindProperty(x => x.lerpWeight);
// <<< Old SSS Model
}
// These shaders don't need to be reference by RenderPipelineResource as they are not use at runtime
m_ProfileMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawSssProfile");
m_TransmittanceMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/DrawTransmittanceGraph");
m_ProfileImage = new RenderTexture(256, 256, 0, RenderTextureFormat.DefaultHDR);
m_TransmittanceImage = new RenderTexture( 16, 256, 0, RenderTextureFormat.DefaultHDR);
}
void OnDisable()
{
CoreUtils.Destroy(m_ProfileMaterial);
CoreUtils.Destroy(m_TransmittanceMaterial);
CoreUtils.Destroy(m_ProfileImage);
CoreUtils.Destroy(m_TransmittanceImage);
}
public override void OnInspectorGUI()
{
var hdPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline;
if (hdPipeline == null)
return;
serializedObject.Update();
CheckStyles();
// Old SSS Model >>>
bool useDisneySSS = hdPipeline.sssSettings.useDisneySSS;
// <<< Old SSS Model
using (var scope = new EditorGUI.ChangeCheckScope())
{
if (useDisneySSS)
{
EditorGUILayout.PropertyField(m_ScatteringDistance, s_Styles.profileScatteringDistance);
using (new EditorGUI.DisabledScope(true))
EditorGUILayout.PropertyField(m_MaxRadius, s_Styles.profileMaxRadius);
}
else
{
EditorGUILayout.PropertyField(m_ScatterDistance1, s_Styles.profileScatterDistance1);
EditorGUILayout.PropertyField(m_ScatterDistance2, s_Styles.profileScatterDistance2);
EditorGUILayout.PropertyField(m_LerpWeight, s_Styles.profileLerpWeight);
}
m_TexturingMode.intValue = EditorGUILayout.Popup(s_Styles.texturingMode, m_TexturingMode.intValue, s_Styles.texturingModeOptions);
m_TransmissionMode.intValue = EditorGUILayout.Popup(s_Styles.profileTransmissionMode, m_TransmissionMode.intValue, s_Styles.transmissionModeOptions);
EditorGUILayout.PropertyField(m_TransmissionTint, s_Styles.profileTransmissionTint);
EditorGUILayout.PropertyField(m_ThicknessRemap, s_Styles.profileMinMaxThickness);
Vector2 thicknessRemap = m_ThicknessRemap.vector2Value;
EditorGUILayout.MinMaxSlider(s_Styles.profileThicknessRemap, ref thicknessRemap.x, ref thicknessRemap.y, 0.0f, 50.0f);
m_ThicknessRemap.vector2Value = thicknessRemap;
EditorGUILayout.PropertyField(m_WorldScale, s_Styles.profileWorldScale);
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.profilePreview0, s_Styles.centeredMiniBoldLabel);
EditorGUILayout.LabelField(s_Styles.profilePreview1, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(s_Styles.profilePreview2, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(s_Styles.profilePreview3, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space();
serializedObject.ApplyModifiedProperties();
if (scope.changed)
{
// Validate each individual asset and update caches.
((SubsurfaceScatteringProfile)target).Validate();
hdPipeline.sssSettings.UpdateCache();
}
}
float r = m_MaxRadius.floatValue;
Vector3 S = m_ShapeParam.vector3Value;
Vector4 T = m_TransmissionTint.colorValue;
Vector2 R = m_ThicknessRemap.vector2Value;
bool transmissionEnabled = m_TransmissionMode.intValue != (int)SubsurfaceScatteringProfile.TransmissionMode.None;
m_ProfileMaterial.SetFloat(HDShaderIDs._MaxRadius, r);
m_ProfileMaterial.SetVector(HDShaderIDs._ShapeParam, S);
// Old SSS Model >>>
CoreUtils.SelectKeyword(m_ProfileMaterial, "SSS_MODEL_DISNEY", "SSS_MODEL_BASIC", useDisneySSS);
// Apply the three-sigma rule, and rescale.
float s = (1.0f / 3.0f) * SssConstants.SSS_BASIC_DISTANCE_SCALE;
float rMax = Mathf.Max(m_ScatterDistance1.colorValue.r, m_ScatterDistance1.colorValue.g, m_ScatterDistance1.colorValue.b,
m_ScatterDistance2.colorValue.r, m_ScatterDistance2.colorValue.g, m_ScatterDistance2.colorValue.b);
Vector4 stdDev1 = s * m_ScatterDistance1.colorValue;
Vector4 stdDev2 = s * m_ScatterDistance2.colorValue;
m_ProfileMaterial.SetVector(HDShaderIDs._StdDev1, stdDev1);
m_ProfileMaterial.SetVector(HDShaderIDs._StdDev2, stdDev2);
m_ProfileMaterial.SetFloat(HDShaderIDs._LerpWeight, m_LerpWeight.floatValue);
m_ProfileMaterial.SetFloat(HDShaderIDs._MaxRadius, rMax);
// <<< Old SSS Model
// Draw the profile.
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(256, 256), m_ProfileImage, m_ProfileMaterial, ScaleMode.ScaleToFit, 1.0f);
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.transmittancePreview0, s_Styles.centeredMiniBoldLabel);
EditorGUILayout.LabelField(s_Styles.transmittancePreview1, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.LabelField(s_Styles.transmittancePreview2, EditorStyles.centeredGreyMiniLabel);
EditorGUILayout.Space();
// Old SSS Model >>>
// Multiply by 0.1 to convert from millimeters to centimeters. Apply the distance scale.
float a = 0.1f * SssConstants.SSS_BASIC_DISTANCE_SCALE;
Vector4 halfRcpVarianceAndWeight1 = new Vector4(a * a * 0.5f / (stdDev1.x * stdDev1.x), a * a * 0.5f / (stdDev1.y * stdDev1.y), a * a * 0.5f / (stdDev1.z * stdDev1.z), 4 * (1.0f - m_LerpWeight.floatValue));
Vector4 halfRcpVarianceAndWeight2 = new Vector4(a * a * 0.5f / (stdDev2.x * stdDev2.x), a * a * 0.5f / (stdDev2.y * stdDev2.y), a * a * 0.5f / (stdDev2.z * stdDev2.z), 4 * m_LerpWeight.floatValue);
m_TransmittanceMaterial.SetVector(HDShaderIDs._HalfRcpVarianceAndWeight1, halfRcpVarianceAndWeight1);
m_TransmittanceMaterial.SetVector(HDShaderIDs._HalfRcpVarianceAndWeight2, halfRcpVarianceAndWeight2);
// <<< Old SSS Model
m_TransmittanceMaterial.SetVector(HDShaderIDs._ShapeParam, S);
m_TransmittanceMaterial.SetVector(HDShaderIDs._TransmissionTint, transmissionEnabled ? T : Vector4.zero);
m_TransmittanceMaterial.SetVector(HDShaderIDs._ThicknessRemap, R);
// Draw the transmittance graph.
EditorGUI.DrawPreviewTexture(GUILayoutUtility.GetRect(16, 16), m_TransmittanceImage, m_TransmittanceMaterial, ScaleMode.ScaleToFit, 16.0f);
}
}
}

9
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/FoliageSSSProfile.asset.meta


fileFormatVersion: 2
guid: d6ee4403015766f4093158d69216c0bf
timeCreated: 1493161911
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SkinSSSProfile.asset.meta


fileFormatVersion: 2
guid: 906339bac2066fc4aa22a3652e1283ef
timeCreated: 1493291209
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

116
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/FoliageSSSProfile.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6e7465350bf0d248b4799d98e18cd24, type: 3}
m_Name: FoliageSSSProfile
m_EditorClassIdentifier:
scatteringDistance: {r: 0.75735295, g: 0.7008203, b: 0.24502596, a: 1}
transmissionTint: {r: 1, g: 1, b: 1, a: 1}
texturingMode: 0
transmissionMode: 1
thicknessRemap: {x: 0, y: 0.2873168}
worldScale: 1
settingsIndex: 1
m_ShapeParam: {x: 1.3203883, y: 1.4268992, z: 4.0812}
m_MaxRadius: 7.839332
m_FilterKernelNearField:
- {x: 0.013854082, y: 1.5332626}
- {x: 0.04207757, y: 1.5715919}
- {x: 0.07101321, y: 1.611625}
- {x: 0.10069309, y: 1.653469}
- {x: 0.13115102, y: 1.6972395}
- {x: 0.16242325, y: 1.743061}
- {x: 0.19454831, y: 1.791069}
- {x: 0.22756726, y: 1.8414105}
- {x: 0.2615238, y: 1.8942443}
- {x: 0.29646498, y: 1.9497447}
- {x: 0.33244094, y: 2.0081}
- {x: 0.36950532, y: 2.069517}
- {x: 0.40771604, y: 2.1342213}
- {x: 0.44713485, y: 2.2024598}
- {x: 0.48782852, y: 2.274504}
- {x: 0.5298689, y: 2.3506513}
- {x: 0.5733336, y: 2.4312308}
- {x: 0.6183063, y: 2.5166042}
- {x: 0.66487795, y: 2.6071734}
- {x: 0.71314675, y: 2.703383}
- {x: 0.76321995, y: 2.805728}
- {x: 0.81521386, y: 2.9147599}
- {x: 0.86925554, y: 3.031096}
- {x: 0.92548406, y: 3.1554284}
- {x: 0.9840515, y: 3.288537}
- {x: 1.0451256, y: 3.431302}
- {x: 1.1088905, y: 3.5847225}
- {x: 1.1755506, y: 3.749937}
- {x: 1.2453312, y: 3.9282467}
- {x: 1.3184844, y: 4.1211514}
- {x: 1.3952904, y: 4.3303804}
- {x: 1.4760638, y: 4.5579505}
- {x: 1.5611593, y: 4.8062224}
- {x: 1.650978, y: 5.0779796}
- {x: 1.7459753, y: 5.3765287}
- {x: 1.8466738, y: 5.7058387}
- {x: 1.9536757, y: 6.070716}
- {x: 2.0676782, y: 6.4770336}
- {x: 2.189499, y: 6.9320674}
- {x: 2.3201032, y: 7.4449396}
- {x: 2.4606442, y: 8.027264}
- {x: 2.612515, y: 8.694056}
- {x: 2.777422, y: 9.465107}
- {x: 2.9574924, y: 10.367077}
- {x: 3.1554203, y: 11.436736}
- {x: 3.3747015, y: 12.726331}
- {x: 3.6199868, y: 14.312694}
- {x: 3.897662, y: 16.313623}
- {x: 4.2168484, y: 18.919455}
- {x: 4.5912457, y: 22.459015}
- {x: 5.042839, y: 27.553566}
- {x: 5.610336, y: 35.534466}
- {x: 6.3721733, y: 49.863647}
- {x: 7.53103, y: 83.235695}
- {x: 10.026244, y: 249.90146}
m_FilterKernelFarField:
- {x: 0.036647703, y: 1.5641627}
- {x: 0.113649175, y: 1.671985}
- {x: 0.19610003, y: 1.7934121}
- {x: 0.28470552, y: 1.9309369}
- {x: 0.38030306, y: 2.0876582}
- {x: 0.48389605, y: 2.2674706}
- {x: 0.5966971, y: 2.4753277}
- {x: 0.72018707, y: 2.717616}
- {x: 0.85619545, y: 3.0026984}
- {x: 1.0070126, y: 3.3417335}
- {x: 1.1755506, y: 3.749937}
- {x: 1.3655809, y: 4.248627}
- {x: 1.5821002, y: 4.868682}
- {x: 1.8319175, y: 5.6567397}
- {x: 2.1246579, y: 6.6871305}
- {x: 2.4745958, y: 8.086858}
- {x: 2.9043517, y: 10.094101}
- {x: 3.4533012, y: 13.217383}
- {x: 4.20053, y: 18.777578}
- {x: 5.349281, y: 31.61934}
- {x: 7.839332, y: 95.36225}
scatterDistance1: {r: 0.3, g: 0.3, b: 0.3, a: 0}
scatterDistance2: {r: 0.6, g: 0.6, b: 0.6, a: 0}
lerpWeight: 0.5
m_HalfRcpWeightedVariances: {x: 2.4691355, y: 2.4691355, z: 2.4691355, w: 2.4691355}
m_FilterKernelBasic:
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.000000048879357}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.11381993}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.23580086}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.37865555}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -0.57677805}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: -1.3907351}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.11382001}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.23580086}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.37865555}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 0.57677805}
- {x: 0.09090909, y: 0.09090909, z: 0.09090909, w: 1.3907368}

116
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SSSProfile/SkinSSSProfile.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6e7465350bf0d248b4799d98e18cd24, type: 3}
m_Name: SkinSSSProfile
m_EditorClassIdentifier:
scatteringDistance: {r: 0.758, g: 0.321, b: 0.201, a: 1}
transmissionTint: {r: 0.7568628, g: 0.32156864, b: 0.20000002, a: 1}
texturingMode: 0
transmissionMode: 2
thicknessRemap: {x: 0, y: 8.152544}
worldScale: 1
settingsIndex: 0
m_ShapeParam: {x: 1.3192612, y: 3.1152647, z: 4.9751244}
m_MaxRadius: 7.84603
m_FilterKernelNearField:
- {x: 0.013865918, y: 1.5345725}
- {x: 0.04211352, y: 1.5729346}
- {x: 0.07107388, y: 1.6130018}
- {x: 0.100779116, y: 1.6548817}
- {x: 0.13126306, y: 1.6986896}
- {x: 0.16256203, y: 1.7445502}
- {x: 0.1947145, y: 1.7925992}
- {x: 0.22776169, y: 1.8429838}
- {x: 0.26174724, y: 1.8958628}
- {x: 0.29671827, y: 1.9514104}
- {x: 0.33272493, y: 2.0098157}
- {x: 0.369821, y: 2.0712852}
- {x: 0.40806437, y: 2.1360447}
- {x: 0.44751683, y: 2.2043417}
- {x: 0.48824534, y: 2.276447}
- {x: 0.5303216, y: 2.3526597}
- {x: 0.5738235, y: 2.433308}
- {x: 0.61883456, y: 2.5187542}
- {x: 0.665446, y: 2.609401}
- {x: 0.713756, y: 2.7056925}
- {x: 0.763872, y: 2.808125}
- {x: 0.8159103, y: 2.91725}
- {x: 0.8699981, y: 3.0336854}
- {x: 0.9262747, y: 3.1581244}
- {x: 0.98489225, y: 3.2913465}
- {x: 1.0460185, y: 3.434234}
- {x: 1.1098381, y: 3.5877857}
- {x: 1.1765549, y: 3.7531407}
- {x: 1.2463952, y: 3.9316032}
- {x: 1.319611, y: 4.124672}
- {x: 1.3964823, y: 4.3340797}
- {x: 1.4773248, y: 4.561845}
- {x: 1.5624928, y: 4.810328}
- {x: 1.6523882, y: 5.082317}
- {x: 1.747467, y: 5.381122}
- {x: 1.8482518, y: 5.710715}
- {x: 1.9553448, y: 6.0759025}
- {x: 2.069445, y: 6.482568}
- {x: 2.1913698, y: 6.9379897}
- {x: 2.3220856, y: 7.4513016}
- {x: 2.4627466, y: 8.0341215}
- {x: 2.614747, y: 8.701484}
- {x: 2.7797952, y: 9.473195}
- {x: 2.9600194, y: 10.375936}
- {x: 3.1581159, y: 11.446505}
- {x: 3.3775842, y: 12.737201}
- {x: 3.6230793, y: 14.324919}
- {x: 3.9009922, y: 16.327562}
- {x: 4.220452, y: 18.935623}
- {x: 4.5951686, y: 22.478209}
- {x: 5.047148, y: 27.57712}
- {x: 5.615129, y: 35.564823}
- {x: 6.3776174, y: 49.90625}
- {x: 7.5374603, y: 83.30668}
- {x: 10.03481, y: 250.11497}
m_FilterKernelFarField:
- {x: 0.03667902, y: 1.5654991}
- {x: 0.11374626, y: 1.6734134}
- {x: 0.19626758, y: 1.7949444}
- {x: 0.28494877, y: 1.9325867}
- {x: 0.38062802, y: 2.0894418}
- {x: 0.48430943, y: 2.2694077}
- {x: 0.59720695, y: 2.4774427}
- {x: 0.72080237, y: 2.7199378}
- {x: 0.8569269, y: 3.005264}
- {x: 1.007873, y: 3.3445888}
- {x: 1.1765549, y: 3.7531407}
- {x: 1.3667475, y: 4.252257}
- {x: 1.5834517, y: 4.872841}
- {x: 1.8334827, y: 5.6615734}
- {x: 2.126473, y: 6.692844}
- {x: 2.4767098, y: 8.093767}
- {x: 2.9068332, y: 10.102725}
- {x: 3.4562516, y: 13.228675}
- {x: 4.2041187, y: 18.793621}
- {x: 5.3538504, y: 31.646347}
- {x: 7.84603, y: 95.44374}
scatterDistance1: {r: 0.3, g: 0.2, b: 0.2, a: 0}
scatterDistance2: {r: 0.6, g: 0.2, b: 0.2, a: 0}
lerpWeight: 0.5
m_HalfRcpWeightedVariances: {x: 2.4691355, y: 12.5, z: 12.5, w: 2.4691355}
m_FilterKernelBasic:
- {x: 0.09090909, y: 0.21162307, z: 0.21162307, w: -0.000000048879357}
- {x: 0.09090909, y: 0.18990478, z: 0.18990478, w: -0.11381993}
- {x: 0.09090909, y: 0.13233659, z: 0.13233659, w: -0.23580086}
- {x: 0.09090909, y: 0.061445467, z: 0.061445467, w: -0.37865555}
- {x: 0.09090909, y: 0.010501689, z: 0.010501689, w: -0.57677805}
- {x: 0.09090909, y: 2.9458339e-10, z: 2.9458339e-10, w: -1.3907351}
- {x: 0.09090909, y: 0.18990476, z: 0.18990476, w: 0.11382001}
- {x: 0.09090909, y: 0.13233659, z: 0.13233659, w: 0.23580086}
- {x: 0.09090909, y: 0.061445467, z: 0.061445467, w: 0.37865555}
- {x: 0.09090909, y: 0.010501689, z: 0.010501689, w: 0.57677805}
- {x: 0.09090909, y: 2.9456845e-10, z: 2.9456845e-10, w: 1.3907368}

12
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs.meta


fileFormatVersion: 2
guid: a6e7465350bf0d248b4799d98e18cd24
timeCreated: 1490016484
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

637
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/SubsurfaceScatteringProfile.cs


using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[GenerateHLSL]
public class SssConstants
{
public const int SSS_N_PROFILES = 8; // Max. number of profiles, including the slot taken by the neutral profile
public const int SSS_NEUTRAL_PROFILE_ID = SSS_N_PROFILES - 1; // Does not result in blurring
public const int SSS_N_SAMPLES_NEAR_FIELD = 55; // Used for extreme close ups; must be a Fibonacci number
public const int SSS_N_SAMPLES_FAR_FIELD = 21; // Used at a regular distance; must be a Fibonacci number
public const int SSS_LOD_THRESHOLD = 4; // The LoD threshold of the near-field kernel (in pixels)
public const int SSS_TRSM_MODE_NONE = 0;
public const int SSS_TRSM_MODE_THIN = 1;
// Old SSS Model >>>
public const int SSS_BASIC_N_SAMPLES = 11; // Must be an odd number
public const int SSS_BASIC_DISTANCE_SCALE = 3; // SSS distance units per centimeter
// <<< Old SSS Model
}
[Serializable]
public class SubsurfaceScatteringProfile : ScriptableObject
{
public enum TexturingMode : uint { PreAndPostScatter = 0, PostScatter = 1 };
public enum TransmissionMode : uint { None = SssConstants.SSS_TRSM_MODE_NONE, ThinObject = SssConstants.SSS_TRSM_MODE_THIN, Regular };
[ColorUsage(false, true, 0f, 8f, 0.125f, 3f)]
public Color scatteringDistance; // Per color channel (no meaningful units)
[ColorUsage(false)]
public Color transmissionTint; // Color, 0 to 1
public TexturingMode texturingMode;
public TransmissionMode transmissionMode;
public Vector2 thicknessRemap; // X = min, Y = max (in millimeters)
public float worldScale; // Size of the world unit in meters
[HideInInspector]
public int settingsIndex; // SubsurfaceScatteringSettings.profiles[i]
[SerializeField]
Vector3 m_ShapeParam; // RGB = shape parameter: S = 1 / D
[SerializeField]
float m_MaxRadius; // In millimeters
[SerializeField]
Vector2[] m_FilterKernelNearField; // X = radius, Y = reciprocal of the PDF
[SerializeField]
Vector2[] m_FilterKernelFarField; // X = radius, Y = reciprocal of the PDF
// Old SSS Model >>>
[ColorUsage(false, true, 0f, 8f, 0.125f, 3f)]
public Color scatterDistance1;
[ColorUsage(false, true, 0f, 8f, 0.125f, 3f)]
public Color scatterDistance2;
[Range(0f, 1f)]
public float lerpWeight;
[SerializeField]
Vector4 m_HalfRcpWeightedVariances;
[SerializeField]
Vector4[] m_FilterKernelBasic;
// <<< Old SSS Model
// --- Public Methods ---
public SubsurfaceScatteringProfile()
{
scatteringDistance = Color.grey;
transmissionTint = Color.white;
texturingMode = TexturingMode.PreAndPostScatter;
transmissionMode = TransmissionMode.None;
thicknessRemap = new Vector2(0.0f, 5.0f);
worldScale = 1.0f;
settingsIndex = SssConstants.SSS_NEUTRAL_PROFILE_ID; // Updated by SubsurfaceScatteringSettings.OnValidate() once assigned
// Old SSS Model >>>
scatterDistance1 = new Color(0.3f, 0.3f, 0.3f, 0.0f);
scatterDistance2 = new Color(0.5f, 0.5f, 0.5f, 0.0f);
lerpWeight = 1.0f;
// <<< Old SSS Model
BuildKernel();
}
public void Validate()
{
thicknessRemap.y = Mathf.Max(thicknessRemap.y, 0f);
thicknessRemap.x = Mathf.Clamp(thicknessRemap.x, 0f, thicknessRemap.y);
worldScale = Mathf.Max(worldScale, 0.001f);
// Old SSS Model >>>
var c = new Color();
c.r = Mathf.Max(0.05f, scatterDistance1.r);
c.g = Mathf.Max(0.05f, scatterDistance1.g);
c.b = Mathf.Max(0.05f, scatterDistance1.b);
c.a = 0.0f;
scatterDistance1 = c;
c.r = Mathf.Max(0.05f, scatterDistance2.r);
c.g = Mathf.Max(0.05f, scatterDistance2.g);
c.b = Mathf.Max(0.05f, scatterDistance2.b);
c.a = 0.0f;
scatterDistance2 = c;
// <<< Old SSS Model
BuildKernel();
}
// Ref: Approximate Reflectance Profiles for Efficient Subsurface Scattering by Pixar.
public void BuildKernel()
{
if (m_FilterKernelNearField == null || m_FilterKernelNearField.Length != SssConstants.SSS_N_SAMPLES_NEAR_FIELD)
{
m_FilterKernelNearField = new Vector2[SssConstants.SSS_N_SAMPLES_NEAR_FIELD];
}
if (m_FilterKernelFarField == null || m_FilterKernelFarField.Length != SssConstants.SSS_N_SAMPLES_FAR_FIELD)
{
m_FilterKernelFarField = new Vector2[SssConstants.SSS_N_SAMPLES_FAR_FIELD];
}
// Clamp to avoid artifacts.
m_ShapeParam.x = 1.0f / Mathf.Max(0.001f, scatteringDistance.r);
m_ShapeParam.y = 1.0f / Mathf.Max(0.001f, scatteringDistance.g);
m_ShapeParam.z = 1.0f / Mathf.Max(0.001f, scatteringDistance.b);
// We importance sample the color channel with the widest scattering distance.
float s = Mathf.Min(m_ShapeParam.x, m_ShapeParam.y, m_ShapeParam.z);
// Importance sample the normalized diffusion profile for the computed value of 's'.
// ------------------------------------------------------------------------------------
// R(r, s) = s * (Exp[-r * s] + Exp[-r * s / 3]) / (8 * Pi * r)
// PDF(r, s) = s * (Exp[-r * s] + Exp[-r * s / 3]) / 4
// CDF(r, s) = 1 - 1/4 * Exp[-r * s] - 3/4 * Exp[-r * s / 3]
// ------------------------------------------------------------------------------------
// Importance sample the near field kernel.
for (int i = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; i < n; i++)
{
float p = (i + 0.5f) * (1.0f / n);
float r = KernelCdfInverse(p, s);
// N.b.: computation of normalized weights, and multiplication by the surface albedo
// of the actual geometry is performed at runtime (in the shader).
m_FilterKernelNearField[i].x = r;
m_FilterKernelNearField[i].y = 1.0f / KernelPdf(r, s);
}
// Importance sample the far field kernel.
for (int i = 0, n = SssConstants.SSS_N_SAMPLES_FAR_FIELD; i < n; i++)
{
float p = (i + 0.5f) * (1.0f / n);
float r = KernelCdfInverse(p, s);
// N.b.: computation of normalized weights, and multiplication by the surface albedo
// of the actual geometry is performed at runtime (in the shader).
m_FilterKernelFarField[i].x = r;
m_FilterKernelFarField[i].y = 1.0f / KernelPdf(r, s);
}
m_MaxRadius = m_FilterKernelFarField[SssConstants.SSS_N_SAMPLES_FAR_FIELD - 1].x;
// Old SSS Model >>>
UpdateKernelAndVarianceData();
// <<< Old SSS Model
}
// Old SSS Model >>>
public void UpdateKernelAndVarianceData()
{
const int numSamples = SssConstants.SSS_BASIC_N_SAMPLES;
const int distanceScale = SssConstants.SSS_BASIC_DISTANCE_SCALE;
if (m_FilterKernelBasic == null || m_FilterKernelBasic.Length != numSamples)
{
m_FilterKernelBasic = new Vector4[numSamples];
}
// Apply the three-sigma rule, and rescale.
Color stdDev1 = ((1.0f / 3.0f) * distanceScale) * scatterDistance1;
Color stdDev2 = ((1.0f / 3.0f) * distanceScale) * scatterDistance2;
// Our goal is to blur the image using a filter which is represented
// as a product of a linear combination of two normalized 1D Gaussians
// as suggested by Jimenez et al. in "Separable Subsurface Scattering".
// A normalized (i.e. energy-preserving) 1D Gaussian with the mean of 0
// is defined as follows: G1(x, v) = exp(-x * x / (2 * v)) / sqrt(2 * Pi * v),
// where 'v' is variance and 'x' is the radial distance from the origin.
// Using the weight 'w', our 1D and the resulting 2D filters are given as:
// A1(v1, v2, w, x) = G1(x, v1) * (1 - w) + G1(r, v2) * w,
// A2(v1, v2, w, x, y) = A1(v1, v2, w, x) * A1(v1, v2, w, y).
// The resulting filter function is a non-Gaussian PDF.
// It is separable by design, but generally not radially symmetric.
// N.b.: our scattering distance is rather limited. Therefore, in order to allow
// for a greater range of standard deviation values for flatter profiles,
// we rescale the world using 'distanceScale', effectively reducing the SSS
// distance units from centimeters to (1 / distanceScale).
// Find the widest Gaussian across 3 color channels.
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);
float step = 1.0f / (numSamples - 1);
// Importance sample the linear combination of two Gaussians.
for (int i = 0; i < numSamples; i++)
{
// Generate 'u' on (0, 0.5] and (0.5, 1).
float u = (i <= numSamples / 2) ? 0.5f - i * step // The center and to the left
: i * step; // From the center to the right
u = Mathf.Clamp(u, 0.001f, 0.999f);
float pos = GaussianCombinationCdfInverse(u, maxStdDev1, maxStdDev2, lerpWeight);
float pdf = GaussianCombination(pos, maxStdDev1, maxStdDev2, lerpWeight);
Vector3 val;
val.x = GaussianCombination(pos, stdDev1.r, stdDev2.r, lerpWeight);
val.y = GaussianCombination(pos, stdDev1.g, stdDev2.g, lerpWeight);
val.z = GaussianCombination(pos, stdDev1.b, stdDev2.b, lerpWeight);
// We do not divide by 'numSamples' since we will renormalize, anyway.
m_FilterKernelBasic[i].x = val.x * (1 / pdf);
m_FilterKernelBasic[i].y = val.y * (1 / pdf);
m_FilterKernelBasic[i].z = val.z * (1 / pdf);
m_FilterKernelBasic[i].w = pos;
weightSum.x += m_FilterKernelBasic[i].x;
weightSum.y += m_FilterKernelBasic[i].y;
weightSum.z += m_FilterKernelBasic[i].z;
}
// Renormalize the weights to conserve energy.
for (int i = 0; i < numSamples; i++)
{
m_FilterKernelBasic[i].x *= 1 / weightSum.x;
m_FilterKernelBasic[i].y *= 1 / weightSum.y;
m_FilterKernelBasic[i].z *= 1 / weightSum.z;
}
Vector4 weightedStdDev;
weightedStdDev.x = Mathf.Lerp(stdDev1.r, stdDev2.r, lerpWeight);
weightedStdDev.y = Mathf.Lerp(stdDev1.g, stdDev2.g, lerpWeight);
weightedStdDev.z = Mathf.Lerp(stdDev1.b, stdDev2.b, lerpWeight);
weightedStdDev.w = Mathf.Lerp(maxStdDev1, maxStdDev2, lerpWeight);
// Store (1 / (2 * WeightedVariance)) per color channel.
m_HalfRcpWeightedVariances.x = 0.5f / (weightedStdDev.x * weightedStdDev.x);
m_HalfRcpWeightedVariances.y = 0.5f / (weightedStdDev.y * weightedStdDev.y);
m_HalfRcpWeightedVariances.z = 0.5f / (weightedStdDev.z * weightedStdDev.z);
m_HalfRcpWeightedVariances.w = 0.5f / (weightedStdDev.w * weightedStdDev.w);
}
// <<< Old SSS Model
public Vector3 shapeParameter
{
// Set in BuildKernel().
get { return m_ShapeParam; }
}
public float maxRadius
{
// Set in BuildKernel().
get { return m_MaxRadius; }
}
public Vector2[] filterKernelNearField
{
// Set in BuildKernel().
get { return m_FilterKernelNearField; }
}
public Vector2[] filterKernelFarField
{
// Set in BuildKernel().
get { return m_FilterKernelFarField; }
}
// Old SSS Model >>>
public Vector4[] filterKernelBasic
{
// Set via UpdateKernelAndVarianceData().
get { return m_FilterKernelBasic; }
}
public Vector4 halfRcpWeightedVariances
{
// Set via UpdateKernelAndVarianceData().
get { return m_HalfRcpWeightedVariances; }
}
// <<< Old SSS Model
// --- Private Methods ---
static float KernelVal(float r, float s)
{
return s * (Mathf.Exp(-r * s) + Mathf.Exp(-r * s * (1.0f / 3.0f))) / (8.0f * Mathf.PI * r);
}
// Computes the value of the integrand over a disk: (2 * PI * r) * KernelVal().
static float KernelValCircle(float r, float s)
{
return 0.25f * s * (Mathf.Exp(-r * s) + Mathf.Exp(-r * s * (1.0f / 3.0f)));
}
static float KernelPdf(float r, float s)
{
return KernelValCircle(r, s);
}
static float KernelCdf(float r, float s)
{
return 1.0f - 0.25f * Mathf.Exp(-r * s) - 0.75f * Mathf.Exp(-r * s * (1.0f / 3.0f));
}
static float KernelCdfDerivative1(float r, float s)
{
return 0.25f * s * Mathf.Exp(-r * s) * (1.0f + Mathf.Exp(r * s * (2.0f / 3.0f)));
}
static float KernelCdfDerivative2(float r, float s)
{
return (-1.0f / 12.0f) * s * s * Mathf.Exp(-r * s) * (3.0f + Mathf.Exp(r * s * (2.0f / 3.0f)));
}
// The CDF is not analytically invertible, so we use Halley's Method of root finding.
// { f(r, s, p) = CDF(r, s) - p = 0 } with the initial guess { r = (10^p - 1) / s }.
static float KernelCdfInverse(float p, float s)
{
// Supply the initial guess.
float r = (Mathf.Pow(10.0f, p) - 1.0f) / s;
float t = float.MaxValue;
while (true)
{
float f0 = KernelCdf(r, s) - p;
float f1 = KernelCdfDerivative1(r, s);
float f2 = KernelCdfDerivative2(r, s);
float dr = f0 / (f1 * (1.0f - f0 * f2 / (2.0f * f1 * f1)));
if (Mathf.Abs(dr) < t)
{
r = r - dr;
t = Mathf.Abs(dr);
}
else
{
// Converged to the best result.
break;
}
}
return r;
}
// Old SSS Model >>>
static float Gaussian(float x, float stdDev)
{
float variance = stdDev * stdDev;
return Mathf.Exp(-x * x / (2 * variance)) / Mathf.Sqrt(2 * Mathf.PI * variance);
}
static float GaussianCombination(float x, float stdDev1, float stdDev2, float lerpWeight)
{
return Mathf.Lerp(Gaussian(x, stdDev1), Gaussian(x, stdDev2), lerpWeight);
}
static float RationalApproximation(float t)
{
// Abramowitz and Stegun formula 26.2.23.
// The absolute value of the error should be less than 4.5 e-4.
float[] c = {2.515517f, 0.802853f, 0.010328f};
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)
{
float x;
if (p < 0.5)
{
// F^-1(p) = - G^-1(p)
x = -RationalApproximation(Mathf.Sqrt(-2.0f * Mathf.Log(p)));
}
else
{
// F^-1(p) = G^-1(1-p)
x = RationalApproximation(Mathf.Sqrt(-2.0f * Mathf.Log(1.0f - p)));
}
return x * stdDev;
}
static float GaussianCombinationCdfInverse(float p, float stdDev1, float stdDev2, float lerpWeight)
{
return Mathf.Lerp(NormalCdfInverse(p, stdDev1), NormalCdfInverse(p, stdDev2), lerpWeight);
}
// <<< Old SSS Model
}
[Serializable]
public class SubsurfaceScatteringSettings : ISerializationCallbackReceiver
{
public int numProfiles; // Excluding the neutral profile
public SubsurfaceScatteringProfile[] profiles;
// Below are the cached values. TODO: uncomment when SSS profile asset serialization is fixed.
/*[NonSerialized]*/ public int texturingModeFlags; // 1 bit/profile; 0 = PreAndPostScatter, 1 = PostScatter
/*[NonSerialized]*/ public int transmissionFlags; // 2 bit/profile; 0 = inf. thick, 1 = thin, 2 = regular
/*[NonSerialized]*/ public Vector4[] thicknessRemaps; // Remap: 0 = start, 1 = end - start
/*[NonSerialized]*/ public Vector4[] worldScales; // Size of the world unit in meters (only the X component is used)
/*[NonSerialized]*/ public Vector4[] shapeParams; // RGB = S = 1 / D, A = filter radius
/*[NonSerialized]*/ public Vector4[] transmissionTints; // RGB = color, A = unused
/*[NonSerialized]*/ public Vector4[] filterKernels; // XY = near field, ZW = far field; 0 = radius, 1 = reciprocal of the PDF
// Old SSS Model >>>
public bool useDisneySSS;
/*[NonSerialized]*/ public Vector4[] halfRcpWeightedVariances;
/*[NonSerialized]*/ public Vector4[] halfRcpVariancesAndWeights;
/*[NonSerialized]*/ public Vector4[] filterKernelsBasic;
// <<< Old SSS Model
// --- Public Methods ---
public SubsurfaceScatteringSettings()
{
numProfiles = 1;
profiles = new SubsurfaceScatteringProfile[numProfiles];
profiles[0] = null;
texturingModeFlags = 0;
transmissionFlags = 0;
thicknessRemaps = null;
worldScales = null;
shapeParams = null;
transmissionTints = null;
filterKernels = null;
// Old SSS Model >>>
useDisneySSS = true;
halfRcpWeightedVariances = null;
halfRcpVariancesAndWeights = null;
filterKernelsBasic = null;
// <<< Old SSS Model
UpdateCache();
}
public void OnValidate()
{
// Reserve one slot for the neutral profile.
numProfiles = Math.Min(profiles.Length, SssConstants.SSS_N_PROFILES - 1);
if (profiles.Length != numProfiles)
{
Array.Resize(ref profiles, numProfiles);
}
for (int i = 0; i < numProfiles; i++)
{
if (profiles[i] != null)
{
// Assign the profile IDs.
profiles[i].settingsIndex = i;
}
}
foreach (var profile in profiles)
{
if (profile != null)
profile.Validate();
}
UpdateCache();
}
public void UpdateCache()
{
texturingModeFlags = transmissionFlags = 0;
if (thicknessRemaps == null || thicknessRemaps.Length != SssConstants.SSS_N_PROFILES)
{
thicknessRemaps = new Vector4[SssConstants.SSS_N_PROFILES];
}
if (worldScales == null || worldScales.Length != SssConstants.SSS_N_PROFILES)
{
worldScales = new Vector4[SssConstants.SSS_N_PROFILES];
}
if (shapeParams == null || shapeParams.Length != SssConstants.SSS_N_PROFILES)
{
shapeParams = new Vector4[SssConstants.SSS_N_PROFILES];
}
if (transmissionTints == null || transmissionTints.Length != SssConstants.SSS_N_PROFILES)
{
transmissionTints = new Vector4[SssConstants.SSS_N_PROFILES];
}
const int filterKernelsNearFieldLen = SssConstants.SSS_N_PROFILES * SssConstants.SSS_N_SAMPLES_NEAR_FIELD;
if (filterKernels == null || filterKernels.Length != filterKernelsNearFieldLen)
{
filterKernels = new Vector4[filterKernelsNearFieldLen];
}
// Old SSS Model >>>
if (halfRcpWeightedVariances == null || halfRcpWeightedVariances.Length != SssConstants.SSS_N_PROFILES)
{
halfRcpWeightedVariances = new Vector4[SssConstants.SSS_N_PROFILES];
}
if (halfRcpVariancesAndWeights == null || halfRcpVariancesAndWeights.Length != 2 * SssConstants.SSS_N_PROFILES)
{
halfRcpVariancesAndWeights = new Vector4[2 * SssConstants.SSS_N_PROFILES];
}
const int filterKernelsLen = SssConstants.SSS_N_PROFILES * SssConstants.SSS_BASIC_N_SAMPLES;
if (filterKernelsBasic == null || filterKernelsBasic.Length != filterKernelsLen)
{
filterKernelsBasic = new Vector4[filterKernelsLen];
}
// <<< Old SSS Model
for (int i = 0; i < SssConstants.SSS_N_PROFILES - 1; i++)
{
// If a profile is null, it means that it was never set in the HDRenderPipeline Asset or that the profile asset has been deleted.
// In this case we want the users to be warned if a material uses one of those. This is why we fill the profile with pink transmission values.
if (i >= numProfiles || profiles[i] == null)
{
// Pink transmission
transmissionFlags |= 1 << i * 2;
transmissionTints[i] = new Vector4(100.0f, 0.0f, 100.0f, 1.0f);
// Default neutral values for the rest
worldScales[i] = Vector4.one;
shapeParams[i] = Vector4.zero;
for (int j = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; j < n; j++)
{
filterKernels[n * i + j].x = 0.0f;
filterKernels[n * i + j].y = 1.0f;
filterKernels[n * i + j].z = 0.0f;
filterKernels[n * i + j].w = 1.0f;
}
// Old SSS Model >>>
halfRcpWeightedVariances[i] = Vector4.one;
halfRcpVariancesAndWeights[2 * i + 0] = Vector4.one;
halfRcpVariancesAndWeights[2 * i + 1] = Vector4.one;
for (int j = 0, n = SssConstants.SSS_BASIC_N_SAMPLES; j < n; j++)
{
filterKernelsBasic[n * i + j] = Vector4.one;
filterKernelsBasic[n * i + j].w = 0.0f;
}
continue;
}
Debug.Assert(numProfiles < 16, "Transmission flags (32-bit integer) cannot support more than 16 profiles.");
texturingModeFlags |= (int)profiles[i].texturingMode << i;
transmissionFlags |= (int)profiles[i].transmissionMode << i * 2;
thicknessRemaps[i] = new Vector4(profiles[i].thicknessRemap.x, profiles[i].thicknessRemap.y - profiles[i].thicknessRemap.x, 0.0f, 0.0f);
worldScales[i] = new Vector4(profiles[i].worldScale, 0, 0, 0);
shapeParams[i] = profiles[i].shapeParameter;
shapeParams[i].w = profiles[i].maxRadius;
transmissionTints[i] = profiles[i].transmissionTint * 0.25f; // Premultiplied
for (int j = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; j < n; j++)
{
filterKernels[n * i + j].x = profiles[i].filterKernelNearField[j].x;
filterKernels[n * i + j].y = profiles[i].filterKernelNearField[j].y;
if (j < SssConstants.SSS_N_SAMPLES_FAR_FIELD)
{
filterKernels[n * i + j].z = profiles[i].filterKernelFarField[j].x;
filterKernels[n * i + j].w = profiles[i].filterKernelFarField[j].y;
}
}
// Old SSS Model >>>
halfRcpWeightedVariances[i] = profiles[i].halfRcpWeightedVariances;
Vector4 stdDev1 = ((1.0f / 3.0f) * SssConstants.SSS_BASIC_DISTANCE_SCALE) * profiles[i].scatterDistance1;
Vector4 stdDev2 = ((1.0f / 3.0f) * SssConstants.SSS_BASIC_DISTANCE_SCALE) * profiles[i].scatterDistance2;
// Multiply by 0.1 to convert from millimeters to centimeters. Apply the distance scale.
// Rescale by 4 to counter rescaling of transmission tints.
float a = 0.1f * SssConstants.SSS_BASIC_DISTANCE_SCALE;
halfRcpVariancesAndWeights[2 * i + 0] = new Vector4(a * a * 0.5f / (stdDev1.x * stdDev1.x), a * a * 0.5f / (stdDev1.y * stdDev1.y), a * a * 0.5f / (stdDev1.z * stdDev1.z), 4 * (1.0f - profiles[i].lerpWeight));
halfRcpVariancesAndWeights[2 * i + 1] = new Vector4(a * a * 0.5f / (stdDev2.x * stdDev2.x), a * a * 0.5f / (stdDev2.y * stdDev2.y), a * a * 0.5f / (stdDev2.z * stdDev2.z), 4 * profiles[i].lerpWeight);
for (int j = 0, n = SssConstants.SSS_BASIC_N_SAMPLES; j < n; j++)
{
filterKernelsBasic[n * i + j] = profiles[i].filterKernelBasic[j];
}
// <<< Old SSS Model
}
// Fill the neutral profile.
{
int i = SssConstants.SSS_NEUTRAL_PROFILE_ID;
worldScales[i] = Vector4.one;
shapeParams[i] = Vector4.zero;
for (int j = 0, n = SssConstants.SSS_N_SAMPLES_NEAR_FIELD; j < n; j++)
{
filterKernels[n * i + j].x = 0.0f;
filterKernels[n * i + j].y = 1.0f;
filterKernels[n * i + j].z = 0.0f;
filterKernels[n * i + j].w = 1.0f;
}
// Old SSS Model >>>
halfRcpWeightedVariances[i] = Vector4.one;
for (int j = 0, n = SssConstants.SSS_BASIC_N_SAMPLES; j < n; j++)
{
filterKernelsBasic[n * i + j] = Vector4.one;
filterKernelsBasic[n * i + j].w = 0.0f;
}
// <<< Old SSS Model
}
}
public void OnBeforeSerialize()
{
// No special action required.
}
public void OnAfterDeserialize()
{
// TODO: uncomment when SSS profile asset serialization is fixed.
// UpdateCache();
}
}
}

/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringProfileEditor.Styles.cs → /ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/SubsurfaceScatteringSettingsEditor.Styles.cs

正在加载...
取消
保存