Evgenii Golubev 8 年前
当前提交
672495ee
共有 58 个文件被更改,包括 492 次插入797 次删除
  1. 2
      Assets/ScriptableRenderPipeline.meta
  2. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline.meta
  3. 16
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs
  4. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor.meta
  5. 106
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  6. 70
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  7. 14
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset
  8. 91
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  9. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting.meta
  10. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop.cs
  11. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources.meta
  12. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass.meta
  13. 24
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  14. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material.meta
  15. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit.meta
  16. 18
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
  17. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit.meta
  18. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
  19. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl
  20. 48
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Editor/PostProcessingEditor.cs
  21. 17
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/PostProcessing.Settings.cs
  22. 151
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/PostProcessing.cs
  23. 26
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/FinalPass.shader
  24. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass.meta
  25. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky.meta
  26. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs
  27. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
  28. 26
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  29. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs
  30. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/Resources.meta
  31. 38
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  32. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyRenderer.cs
  33. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs
  34. 4
      Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl
  35. 2
      Assets/TestScenes/HDTest/GlobalIlluminationTest/TestRealtime.cs
  36. 64
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/SceneSettingsManagementWindow.cs
  37. 44
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettings.cs
  38. 12
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettings.cs.meta
  39. 81
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettingsManager.cs
  40. 12
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettingsManager.cs.meta
  41. 15
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs
  42. 17
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs
  43. 45
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipeWindow.cs
  44. 52
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.hlsl
  45. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.hlsl.meta
  46. 9
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.shader.meta
  47. 171
      Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.shader
  48. 15
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyParameters.cs
  49. 17
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyParametersSingleton.cs
  50. 20
      Assets/TestScenes/HDTest/CascadedShadowsTest/HDRISkyParameters_Cascaded.asset
  51. 9
      Assets/TestScenes/HDTest/CascadedShadowsTest/HDRISkyParameters_Cascaded.asset.meta
  52. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/SceneSettingsManagementWindow.cs.meta
  53. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs.meta
  54. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs.meta
  55. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs
  56. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs.meta
  57. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs.meta
  58. 0
      /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs

2
Assets/ScriptableRenderPipeline.meta


fileFormatVersion: 2
guid: 7f2fa2efb8ce343069fc5393536094ad
guid: 403e54624681147459c529bbda90360e
folderAsset: yes
timeCreated: 1466769773
licenseType: Pro

2
Assets/ScriptableRenderPipeline/HDRenderPipeline.meta


fileFormatVersion: 2
guid: 4c38eac64d0e8344d85c9f309419d619
guid: a75de3f722a762f4daf65be08cd9c5c6
folderAsset: yes
timeCreated: 1483548930
licenseType: Pro

16
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public class GlobalDebugParameters
public class GlobalDebugSettings
{
public float debugOverlayRatio = 0.33f;
public bool displayMaterialDebug = false;

public MaterialDebugParameters materialDebugParameters = new MaterialDebugParameters();
public LightingDebugParameters lightingDebugParameters = new LightingDebugParameters();
public RenderingDebugParameters renderingDebugParametrs = new RenderingDebugParameters();
public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings();
public LightingDebugSettings lightingDebugSettings = new LightingDebugSettings();
public RenderingDebugSettings renderingDebugSettings = new RenderingDebugSettings();
lightingDebugParameters.OnValidate();
lightingDebugSettings.OnValidate();
public class MaterialDebugParameters
public class MaterialDebugSettings
public class RenderingDebugParameters
public class RenderingDebugSettings
{
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;

}
[Serializable]
public class LightingDebugParameters
public class LightingDebugSettings
{
public bool enableShadows = true;
public ShadowDebugMode shadowDebugMode = ShadowDebugMode.None;

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor.meta


fileFormatVersion: 2
guid: ab51b986e84ae98449eab2308fbe74db
guid: 6170264326b703040b82caf4f14a7567
folderAsset: yes
timeCreated: 1479127051
licenseType: Pro

106
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


// Sky Settings
public readonly GUIContent skyParams = new GUIContent("Sky Settings");
// Global debug parameters
// Global debug Settings
public readonly GUIContent debugging = new GUIContent("Debugging");
public readonly GUIContent debugOverlayRatio = new GUIContent("Overlay Ratio");

public int[] debugViewMaterialValues = null;
// Rendering Debug
public readonly GUIContent renderingDebugParameters = new GUIContent("Rendering Debug");
public readonly GUIContent renderingDebugSettings = new GUIContent("Rendering Debug");
public readonly GUIContent lightingDebugParameters = new GUIContent("Lighting Debug");
public readonly GUIContent lightingDebugSettings = new GUIContent("Lighting Debug");
public readonly GUIContent shadowDebugEnable = new GUIContent("Enable Shadows");
public readonly GUIContent shadowDebugVisualizationMode = new GUIContent("Shadow Debug Mode");
public readonly GUIContent shadowDebugVisualizeShadowIndex = new GUIContent("Visualize Shadow Index");

SerializedProperty m_LightingDebugOverrideSmoothnessValue = null;
SerializedProperty m_LightingDebugAlbedo = null;
// Rendering Parameters
// Rendering Settings
SerializedProperty m_RenderingUseForwardOnly = null;
SerializedProperty m_RenderingUseDepthPrepass = null;

m_DebugOverlayRatio = FindProperty(x => x.globalDebugParameters.debugOverlayRatio);
m_ShowLightingDebug = FindProperty(x => x.globalDebugParameters.displayLightingDebug);
m_ShowRenderingDebug = FindProperty(x => x.globalDebugParameters.displayRenderingDebug);
m_ShowMaterialDebug = FindProperty(x => x.globalDebugParameters.displayMaterialDebug);
m_DebugOverlayRatio = FindProperty(x => x.globalDebugSettings.debugOverlayRatio);
m_ShowLightingDebug = FindProperty(x => x.globalDebugSettings.displayLightingDebug);
m_ShowRenderingDebug = FindProperty(x => x.globalDebugSettings.displayRenderingDebug);
m_ShowMaterialDebug = FindProperty(x => x.globalDebugSettings.displayMaterialDebug);
m_MaterialDebugMode = FindProperty(x => x.globalDebugParameters.materialDebugParameters.debugViewMaterial);
m_MaterialDebugMode = FindProperty(x => x.globalDebugSettings.materialDebugSettings.debugViewMaterial);
m_DisplayOpaqueObjects = FindProperty(x => x.globalDebugParameters.renderingDebugParametrs.displayOpaqueObjects);
m_DisplayTransparentObjects = FindProperty(x => x.globalDebugParameters.renderingDebugParametrs.displayTransparentObjects);
m_EnableDistortion = FindProperty(x => x.globalDebugParameters.renderingDebugParametrs.enableDistortion);
m_DisplayOpaqueObjects = FindProperty(x => x.globalDebugSettings.renderingDebugSettings.displayOpaqueObjects);
m_DisplayTransparentObjects = FindProperty(x => x.globalDebugSettings.renderingDebugSettings.displayTransparentObjects);
m_EnableDistortion = FindProperty(x => x.globalDebugSettings.renderingDebugSettings.enableDistortion);
m_DebugShadowEnabled = FindProperty(x => x.globalDebugParameters.lightingDebugParameters.enableShadows);
m_ShadowDebugMode = FindProperty(x => x.globalDebugParameters.lightingDebugParameters.shadowDebugMode);
m_ShadowDebugShadowMapIndex = FindProperty(x => x.globalDebugParameters.lightingDebugParameters.shadowMapIndex);
m_LightingDebugMode = FindProperty(x => x.globalDebugParameters.lightingDebugParameters.lightingDebugMode);
m_LightingDebugOverrideSmoothness = FindProperty(x => x.globalDebugParameters.lightingDebugParameters.overrideSmoothness);
m_LightingDebugOverrideSmoothnessValue = FindProperty(x => x.globalDebugParameters.lightingDebugParameters.overrideSmoothnessValue);
m_LightingDebugAlbedo = FindProperty(x => x.globalDebugParameters.lightingDebugParameters.debugLightingAlbedo);
m_DebugShadowEnabled = FindProperty(x => x.globalDebugSettings.lightingDebugSettings.enableShadows);
m_ShadowDebugMode = FindProperty(x => x.globalDebugSettings.lightingDebugSettings.shadowDebugMode);
m_ShadowDebugShadowMapIndex = FindProperty(x => x.globalDebugSettings.lightingDebugSettings.shadowMapIndex);
m_LightingDebugMode = FindProperty(x => x.globalDebugSettings.lightingDebugSettings.lightingDebugMode);
m_LightingDebugOverrideSmoothness = FindProperty(x => x.globalDebugSettings.lightingDebugSettings.overrideSmoothness);
m_LightingDebugOverrideSmoothnessValue = FindProperty(x => x.globalDebugSettings.lightingDebugSettings.overrideSmoothnessValue);
m_LightingDebugAlbedo = FindProperty(x => x.globalDebugSettings.lightingDebugSettings.debugLightingAlbedo);
m_RenderingUseForwardOnly = FindProperty(x => x.renderingParameters.useForwardRenderingOnly);
m_RenderingUseDepthPrepass = FindProperty(x => x.renderingParameters.useDepthPrepass);
m_RenderingUseForwardOnly = FindProperty(x => x.renderingSettings.useForwardRenderingOnly);
m_RenderingUseDepthPrepass = FindProperty(x => x.renderingSettings.useDepthPrepass);
}

{
EditorGUILayout.LabelField(styles.debugging);
// Global debug parameters
// Global debug settings
MaterialDebugParametersUI(renderContext);
RenderingDebugParametersUI(renderContext);
LightingDebugParametersUI(renderContext, renderpipelineInstance);
MaterialDebugSettingsUI(renderContext);
RenderingDebugSettingsUI(renderContext);
LightingDebugSettingsUI(renderContext, renderpipelineInstance);
EditorGUILayout.Space();

private void MaterialDebugParametersUI(HDRenderPipeline renderContext)
private void MaterialDebugSettingsUI(HDRenderPipeline renderContext)
{
m_ShowMaterialDebug.boolValue = EditorGUILayout.Foldout(m_ShowMaterialDebug.boolValue, styles.materialDebugLabel);
if (!m_ShowMaterialDebug.boolValue)

EditorGUI.indentLevel--;
}
private void RenderingDebugParametersUI(HDRenderPipeline renderContext)
private void RenderingDebugSettingsUI(HDRenderPipeline renderContext)
m_ShowRenderingDebug.boolValue = EditorGUILayout.Foldout(m_ShowRenderingDebug.boolValue, styles.renderingDebugParameters);
m_ShowRenderingDebug.boolValue = EditorGUILayout.Foldout(m_ShowRenderingDebug.boolValue, styles.renderingDebugSettings);
if (!m_ShowRenderingDebug.boolValue)
return;

}
}
private void LightingDebugParametersUI(HDRenderPipeline renderContext, HDRenderPipelineInstance renderpipelineInstance)
private void LightingDebugSettingsUI(HDRenderPipeline renderContext, HDRenderPipelineInstance renderpipelineInstance)
m_ShowLightingDebug.boolValue = EditorGUILayout.Foldout(m_ShowLightingDebug.boolValue, styles.lightingDebugParameters);
m_ShowLightingDebug.boolValue = EditorGUILayout.Foldout(m_ShowLightingDebug.boolValue, styles.lightingDebugSettings);
if (!m_ShowLightingDebug.boolValue)
return;

HackSetDirty(renderContext); // Repaint
}
SkySettingsUI(renderContext);
ShadowParametersUI(renderContext);
TextureParametersUI(renderContext);
RendereringParametersUI(renderContext);
ShadowSettingsUI(renderContext);
TextureSettingsUI(renderContext);
RendereringSettingsUI(renderContext);
private void SkySettingsUI(HDRenderPipeline pipe)
private void ShadowSettingsUI(HDRenderPipeline renderContext)
EditorGUILayout.LabelField(styles.skyParams);
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
pipe.skyParameters = (SkyParameters)EditorGUILayout.ObjectField(new GUIContent("Sky Settings"), pipe.skyParameters, typeof(SkyParameters), false);
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(pipe); // Repaint
}
}
private void ShadowParametersUI(HDRenderPipeline renderContext)
{
EditorGUILayout.Space();
var shadowParameters = renderContext.shadowSettings;
var shadowSettings = renderContext.shadowSettings;
shadowParameters.shadowAtlasWidth = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasWidth, shadowParameters.shadowAtlasWidth));
shadowParameters.shadowAtlasHeight = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasHeight, shadowParameters.shadowAtlasHeight));
shadowSettings.shadowAtlasWidth = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasWidth, shadowSettings.shadowAtlasWidth));
shadowSettings.shadowAtlasHeight = Mathf.Max(0, EditorGUILayout.IntField(styles.shadowsAtlasHeight, shadowSettings.shadowAtlasHeight));
if (EditorGUI.EndChangeCheck())
{

}
private void RendereringParametersUI(HDRenderPipeline renderContext)
private void RendereringSettingsUI(HDRenderPipeline renderContext)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(styles.renderingSettingsLabel);

EditorGUI.indentLevel--;
}
private void TextureParametersUI(HDRenderPipeline renderContext)
private void TextureSettingsUI(HDRenderPipeline renderContext)
var textureParameters = renderContext.textureSettings;
var textureSettings = renderContext.textureSettings;
textureParameters.spotCookieSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.spotCookieSize, textureParameters.spotCookieSize), 16, 1024));
textureParameters.pointCookieSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.pointCookieSize, textureParameters.pointCookieSize), 16, 1024));
textureParameters.reflectionCubemapSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.reflectionCubemapSize, textureParameters.reflectionCubemapSize), 64, 1024));
textureSettings.spotCookieSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.spotCookieSize, textureSettings.spotCookieSize), 16, 1024));
textureSettings.pointCookieSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.pointCookieSize, textureSettings.pointCookieSize), 16, 1024));
textureSettings.reflectionCubemapSize = Mathf.NextPowerOfTwo(Mathf.Clamp(EditorGUILayout.IntField(styles.reflectionCubemapSize, textureSettings.reflectionCubemapSize), 64, 1024));
renderContext.textureSettings = textureParameters;
renderContext.textureSettings = textureSettings;
HackSetDirty(renderContext); // Repaint
}
EditorGUI.indentLevel--;

70
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
using UnityEngine.Experimental.Rendering.HDPipeline;
// This script is a helper for the artits to re-synchronise all layered materials
[MenuItem("HDRenderPipeline/Synchronize all Layered materials")]
static void SynchronizeAllLayeredMaterial()
{

if (mat.shader.name == "HDRenderPipeline/LayeredLit" || mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
{
LayeredLitGUI.SynchronizeAllLayers(mat);
EditorUtility.SetDirty(mat);
}
static void RemoveMaterialKeywords(Material material)
{
string[] keywordsToRemove = material.shaderKeywords;
foreach (var keyword in keywordsToRemove)
{
material.DisableKeyword(keyword);
}
[MenuItem("HDRenderPipeline/Update all materials keywords")]
static void UpdateAllMaterialKeywords()
// The goal of this script is to help maintenance of data that have already been produced but need to update to the latest shader code change.
// In case the shader code have change and the inspector have been update with new kind of keywords we need to regenerate the set of keywords use by the material.
// This script will remove all keyword of a material and trigger the inspector that will re-setup all the used keywords.
// It require that the inspector of the material have a static function call that update all keyword based on material properties.
[MenuItem("HDRenderPipeline/Reset all materials keywords")]
static void ResetAllMaterialKeywords()
Object[] materials = Resources.FindObjectsOfTypeAll<Material>();
foreach (Object obj in materials)
try
Material mat = obj as Material;
if (mat.shader.name == "HDRenderPipeline/LayeredLit" || mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
{
LayeredLitGUI.SetupMaterialKeywordsAndPass(mat);
}
else if (mat.shader.name == "HDRenderPipeline/Lit" || mat.shader.name == "HDRenderPipeline/LitTessellation")
{
LitGUI.SetupMaterialKeywordsAndPass(mat);
}
else if (mat.shader.name == "HDRenderPipeline/Unlit")
Object[] materials = Resources.FindObjectsOfTypeAll<Material>();
for (int i = 0, length = materials.Length; i < length; i++)
UnlitGUI.SetupMaterialKeywordsAndPass(mat);
Material mat = materials[i] as Material;
EditorUtility.DisplayProgressBar(
"Setup materials Keywords...",
string.Format("{0} / {1} materials cleaned.", i, length),
i / (float)(length - 1));
if (mat.shader.name == "HDRenderPipeline/LayeredLit" || mat.shader.name == "HDRenderPipeline/LayeredLitTessellation")
{
// We remove all keyword already present
RemoveMaterialKeywords(mat);
LayeredLitGUI.SetupMaterialKeywordsAndPass(mat);
EditorUtility.SetDirty(mat);
}
else if (mat.shader.name == "HDRenderPipeline/Lit" || mat.shader.name == "HDRenderPipeline/LitTessellation")
{
// We remove all keyword already present
RemoveMaterialKeywords(mat);
LitGUI.SetupMaterialKeywordsAndPass(mat);
EditorUtility.SetDirty(mat);
}
else if (mat.shader.name == "HDRenderPipeline/Unlit")
{
// We remove all keyword already present
RemoveMaterialKeywords(mat);
UnlitGUI.SetupMaterialKeywordsAndPass(mat);
EditorUtility.SetDirty(mat);
}
}
finally
{
EditorUtility.ClearProgressBar();
}
}
}

14
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset


m_EditorClassIdentifier:
m_LightLoopProducer: {fileID: 11400000, guid: bf8cd9ae03ff7d54c89603e67be0bfc5,
type: 2}
globalDebugParameters:
globalDebugSettings:
materialDebugParameters:
materialDebugSettings:
lightingDebugParameters:
lightingDebugSettings:
enableShadows: 1
shadowDebugMode: 0
shadowMapIndex: 0

debugLightingAlbedo: {r: 0.5, g: 0.5, b: 0.5, a: 1}
renderingDebugParametrs:
renderingDebugSettings:
renderingParameters:
renderingSettings:
useForwardRenderingOnly: 0
useDepthPrepass: 0
m_ShadowSettings:

maxShadowDistance: 1000
maxShadowDistance: 400
directionalLightCascadeCount: 4
directionalLightCascades: {x: 0.05, y: 0.2, z: 0.3}
directionalLightNearPlaneOffset: 5

m_ShadowCascadeSplit1: 0.2
m_ShadowCascadeSplit2: 0.3
m_ShadowNearPlaneOffset: 5
m_SkyParameters: {fileID: 0}
m_SkySettings: {fileID: 0}

91
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


// NOTE:
// All those properties are public because of how HDRenderPipelineInspector retrieve those properties via serialization/reflection
// Those that are not will be refatored later.
public GlobalDebugParameters globalDebugParameters = new GlobalDebugParameters();
public GlobalDebugSettings globalDebugSettings = new GlobalDebugSettings();
public RenderingParameters renderingParameters = new RenderingParameters();
public RenderingSettings renderingSettings = new RenderingSettings();
[SerializeField] ShadowSettings m_ShadowSettings = ShadowSettings.Default;
public SubsurfaceScatteringParameters localSssParameters;
[SerializeField] TextureSettings m_TextureSettings = TextureSettings.Default;

// Renderer Settings (per "scene")
[SerializeField] private CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;
[SerializeField] private SkyParameters m_SkyParameters;
[SerializeField] private SkySettings m_SkySettings;
public CommonSettings.Settings commonSettingsToUse
{

}
}
public SkyParameters skyParameters
public SkySettings skySettings
get { return m_SkyParameters; }
set { m_SkyParameters = value; }
get { return m_SkySettings; }
set { m_SkySettings = value; }
public SkyParameters skyParametersToUse
public SkySettings skySettingsToUse
if (SkyParametersSingleton.overrideSettings)
return SkyParametersSingleton.overrideSettings;
if (SkySettingsSingleton.overrideSettings)
return SkySettingsSingleton.overrideSettings;
return m_SkyParameters;
return m_SkySettings;
}
}

return localSssParameters;
}
}
public void ApplyDebugParameters()
public void ApplyDebugSettings()
m_ShadowSettings.enabled = globalDebugParameters.lightingDebugParameters.enableShadows;
m_ShadowSettings.enabled = globalDebugSettings.lightingDebugSettings.enableShadows;
LightingDebugParameters lightDebugParameters = globalDebugParameters.lightingDebugParameters;
Vector4 debugModeAndAlbedo = new Vector4((float)lightDebugParameters.lightingDebugMode, lightDebugParameters.debugLightingAlbedo.r, lightDebugParameters.debugLightingAlbedo.g, lightDebugParameters.debugLightingAlbedo.b);
Vector4 debugSmoothness = new Vector4(lightDebugParameters.overrideSmoothness ? 1.0f : 0.0f, lightDebugParameters.overrideSmoothnessValue, 0.0f, 0.0f);
LightingDebugSettings lightDebugSettings = globalDebugSettings.lightingDebugSettings;
Vector4 debugModeAndAlbedo = new Vector4((float)lightDebugSettings.lightingDebugMode, lightDebugSettings.debugLightingAlbedo.r, lightDebugSettings.debugLightingAlbedo.g, lightDebugSettings.debugLightingAlbedo.b);
Vector4 debugSmoothness = new Vector4(lightDebugSettings.overrideSmoothness ? 1.0f : 0.0f, lightDebugSettings.overrideSmoothnessValue, 0.0f, 0.0f);
Shader.SetGlobalVector("_DebugLightModeAndAlbedo", debugModeAndAlbedo);
Shader.SetGlobalVector("_DebugLightingSmoothness", debugSmoothness);

public void OnValidate()
{
globalDebugParameters.OnValidate();
globalDebugSettings.OnValidate();
public class RenderingParameters
public class RenderingSettings
{
public bool useForwardRenderingOnly = false; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool useDepthPrepass = false;

readonly SkyManager m_SkyManager = new SkyManager();
private readonly BaseLightLoop m_LightLoop;
private GlobalDebugParameters globalDebugParameters
private GlobalDebugSettings globalDebugSettings
get { return m_Owner.globalDebugParameters; }
get { return m_Owner.globalDebugSettings; }
}
public HDRenderPipelineInstance(HDRenderPipeline owner)

m_LightLoop.Build(owner.textureSettings);
m_SkyManager.Build();
m_SkyManager.skyParameters = owner.skyParametersToUse;
m_SkyManager.skySettings = owner.skySettingsToUse;
}
public override void Dispose()

// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
m_SkyManager.skyParameters = m_Owner.skyParametersToUse;
m_SkyManager.skySettings = m_Owner.skySettingsToUse;
m_SkyManager.Resize(camera.nearClipPlane, camera.farClipPlane); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
if (m_LightLoop == null)

if (m_LightLoop != null)
m_LightLoop.NewFrame();
m_Owner.ApplyDebugParameters();
m_Owner.ApplyDebugSettings();
m_Owner.UpdateCommonSettings();
// Set Frame constant buffer

cmd.Dispose();
}
if (globalDebugParameters.materialDebugParameters.debugViewMaterial != 0)
if (globalDebugSettings.materialDebugSettings.debugViewMaterial != 0)
{
RenderDebugViewMaterial(cullResults, hdCamera, renderContext);
}

void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!globalDebugParameters.renderingDebugParametrs.displayOpaqueObjects)
if (!globalDebugSettings.renderingDebugSettings.displayOpaqueObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))

void RenderTransparentRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)
{
if (!globalDebugParameters.renderingDebugParametrs.displayTransparentObjects)
if (!globalDebugSettings.renderingDebugSettings.displayTransparentObjects)
return;
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName(passName))

{
// If we are forward only we will do a depth prepass
// TODO: Depth prepass should be enabled based on light loop settings. LightLoop define if they need a depth prepass + forward only...
if (!m_Owner.renderingParameters.useDepthPrepass)
if (!m_Owner.renderingSettings.useDepthPrepass)
return;
using (new Utilities.ProfilingSample("Depth Prepass", renderContext))

void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext renderContext)
{
if (m_Owner.renderingParameters.ShouldUseForwardRenderingOnly())
if (m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
{
return ;
}

bool debugLighting = globalDebugParameters.lightingDebugParameters.lightingDebugMode != LightingDebugMode.None;
bool debugLighting = globalDebugSettings.lightingDebugSettings.lightingDebugMode != LightingDebugMode.None;
// setup GBuffer for rendering
Utilities.SetRenderTarget(renderContext, m_gbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT);

{
// If we are forward only we don't need to render ForwardOnlyOpaqueDepthOnly object
// But in case we request a prepass we render it
if (m_Owner.renderingParameters.ShouldUseForwardRenderingOnly() && !m_Owner.renderingParameters.useDepthPrepass)
if (m_Owner.renderingSettings.ShouldUseForwardRenderingOnly() && !m_Owner.renderingSettings.useDepthPrepass)
return;
using (new Utilities.ProfilingSample("Forward opaque depth", renderContext))

{
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, Utilities.kClearAll, Color.black);
Shader.SetGlobalInt("_DebugViewMaterial", (int)globalDebugParameters.materialDebugParameters.debugViewMaterial);
Shader.SetGlobalInt("_DebugViewMaterial", (int)globalDebugSettings.materialDebugSettings.debugViewMaterial);
if (!m_Owner.renderingParameters.ShouldUseForwardRenderingOnly())
if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
m_DebugViewMaterialGBuffer.SetFloat("_DebugViewMaterial", (float)globalDebugParameters.materialDebugParameters.debugViewMaterial);
m_DebugViewMaterialGBuffer.SetFloat("_DebugViewMaterial", (float)globalDebugSettings.materialDebugSettings.debugViewMaterial);
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures

void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext, bool enableSSS)
{
if (m_Owner.renderingParameters.ShouldUseForwardRenderingOnly() || m_LightLoop == null)
if (m_Owner.renderingSettings.ShouldUseForwardRenderingOnly() || m_LightLoop == null)
{
return ;
}

if (enableSSS)
{
// Output split lighting for materials tagged with the SSS stencil bit.
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugParameters.lightingDebugParameters, colorRTs, m_CameraStencilBufferRT, true, enableSSS);
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugSettings.lightingDebugSettings, colorRTs, m_CameraStencilBufferRT, true, enableSSS);
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugParameters.lightingDebugParameters, colorRTs, m_CameraStencilBufferRT, false, enableSSS);
m_LightLoop.RenderDeferredLighting(hdCamera, renderContext, globalDebugSettings.lightingDebugSettings, colorRTs, m_CameraStencilBufferRT, false, enableSSS);
}
// Combines specular lighting and diffuse lighting with subsurface scattering.

if (m_Owner.renderingParameters.ShouldUseForwardRenderingOnly()) return;
if (m_Owner.renderingSettings.ShouldUseForwardRenderingOnly()) return;
if (!sssParameters.enableSSS) return;

{
// TODO: Currently we can't render opaque object forward when deferred is enabled
// miss option
if (!m_Owner.renderingParameters.ShouldUseForwardRenderingOnly() && renderOpaque)
if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly() && renderOpaque)
return;
using (new Utilities.ProfilingSample("Forward Pass", renderContext))

if (m_LightLoop != null)
m_LightLoop.RenderForward(camera, renderContext, renderOpaque);
bool debugLighting = globalDebugParameters.lightingDebugParameters.lightingDebugMode != LightingDebugMode.None;
bool debugLighting = globalDebugSettings.lightingDebugSettings.lightingDebugMode != LightingDebugMode.None;
string forwardPassName = debugLighting ? "ForwardDebugLighting" : "Forward";
if (renderOpaque)

if (m_LightLoop != null)
m_LightLoop.RenderForward(camera, renderContext, true);
bool debugLighting = globalDebugParameters.lightingDebugParameters.lightingDebugMode != LightingDebugMode.None;
bool debugLighting = globalDebugSettings.lightingDebugSettings.lightingDebugMode != LightingDebugMode.None;
RenderOpaqueRenderList(cullResults, camera, renderContext, debugLighting ? "ForwardOnlyOpaqueDebugLighting" : "ForwardOnlyOpaque", Utilities.kRendererConfigurationBakedLighting);
}
}

using (new Utilities.ProfilingSample("Velocity Pass", renderContext))
{
// If opaque velocity have been render during GBuffer no need to render it here
if ((ShaderConfig.s_VelocityInGbuffer == 1) || m_Owner.renderingParameters.ShouldUseForwardRenderingOnly())
if ((ShaderConfig.s_VelocityInGbuffer == 1) || m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
return ;
int w = camera.pixelWidth;

void RenderDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext)
{
if (!globalDebugParameters.renderingDebugParametrs.enableDistortion)
if (!globalDebugSettings.renderingDebugSettings.enableDistortion)
return ;
using (new Utilities.ProfilingSample("Distortion Pass", renderContext))

debugCB.name = "Debug Overlay";
float x = 0;
float overlayRatio = globalDebugParameters.debugOverlayRatio;
float overlayRatio = globalDebugSettings.debugOverlayRatio;
LightingDebugParameters shadowDebug = globalDebugParameters.lightingDebugParameters;
LightingDebugSettings shadowDebug = globalDebugSettings.lightingDebugSettings;
if (shadowDebug.shadowDebugMode != ShadowDebugMode.None)
{

cmd.GetTemporaryRT(m_CameraDepthStencilBufferCopy, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth);
cmd.GetTemporaryRT(m_CameraStencilBuffer, w, h, 24, FilterMode.Point, RenderTextureFormat.Depth);
if (!m_Owner.renderingParameters.ShouldUseForwardRenderingOnly())
if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
{
m_gbufferManager.InitGBuffers(w, h, cmd);
}

}
// Clear GBuffers
if (!m_Owner.renderingParameters.ShouldUseForwardRenderingOnly())
if (!m_Owner.renderingSettings.ShouldUseForwardRenderingOnly())
{
using (new Utilities.ProfilingSample("Clear GBuffer", renderContext))
{

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting.meta


fileFormatVersion: 2
guid: 1c14e71d397fce047b1675fc26d0bb48
guid: 3002976b0b09954499dd1f6e00169b06
folderAsset: yes
timeCreated: 1474297943
licenseType: Pro

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop.cs


public virtual void PushGlobalParams(Camera camera, ScriptableRenderContext loop) {}
public virtual void RenderDeferredLighting(HDCamera hdCamera, ScriptableRenderContext renderContext,
LightingDebugParameters lightDebugParameters,
LightingDebugSettings lightDebugParameters,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier stencilBuffer,
bool outputSplitLightingForSSS, bool enableSSS) {}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/Resources.meta


fileFormatVersion: 2
guid: 8d7b73e3debb13b46a544563ce8f4a64
guid: 0823a45531ce4ee45ab39bcbe1ea52a6
folderAsset: yes
timeCreated: 1479129942
licenseType: Pro

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass.meta


fileFormatVersion: 2
guid: 8a355c056864a5d4cb26d9c3168ae0bb
guid: 8d0d2ae5d51ae6e42a81b92e8693272f
folderAsset: yes
timeCreated: 1479218330
licenseType: Pro

24
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


}
#endif
private void SetupRenderingForDebug(LightingDebugParameters lightDebugParameters)
private void SetupRenderingForDebug(LightingDebugSettings lightDebugSettings)
Utilities.SetKeyword(m_DeferredDirectMaterialSRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredDirectMaterialMRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredIndirectMaterialSRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredIndirectMaterialMRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredAllMaterialSRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredAllMaterialMRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_SingleDeferredMaterialSRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_SingleDeferredMaterialMRT, "LIGHTING_DEBUG", lightDebugParameters.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredDirectMaterialSRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredDirectMaterialMRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredIndirectMaterialSRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredIndirectMaterialMRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredAllMaterialSRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_DeferredAllMaterialMRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_SingleDeferredMaterialSRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
Utilities.SetKeyword(m_SingleDeferredMaterialMRT, "LIGHTING_DEBUG", lightDebugSettings.lightingDebugMode != LightingDebugMode.None);
LightingDebugParameters lightDebugParameters,
LightingDebugSettings lightDebugSettings,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier stencilBuffer,
bool outputSplitLightingForSSS, bool enableSSS)
{

SetGlobalBuffer("g_vLightListGlobal", bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)
if (lightDebugParameters.lightingDebugMode == LightingDebugMode.None)
if (lightDebugSettings.lightingDebugMode == LightingDebugMode.None)
SetGlobalPropertyRedirect(shadeOpaqueShader, usingFptl ? s_shadeOpaqueFptlKernel : s_shadeOpaqueClusteredKernel, cmd);
else
SetGlobalPropertyRedirect(shadeOpaqueShader, usingFptl ? s_shadeOpaqueFptlDebugLightingKernel : s_shadeOpaqueClusteredDebugLightingKernel, cmd);

}
// Must be done after setting up the compute shader above.
SetupRenderingForDebug(lightDebugParameters);
SetupRenderingForDebug(lightDebugSettings);
if (m_PassSettings.disableTileAndCluster)
{

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material.meta


fileFormatVersion: 2
guid: 96af336cb096f854ea18990a1c0a4e19
guid: 49844bc6823848a4087668ebd3367436
folderAsset: yes
timeCreated: 1474297943
licenseType: Pro

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit.meta


fileFormatVersion: 2
guid: e173dfe6cd75d954b95306237244f6de
guid: c526d3e6d7f3ce1408308bb431089d2d
folderAsset: yes
timeCreated: 1476653183
licenseType: Pro

18
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs


protected override void FindMaterialProperties(MaterialProperty[] props)
{
// Inherit from LitUI
horizonFade = FindProperty(kHorizonFade, props);
layerCount = FindProperty(kLayerCount, props);
layerMaskMap = FindProperty(kLayerMaskMap, props);
vertexColorMode = FindProperty(kVertexColorMode, props);

Material[] layers = null;
InitializeMaterialLayers(materialImporter, ref layers);
for (int i = 0 ; i < layerCount ; ++i)
// We could have no userData in the assets, so test if we have load something
if (layers != null)
SynchronizeLayerProperties(material, layers, i);
for (int i = 0; i < layerCount; ++i)
{
SynchronizeLayerProperties(material, layers, i);
}
}
}

useHeightBasedBlend.floatValue = enabled ? 1.0f : 0.0f;
}
m_MaterialEditor.ShaderProperty(objectScaleAffectTile, mainLayerModeInfluenceEnable ? styles.objectScaleAffectTileText2 : styles.objectScaleAffectTileText);
m_MaterialEditor.ShaderProperty(objectScaleAffectTile, mainLayerModeInfluenceEnable ? styles.objectScaleAffectTileText2 : styles.objectScaleAffectTileText);
m_MaterialEditor.ShaderProperty(horizonFade, Styles.horizonFadeText);
EditorGUILayout.Space();

SetKeyword(material, "_DETAIL_MAP" + i, material.GetTexture(kDetailMap + i));
SetKeyword(material, "_HEIGHTMAP0" + i, material.GetTexture(kHeightMap + i));
SetKeyword(material, "_HEIGHTMAP" + i, material.GetTexture(kHeightMap + i));
}
SetKeyword(material, "_EMISSIVE_COLOR_MAP", material.GetTexture(kEmissiveColorMap));

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit.meta


fileFormatVersion: 2
guid: d6cadd3aaf3ad6641b86e85a0929b245
guid: 0d05f89ce69203543914d745c388e6bb
folderAsset: yes
timeCreated: 1476653183
licenseType: Pro

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/LitUI.cs


protected MaterialProperty specularOcclusionMap = null;
protected const string kSpecularOcclusionMap = "_SpecularOcclusionMap";
protected MaterialProperty horizonFade = null;
const string kHorizonFade = "_HorizonFade";
protected const string kHorizonFade = "_HorizonFade";
protected MaterialProperty normalMap = null;
protected const string kNormalMap = "_NormalMap";
protected MaterialProperty normalScale = null;

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitData.hlsl


return result;
}
#define SURFACEDATA_BLEND_VECTOR3(surfaceData, name, mask) BlendLayeredVector3(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);
#define SURFACEDATA_BLEND_SCALAR(surfaceData, name, mask) BlendLayeredScalar(surfaceData##0.##name, surfaceData##1.##name, surfaceData##2.##name, surfaceData##3.##name, mask);
#define SURFACEDATA_BLEND_VECTOR3(surfaceData, name, mask) BlendLayeredVector3(MERGE_NAME(surfaceData, 0) MERGE_NAME(., name), MERGE_NAME(surfaceData, 1) MERGE_NAME(., name), MERGE_NAME(surfaceData, 2) MERGE_NAME(., name), MERGE_NAME(surfaceData, 3) MERGE_NAME(., name), mask);
#define SURFACEDATA_BLEND_SCALAR(surfaceData, name, mask) BlendLayeredScalar(MERGE_NAME(surfaceData, 0) MERGE_NAME(., name), MERGE_NAME(surfaceData, 1) MERGE_NAME(., name), MERGE_NAME(surfaceData, 2) MERGE_NAME(., name), MERGE_NAME(surfaceData, 3) MERGE_NAME(., name), mask);
#define PROP_BLEND_SCALAR(name, mask) BlendLayeredScalar(name##0, name##1, name##2, name##3, mask);
void GetLayerTexCoord(float2 texCoord0, float2 texCoord1, float2 texCoord2, float2 texCoord3,

48
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Editor/PostProcessingEditor.cs


public SerializedProperty intensity;
public SerializedProperty smoothness;
}
public class BloomSettings
{
public SerializedProperty enabled;
public SerializedProperty intensity;
public SerializedProperty threshold;
public SerializedProperty softKnee;
public SerializedProperty radius;
public SerializedProperty lensTexture;
public SerializedProperty lensIntensity;
}
#endregion
public ColorGradingSettings colorGrading;

public BloomSettings bloomSettings;
public SerializedProperty globalDithering;
SerializedProperty FindProperty<TValue>(Expression<Func<PostProcessing, TValue>> expr)

smoothness = FindProperty(x => x.vignetteSettings.smoothness)
};
bloomSettings = new BloomSettings
{
enabled = FindProperty(x => x.bloomSettings.enabled),
intensity = FindProperty(x => x.bloomSettings.intensity),
threshold = FindProperty(x => x.bloomSettings.threshold),
softKnee = FindProperty(x => x.bloomSettings.softKnee),
radius = FindProperty(x => x.bloomSettings.radius),
lensTexture = FindProperty(x => x.bloomSettings.lensTexture),
lensIntensity = FindProperty(x => x.bloomSettings.lensIntensity)
};
globalDithering = FindProperty(x => x.globalDithering);
}

Do("Color Grading", ColorGradingUI);
Do("Eye Adaptation", EyeAdaptationUI);
Do("Bloom", BloomUI);
Do("Chromatic Aberration", ChromaticAberrationUI);
Do("Vignette", VignetteUI);

EditorGUILayout.PropertyField(eyeAdaptation.speedDown);
EditorGUI.indentLevel--;
}
}
}
void BloomUI()
{
EditorGUILayout.PropertyField(bloomSettings.enabled);
if (bloomSettings.enabled.boolValue)
{
EditorGUILayout.PropertyField(bloomSettings.intensity);
EditorGUILayout.PropertyField(bloomSettings.threshold);
EditorGUILayout.PropertyField(bloomSettings.softKnee);
EditorGUILayout.PropertyField(bloomSettings.radius);
EditorGUILayout.PropertyField(bloomSettings.lensTexture);
EditorGUILayout.PropertyField(bloomSettings.lensIntensity);
bloomSettings.intensity.floatValue = Mathf.Max(0f, bloomSettings.intensity.floatValue);
bloomSettings.threshold.floatValue = Mathf.Max(0f, bloomSettings.threshold.floatValue);
bloomSettings.lensIntensity.floatValue = Mathf.Max(0f, bloomSettings.lensIntensity.floatValue);
}
}

17
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/PostProcessing.Settings.cs


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

[Range(0f, 1f)] public float intensity = 0.3f;
[Range(0f, 1f)] public float smoothness = 0.3f;
}
[Serializable]
public sealed class BloomSettings
{
public bool enabled = false;
public float intensity = 0.5f;
public float threshold = 1.1f;
[Range(0f, 1f)] public float softKnee = 0.5f;
[Range(1f, 7f)] public float radius = 5f;
public Texture lensTexture;
public float lensIntensity = 3f;
}
}
}

151
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/PostProcessing.cs


[RequireComponent(typeof(Camera))]
public sealed partial class PostProcessing : MonoBehaviour
{
// Quick & very dirty temporary wrapper used for bloom (easy porting from old school render
// texture blitting to command buffers)
struct RenderTextureWrapper
{
static int s_Counter = 0;
public int id;
public RenderTargetIdentifier identifier;
public int width;
public int height;
public int depth;
public FilterMode filter;
public RenderTextureFormat format;
internal void Release(CommandBuffer cmd)
{
cmd.ReleaseTemporaryRT(id);
id = 0;
}
internal static RenderTextureWrapper Create(CommandBuffer cmd, int width, int height, int depth = 0, FilterMode filter = FilterMode.Bilinear, RenderTextureFormat format = RenderTextureFormat.DefaultHDR)
{
s_Counter++;
int id = Shader.PropertyToID("_TempRenderTexture_" + s_Counter);
cmd.GetTemporaryRT(id, width, height, depth, filter, format);
return new RenderTextureWrapper
{
id = id,
identifier = new RenderTargetIdentifier(id),
width = width,
height = height,
depth = depth,
filter = filter,
format = format
};
}
}
public BloomSettings bloomSettings = new BloomSettings();
Material m_BloomMaterial;
Material m_FinalPassMaterial;
ComputeShader m_EyeCompute;

static uint[] s_EmptyHistogramBuffer = new uint[k_HistogramBins];
const int k_MaxPyramidBlurLevel = 16;
readonly RenderTextureWrapper[] m_BlurBuffer1 = new RenderTextureWrapper[k_MaxPyramidBlurLevel];
readonly RenderTextureWrapper[] m_BlurBuffer2 = new RenderTextureWrapper[k_MaxPyramidBlurLevel];
RenderTextureWrapper m_BloomTex;
bool m_FirstFrame = true;
// Don't forget to update 'EyeAdaptation.cginc' if you change these values !

void OnEnable()
{
m_EyeAdaptationMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/EyeAdaptation");
m_BloomMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/Bloom");
m_FinalPassMaterial = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/FinalPass");
m_EyeCompute = Resources.Load<ComputeShader>("EyeHistogram");

void OnDisable()
{
Utilities.Destroy(m_EyeAdaptationMaterial);
Utilities.Destroy(m_BloomMaterial);
Utilities.Destroy(m_FinalPassMaterial);
foreach (var rt in m_AutoExposurePool)

Utilities.SafeRelease(m_HistogramBuffer);
m_EyeAdaptationMaterial = null;
m_BloomMaterial = null;
m_FinalPassMaterial = null;
}

if (eyeAdaptation.enabled)
DoEyeAdaptation(camera, cmd, source);
if (bloomSettings.enabled)
DoBloom(camera, cmd, source);
if (chromaSettings.enabled)
DoChromaticAberration();

DoColorGrading();
cmd.Blit(source, destination, m_FinalPassMaterial, 0);
if (bloomSettings.enabled)
m_BloomTex.Release(cmd);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();

m_FirstFrame = false;
}
void DoBloom(Camera camera, CommandBuffer cmd, RenderTargetIdentifier source)
{
m_BloomMaterial.shaderKeywords = null;
// Apply auto exposure before the prefiltering pass if needed
if (eyeAdaptation.enabled)
{
m_BloomMaterial.EnableKeyword("EYE_ADAPTATION");
m_BloomMaterial.SetTexture(Uniforms._AutoExposure, m_CurrentAutoExposure);
}
// Do bloom on a half-res buffer, full-res doesn't bring much and kills performances on
// fillrate limited platforms
int tw = camera.pixelWidth / 2;
int th = camera.pixelHeight / 2;
// Determine the iteration count
float logh = Mathf.Log(th, 2f) + bloomSettings.radius - 8f;
int logh_i = (int)logh;
int iterations = Mathf.Clamp(logh_i, 1, k_MaxPyramidBlurLevel);
// Uupdate the shader properties
float lthresh = Mathf.GammaToLinearSpace(bloomSettings.threshold);;
m_BloomMaterial.SetFloat(Uniforms._Threshold, lthresh);
float knee = lthresh * bloomSettings.softKnee + 1e-5f;
var curve = new Vector3(lthresh - knee, knee * 2f, 0.25f / knee);
m_BloomMaterial.SetVector(Uniforms._Curve, curve);
float sampleScale = 0.5f + logh - logh_i;
m_BloomMaterial.SetFloat(Uniforms._SampleScale, sampleScale);
// Prefilter pass
var prefiltered = RenderTextureWrapper.Create(cmd, tw, th, 0, FilterMode.Point);
cmd.Blit(source, prefiltered.identifier, m_BloomMaterial, 0);
var last = prefiltered;
// Construct a mip pyramid
for (int level = 0; level < iterations; level++)
{
m_BlurBuffer1[level] = RenderTextureWrapper.Create(cmd, last.width / 2, last.height / 2);
cmd.Blit(last.identifier, m_BlurBuffer1[level].identifier, m_BloomMaterial, level == 0 ? 1 : 2);
last = m_BlurBuffer1[level];
}
// Upsample and combine loop
for (int level = iterations - 2; level >= 0; level--)
{
var baseTex = m_BlurBuffer1[level];
cmd.SetGlobalTexture(Uniforms._BaseTex, baseTex.identifier); // Boooo
m_BlurBuffer2[level] = RenderTextureWrapper.Create(cmd, baseTex.width, baseTex.height);
cmd.Blit(last.identifier, m_BlurBuffer2[level].identifier, m_BloomMaterial, 3);
last = m_BlurBuffer2[level];
}
m_BloomTex = last;
// Release the temporary buffers
for (int i = 0; i < k_MaxPyramidBlurLevel; i++)
{
if (m_BlurBuffer1[i].id != 0)
m_BlurBuffer1[i].Release(cmd);
if (m_BlurBuffer2[i].id != 0 && m_BlurBuffer2[i].id != m_BloomTex.id)
m_BlurBuffer2[i].Release(cmd);
}
prefiltered.Release(cmd);
// Push everything to the uber material
m_FinalPassMaterial.EnableKeyword("BLOOM");
cmd.SetGlobalTexture(Uniforms._BloomTex, m_BloomTex.identifier);
cmd.SetGlobalVector(Uniforms._Bloom_Settings, new Vector2(sampleScale, bloomSettings.intensity));
if (bloomSettings.lensIntensity > 0f && bloomSettings.lensTexture != null)
{
m_FinalPassMaterial.EnableKeyword("BLOOM_LENS_DIRT");
cmd.SetGlobalTexture(Uniforms._Bloom_DirtTex, bloomSettings.lensTexture);
cmd.SetGlobalFloat(Uniforms._Bloom_DirtIntensity, bloomSettings.lensIntensity);
}
}
void DoChromaticAberration()
{
var spectralLut = chromaSettings.spectralTexture == null

internal static readonly int _AutoExposure = Shader.PropertyToID("_AutoExposure");
internal static readonly int _DebugWidth = Shader.PropertyToID("_DebugWidth");
internal static readonly int _Threshold = Shader.PropertyToID("_Threshold");
internal static readonly int _Curve = Shader.PropertyToID("_Curve");
internal static readonly int _SampleScale = Shader.PropertyToID("_SampleScale");
internal static readonly int _BaseTex = Shader.PropertyToID("_BaseTex");
internal static readonly int _BloomTex = Shader.PropertyToID("_BloomTex");
internal static readonly int _Bloom_Settings = Shader.PropertyToID("_Bloom_Settings");
internal static readonly int _Bloom_DirtTex = Shader.PropertyToID("_Bloom_DirtTex");
internal static readonly int _Bloom_DirtIntensity = Shader.PropertyToID("_Bloom_DirtIntensity");
internal static readonly int _ChromaticAberration_Amount = Shader.PropertyToID("_ChromaticAberration_Amount");
internal static readonly int _ChromaticAberration_Lut = Shader.PropertyToID("_ChromaticAberration_Lut");

26
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/FinalPass.shader


#include "ShaderLibrary/Common.hlsl"
#include "HDRenderPipeline/ShaderVariables.hlsl"
#include "ColorGrading.hlsl"
#include "Bloom.hlsl"
TEXTURE2D(_MainTex);
SAMPLER2D(sampler_MainTex);

float4 _LogLut_Params;
float _Exposure;
TEXTURE2D(_BloomTex);
SAMPLER2D(sampler_BloomTex);
float4 _BloomTex_TexelSize;
float2 _Bloom_Settings; // x: sampleScale, y: bloom.intensity
TEXTURE2D(_Bloom_DirtTex);
SAMPLER2D(sampler_Bloom_DirtTex);
float _Bloom_DirtIntensity;
float4 _NeutralTonemapperParams1;
float4 _NeutralTonemapperParams2;

}
#endif
#if BLOOM
{
float3 bloom = UpsampleFilter(TEXTURE2D_PARAM(_BloomTex, sampler_BloomTex), uv, _BloomTex_TexelSize.xy, _Bloom_Settings.x) * _Bloom_Settings.y; // Flipped
color += bloom;
#if BLOOM_LENS_DIRT
{
float3 dirt = SAMPLE_TEXTURE2D(_Bloom_DirtTex, sampler_Bloom_DirtTex, uv).rgb * _Bloom_DirtIntensity; // Flipped
color += bloom * dirt;
}
#endif
}
#endif
#if VIGNETTE
{
float2 d = abs(uv - _Vignette_Settings.zw) * _Vignette_Settings.x;

#pragma fragment Frag
#pragma multi_compile __ NEUTRAL_GRADING CUSTOM_GRADING
#pragma multi_compile __ EYE_ADAPTATION
#pragma multi_compile __ BLOOM
#pragma multi_compile __ BLOOM_LENS_DIRT
#pragma multi_compile __ CHROMATIC_ABERRATION
#pragma multi_compile __ VIGNETTE
#pragma multi_compile __ DITHERING

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass.meta


fileFormatVersion: 2
guid: e3b3ad4462341ec4b86566ec1fd82c7c
guid: 057d8506536500045b3047320a4d6122
folderAsset: yes
timeCreated: 1476885561
licenseType: Pro

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky.meta


fileFormatVersion: 2
guid: 066ab4d03bd03384f81c9d82b479f8dd
guid: 99e8d5bd81663624399d10e3fc27571c
folderAsset: yes
timeCreated: 1479239906
licenseType: Pro

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[CanEditMultipleObjects]
[CustomEditor(typeof(HDRISkyParameters))]
[CustomEditor(typeof(HDRISkySettings))]
public class HDRISkyParametersEditor
: Editor
{

6
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs


public class HDRISkyRenderer : SkyRenderer
{
Material m_SkyHDRIMaterial; // Renders a cubemap into a render texture (can be cube or 2D)
private HDRISkyParameters m_HdriSkyParams;
private HDRISkySettings m_HdriSkyParams;
public HDRISkyRenderer(HDRISkyParameters hdriSkyParams)
public HDRISkyRenderer(HDRISkySettings hdriSkyParams)
{
m_HdriSkyParams = hdriSkyParams;
}

}
}
public override void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap)
public override void RenderSky(BuiltinSkyParameters builtinParams, SkySettings skyParameters, bool renderForCubemap)
{
m_SkyHDRIMaterial.SetTexture("_Cubemap", m_HdriSkyParams.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(m_HdriSkyParams.exposure, m_HdriSkyParams.multiplier, m_HdriSkyParams.rotation, 0.0f));

26
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs


public class ProceduralSkyRenderer : SkyRenderer
{
Material m_ProceduralSkyMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
private ProceduralSkyParameters m_ProceduralSkyParameters;
private ProceduralSkySettings m_ProceduralSkySettings;
public ProceduralSkyRenderer(ProceduralSkyParameters proceduralSkyParameters)
public ProceduralSkyRenderer(ProceduralSkySettings proceduralSkySettings)
m_ProceduralSkyParameters = proceduralSkyParameters;
m_ProceduralSkySettings = proceduralSkySettings;
}
public override void Build()

public override bool IsSkyValid()
{
if (m_ProceduralSkyMaterial == null || m_ProceduralSkyParameters == null)
if (m_ProceduralSkyMaterial == null || m_ProceduralSkySettings == null)
return m_ProceduralSkyParameters.skyHDRI != null &&
m_ProceduralSkyParameters.worldMieColorRamp != null &&
m_ProceduralSkyParameters.worldRayleighColorRamp != null;
return m_ProceduralSkySettings.skyHDRI != null &&
m_ProceduralSkySettings.worldMieColorRamp != null &&
m_ProceduralSkySettings.worldRayleighColorRamp != null;
}
public override void SetRenderTargets(BuiltinSkyParameters builtinParams)

Utilities.SetRenderTarget(builtinParams.renderContext, builtinParams.colorBuffer);
}
void SetKeywords(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param, bool renderForCubemap)
void SetKeywords(BuiltinSkyParameters builtinParams, ProceduralSkySettings param, bool renderForCubemap)
{
// Ensure that all preprocessor symbols are initially undefined.
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS");

m_ProceduralSkyMaterial.EnableKeyword("PERFORM_SKY_OCCLUSION_TEST");
}
if (param.debugMode != ProceduralSkyParameters.ScatterDebugMode.None)
if (param.debugMode != ProceduralSkySettings.ScatterDebugMode.None)
void SetUniforms(BuiltinSkyParameters builtinParams, ProceduralSkyParameters param, bool renderForCubemap, ref MaterialPropertyBlock properties)
void SetUniforms(BuiltinSkyParameters builtinParams, ProceduralSkySettings param, bool renderForCubemap, ref MaterialPropertyBlock properties)
{
properties.SetTexture("_Cubemap", param.skyHDRI);
properties.SetVector("_SkyParam", new Vector4(param.exposure, param.multiplier, param.rotation, 0.0f));

properties.SetFloat("_HeightMieDensity", renderForCubemap ? -0.0f : -param.heightMieDensity / 100000f);
}
override public void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap)
override public void RenderSky(BuiltinSkyParameters builtinParams, SkySettings skyParameters, bool renderForCubemap)
SetKeywords(builtinParams, m_ProceduralSkyParameters, renderForCubemap);
SetKeywords(builtinParams, m_ProceduralSkySettings, renderForCubemap);
SetUniforms(builtinParams, m_ProceduralSkyParameters, renderForCubemap, ref properties);
SetUniforms(builtinParams, m_ProceduralSkySettings, renderForCubemap, ref properties);
var cmd = new CommandBuffer { name = "" };

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs


{
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class ProceduralSkyParameters : SkyParameters
public class ProceduralSkySettings : SkySettings
{
public enum OcclusionDownscale { x1 = 1, x2 = 2, x4 = 4 }
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/Resources.meta


fileFormatVersion: 2
guid: 4cdc45a9a65126a42aca158413a5b089
guid: 920208451db81a846ae1c2d55f7b50b4
folderAsset: yes
timeCreated: 1479239906
licenseType: Pro

38
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


bool m_useMIS = false;
private SkyParameters m_SkyParameters;
public SkyParameters skyParameters
private SkySettings m_SkySettings;
public SkySettings skySettings
if (m_SkyParameters == value)
if (m_SkySettings == value)
return;
if (m_Renderer != null)

}
m_SkyParametersHash = 0;
m_SkyParameters = value;
m_SkySettings = value;
m_UpdateRequired = true;
if (value != null)

}
}
get { return m_SkyParameters; }
get { return m_SkySettings; }
}
protected Mesh BuildSkyMesh(Vector3 cameraPosition, Matrix4x4 cameraInvViewProjectionMatrix, bool forceUVBottom)

};
}
void RebuildTextures(SkyParameters skyParameters)
void RebuildTextures(SkySettings skySettings)
if (skyParameters != null)
resolution = (int)skyParameters.resolution;
if (skySettings != null)
resolution = (int)skySettings.resolution;
if ((m_SkyboxCubemapRT != null) && (m_SkyboxCubemapRT.width != resolution))
{

public void Resize(float nearPlane, float farPlane)
{
// When loading RenderDoc, RenderTextures will go null
RebuildTextures(skyParameters);
RebuildTextures(skySettings);
RebuildSkyMeshes(nearPlane, farPlane);
}

return m_Renderer != null && m_Renderer.IsSkyValid();
}
private void RenderSkyToCubemap(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, RenderTexture target)
private void RenderSkyToCubemap(BuiltinSkyParameters builtinParams, SkySettings skySettings, RenderTexture target)
{
for (int i = 0; i < 6; ++i)
{

builtinParams.depthBuffer = BuiltinSkyParameters.nullRT;
Utilities.SetRenderTarget(builtinParams.renderContext, target, ClearFlag.ClearNone, 0, (CubemapFace)i);
m_Renderer.RenderSky(builtinParams, skyParameters, true);
m_Renderer.RenderSky(builtinParams, skySettings, true);
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderContext, BuiltinSkyParameters builtinParams, SkyParameters skyParams, Texture input, RenderTexture target)
private void RenderCubemapGGXConvolution(ScriptableRenderContext renderContext, BuiltinSkyParameters builtinParams, SkySettings skyParams, Texture input, RenderTexture target)
{
using (new Utilities.ProfilingSample("Sky Pass: GGX Convolution", renderContext))
{

}
if (
(skyParameters.updateMode == EnvironementUpdateMode.OnDemand && m_UpdateRequired) ||
(skyParameters.updateMode == EnvironementUpdateMode.OnChanged && skyParameters.GetHash() != m_SkyParametersHash) ||
(skyParameters.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skyParameters.updatePeriod)
(skySettings.updateMode == EnvironementUpdateMode.OnDemand && m_UpdateRequired) ||
(skySettings.updateMode == EnvironementUpdateMode.OnChanged && skySettings.GetHash() != m_SkyParametersHash) ||
(skySettings.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skySettings.updatePeriod)
RenderSkyToCubemap(m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT);
RenderSkyToCubemap(m_BuiltinParameters, skySettings, m_SkyboxCubemapRT);
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skySettings, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
m_SkyParametersHash = skyParameters.GetHash();
m_SkyParametersHash = skySettings.GetHash();
m_CurrentUpdateTime = 0.0f;
}
}

m_BuiltinParameters.depthBuffer = depthBuffer;
m_Renderer.SetRenderTargets(m_BuiltinParameters);
m_Renderer.RenderSky(m_BuiltinParameters, skyParameters, false);
m_Renderer.RenderSky(m_BuiltinParameters, skySettings, false);
}
}
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyRenderer.cs


public abstract void Cleanup();
public abstract void SetRenderTargets(BuiltinSkyParameters builtinParams);
// renderForCubemap: When rendering into a cube map, no depth buffer is available so user has to make sure not to use depth testing or the depth texture.
public abstract void RenderSky(BuiltinSkyParameters builtinParams, SkyParameters skyParameters, bool renderForCubemap);
public abstract void RenderSky(BuiltinSkyParameters builtinParams, SkySettings skyParameters, bool renderForCubemap);
public abstract bool IsSkyValid();
}
}

2
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
public abstract class SkyParameters : ScriptableObject
public abstract class SkySettings : ScriptableObject
{
protected class Unhashed : System.Attribute {}

4
Assets/ScriptableRenderPipeline/ShaderLibrary/Common.hlsl


#endif
#include "API/Validate.hlsl"
// Some shader compiler don't support to do multiple ## for concatenation inside the same macro, it require an indirection.
// This is the purpose of this macro
#define MERGE_NAME(X, Y) X##Y
// ----------------------------------------------------------------------------
// Common intrinsic (general implementation of intrinsic available on some platform)
// ----------------------------------------------------------------------------

2
Assets/TestScenes/HDTest/GlobalIlluminationTest/TestRealtime.cs


void Update () {
if (m_SceneSettings != null)
{
HDRISkyParameters skyParams = m_SceneSettings.GetComponent<HDRISkyParameters>();
HDRISkySettings skyParams = m_SceneSettings.GetComponent<HDRISkySettings>();
if (skyParams)
skyParams.rotation = (skyParams.rotation + Time.deltaTime * m_RotationSpeed) % 360.0f;
}

64
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/SceneSettingsManagementWindow.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public class SceneSettingsManagementWindow : EditorWindow
{
[MenuItem("HDRenderPipeline/Scene Settings Management")]
static void SceneSettingsManagement()
{
GetWindow<SceneSettingsManagementWindow>().Show();
}
static private string m_LastCreationPath = "Assets";
void CreateAsset<AssetType>(string assetName) where AssetType : ScriptableObject
{
string assetPath = EditorUtility.SaveFilePanel("Create new Asset", m_LastCreationPath, assetName, "asset");
if (!string.IsNullOrEmpty(assetPath))
{
assetPath = assetPath.Substring(assetPath.LastIndexOf("Assets"));
m_LastCreationPath = System.IO.Path.GetDirectoryName(assetPath);
var instance = CreateInstance<AssetType>();
AssetDatabase.CreateAsset(instance, assetPath);
}
}
void OnGUI()
{
// Keep it there temporarily until it's back to an "engine" setting in the HDRenderPipeline asset.
SubsurfaceScatteringSettings.overrideSettings = (SubsurfaceScatteringParameters)EditorGUILayout.ObjectField(new GUIContent("SSS Settings"), SubsurfaceScatteringSettings.overrideSettings, typeof(SubsurfaceScatteringParameters), false);
EditorGUILayout.Space();
if (GUILayout.Button("Create new Common Settings"))
{
CreateAsset<CommonSettings>("NewCommonSettings");
}
if (GUILayout.Button("Create new HDRI sky params"))
{
CreateAsset<HDRISkySettings>("NewHDRISkySettings");
}
if (GUILayout.Button("Create new Procedural sky params"))
{
CreateAsset<ProceduralSkySettings>("NewProceduralSkyParameters");
}
if (GUILayout.Button("Create new SSS params"))
{
CreateAsset<SubsurfaceScatteringParameters>("NewSssParameters");
}
EditorGUILayout.Space();
if (GUILayout.Button("Create Scene Settings"))
{
var manager = new GameObject();
manager.name = "Scene Settings";
manager.AddComponent<SceneSettings>();
}
}
}
}

44
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettings.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
public class SceneSettings : MonoBehaviour
{
public CommonSettings commonSettings
{
get { return m_CommonSettings; }
}
public SkySettings skySettings
{
get { return m_SkySettings; }
}
[SerializeField] private CommonSettings m_CommonSettings;
[SerializeField] private SkySettings m_SkySettings;
// Use this for initialization
void OnEnable()
{
SceneSettingsManager.instance.AddSceneSettings(this);
}
void OnDisable()
{
SceneSettingsManager.instance.RemoveSceneSettings(this);
}
void OnValidate()
{
// If the setting is already the one currently used we need to tell the manager to reapply it.
if(SceneSettingsManager.instance.GetCurrentSceneSetting())
{
SceneSettingsManager.instance.UpdateCurrentSceneSetting();
}
}
}
}

12
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettings.cs.meta


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

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class SceneSettingsManager
{
static private SceneSettingsManager s_Instance = null;
static public SceneSettingsManager instance
{
get
{
if(s_Instance == null)
s_Instance = new SceneSettingsManager();
return s_Instance;
}
}
private List<SceneSettings> m_SceneSettingsList = new List<SceneSettings>();
void OnEnable()
{
}
void OnDisable()
{
}
public SceneSettings GetCurrentSceneSetting()
{
if (m_SceneSettingsList.Count == 0)
return null;
else
return m_SceneSettingsList[m_SceneSettingsList.Count - 1];
}
// This can be needed in the editor in case the current setting is being changed. In this case we need to reapply it.
public void UpdateCurrentSceneSetting()
{
if (m_SceneSettingsList.Count != 0)
ApplySettings(GetCurrentSceneSetting());
}
public void AddSceneSettings(SceneSettings settings)
{
m_SceneSettingsList.Add(settings);
ApplySettings(settings);
}
public void RemoveSceneSettings(SceneSettings settings)
{
m_SceneSettingsList.Remove(settings);
// Always reapply the settings at the top of the list
// (this way if the setting being removed was the active one we switch to the next one)
ApplySettings(GetCurrentSceneSetting());
}
private void ApplySettings(SceneSettings settings)
{
if(settings)
{
if (settings.commonSettings != null)
CommonSettingsSingleton.overrideSettings = settings.commonSettings;
if (settings.skySettings != null)
SkySettingsSingleton.overrideSettings = settings.skySettings;
}
else
{
CommonSettingsSingleton.overrideSettings = null;
SkySettingsSingleton.overrideSettings = null;
}
}
}
}

12
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettingsManager.cs.meta


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

15
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
public class HDRISkySettings
: SkySettings
{
public Cubemap skyHDRI;
public override SkyRenderer GetRenderer()
{
return new HDRISkyRenderer(this);
}
}
}

17
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs


#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class SkySettingsSingleton : Singleton<SkySettingsSingleton>
{
private SkySettings settings { get; set; }
public static SkySettings overrideSettings
{
get { return instance.settings; }
set { instance.settings = value; }
}
}
}

45
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipeWindow.cs


using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public class HDRenderPipeWindow : EditorWindow
{
[MenuItem("HDRenderPipeline/Configure Overrides")]
static void ConfigureOverrides()
{
GetWindow<HDRenderPipeWindow>().Show();
}
void OnGUI()
{
CommonSettingsSingleton.overrideSettings = (CommonSettings)EditorGUILayout.ObjectField(new GUIContent("Common Settings"), CommonSettingsSingleton.overrideSettings, typeof(CommonSettings), false);
SkyParametersSingleton.overrideSettings = (SkyParameters)EditorGUILayout.ObjectField(new GUIContent("Sky Settings"), SkyParametersSingleton.overrideSettings, typeof(SkyParameters), false);
SubsurfaceScatteringSettings.overrideSettings = (SubsurfaceScatteringParameters)EditorGUILayout.ObjectField(new GUIContent("Subsurface Scattering Settings"), SubsurfaceScatteringSettings.overrideSettings, typeof(SubsurfaceScatteringParameters), false);
if (GUILayout.Button("Create new common settings"))
{
var instance = CreateInstance<CommonSettings>();
AssetDatabase.CreateAsset(instance, "Assets/NewCommonSettings.asset");
}
if (GUILayout.Button("Create new HDRI sky params"))
{
var instance = CreateInstance<HDRISkyParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewHDRISkyParameters.asset");
}
if (GUILayout.Button("Create new Procedural sky params"))
{
var instance = CreateInstance<ProceduralSkyParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewProceduralSkyParameters.asset");
}
if (GUILayout.Button("Create new SSS params"))
{
var instance = CreateInstance<SubsurfaceScatteringParameters>();
AssetDatabase.CreateAsset(instance, "Assets/NewSssParameters.asset");
}
}
}
}

52
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.hlsl


#ifndef UNITY_BLOOM
#define UNITY_BLOOM
// Downsample with a 4x4 box filter
float3 DownsampleFilter(TEXTURE2D_ARGS(tex, texSampler), float2 uv, float2 texelSize)
{
float4 d = texelSize.xyxy * float4(-1.0, -1.0, 1.0, 1.0);
float3 s;
s = SAMPLE_TEXTURE2D(tex, texSampler, uv + d.xy).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.zy).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.xw).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.zw).rgb;
return s * (1.0 / 4.0);
}
float3 UpsampleFilter(TEXTURE2D_ARGS(tex, texSampler), float2 uv, float2 texelSize, float sampleScale)
{
#if 0
// 4-tap bilinear upsampler
float4 d = texelSize.xyxy * float4(-1.0, -1.0, 1.0, 1.0) * (sampleScale * 0.5);
float3 s;
s = SAMPLE_TEXTURE2D(tex, texSampler, uv + d.xy).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.zy).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.xw).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.zw).rgb;
return s * (1.0 / 4.0);
#else
// 9-tap bilinear upsampler (tent filter)
float4 d = texelSize.xyxy * float4(1.0, 1.0, -1.0, 0.0) * sampleScale;
float3 s;
s = SAMPLE_TEXTURE2D(tex, texSampler, uv - d.xy).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv - d.wy).rgb * 2.0;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv - d.zy).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.zw).rgb * 2.0;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv).rgb * 4.0;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.xw).rgb * 2.0;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.zy).rgb;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.wy).rgb * 2.0;
s += SAMPLE_TEXTURE2D(tex, texSampler, uv + d.xy).rgb;
return s * (1.0 / 16.0);
#endif
}
#endif // UNITY_BLOOM

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.hlsl.meta


fileFormatVersion: 2
guid: 41784642d71cc4a46acbaa1c81d71109
timeCreated: 1486047545
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.shader.meta


fileFormatVersion: 2
guid: 0e58ecfc4bcd918478485f7b80aae431
timeCreated: 1486047504
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

171
Assets/ScriptableRenderPipeline/HDRenderPipeline/PostProcess/Resources/Bloom.shader


Shader "Hidden/HDRenderPipeline/Bloom"
{
Properties
{
_MainTex ("", 2D) = "" {}
_BaseTex ("", 2D) = "" {}
_AutoExposure ("", 2D) = "" {}
}
HLSLINCLUDE
#pragma target 4.5
#include "ShaderLibrary/Common.hlsl"
#include "HDRenderPipeline/ShaderVariables.hlsl"
#include "Bloom.hlsl"
TEXTURE2D(_MainTex);
SAMPLER2D(sampler_MainTex);
float4 _MainTex_TexelSize;
TEXTURE2D(_BaseTex);
SAMPLER2D(sampler_BaseTex);
float4 _BaseTex_TexelSize;
TEXTURE2D(_AutoExposure);
SAMPLER2D(sampler_AutoExposure);
float _Threshold;
float3 _Curve;
float _SampleScale;
struct Attributes
{
float3 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
};
struct VaryingsMultitex
{
float4 vertex : SV_POSITION;
float2 texcoordMain : TEXCOORD0;
float2 texcoordBase : TEXCOORD1;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.vertex = TransformWorldToHClip(input.vertex);
output.texcoord = input.texcoord.xy;
return output;
}
VaryingsMultitex VertMultitex(Attributes input)
{
VaryingsMultitex o;
o.vertex = TransformWorldToHClip(input.vertex);
o.texcoordMain = input.texcoord.xy;
o.texcoordBase = o.texcoordMain;
#if UNITY_UV_STARTS_AT_TOP
if (_BaseTex_TexelSize.y < 0.0)
o.texcoordMain.y = 1.0 - o.texcoordMain.y;
#endif
return o;
}
float4 FetchAutoExposed(TEXTURE2D_ARGS(tex, texSampler), float2 uv)
{
float autoExposure = 1.0;
#if EYE_ADAPTATION
autoExposure = SAMPLE_TEXTURE2D(_AutoExposure, sampler_AutoExposure, uv).r;
#endif
return SAMPLE_TEXTURE2D(tex, texSampler, uv) * autoExposure;
}
float4 FragPrefilter(Varyings i) : SV_Target
{
float2 uv = i.texcoord;
float4 s0 = min(65504.0, FetchAutoExposed(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), uv));
float3 m = s0.rgb;
// Pixel brightness
float br = max(m.r, max(m.g, m.r));
// Under-threshold part: quadratic curve
float rq = clamp(br - _Curve.x, 0.0, _Curve.y);
rq = _Curve.z * rq * rq;
// Combine and apply the brightness response curve.
m *= max(rq, br - _Threshold) / max(br, 1e-5);
return float4(m, 0.0);
}
float4 FragDownsample1(Varyings i) : SV_Target
{
return float4(DownsampleFilter(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy), 0.0);
}
float4 FragDownsample2(Varyings i) : SV_Target
{
return float4(DownsampleFilter(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoord, _MainTex_TexelSize.xy), 0.0);
}
float4 FragUpsample(VaryingsMultitex i) : SV_Target
{
float3 base = SAMPLE_TEXTURE2D(_BaseTex, sampler_BaseTex, i.texcoordBase).rgb;
float3 blur = UpsampleFilter(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), i.texcoordMain, _MainTex_TexelSize.xy, _SampleScale);
return float4(base + blur, 0.0);
}
ENDHLSL
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
HLSLPROGRAM
#pragma multi_compile __ EYE_ADAPTATION
#pragma vertex Vert
#pragma fragment FragPrefilter
ENDHLSL
}
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragDownsample1
ENDHLSL
}
Pass
{
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragDownsample2
ENDHLSL
}
Pass
{
HLSLPROGRAM
#pragma vertex VertMultitex
#pragma fragment FragUpsample
ENDHLSL
}
}
Fallback Off
}

15
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyParameters.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
public class HDRISkyParameters
: SkyParameters
{
public Cubemap skyHDRI;
public override SkyRenderer GetRenderer()
{
return new HDRISkyRenderer(this);
}
}
}

17
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyParametersSingleton.cs


#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class SkyParametersSingleton : Singleton<SkyParametersSingleton>
{
private SkyParameters settings { get; set; }
public static SkyParameters overrideSettings
{
get { return instance.settings; }
set { instance.settings = value; }
}
}
}

20
Assets/TestScenes/HDTest/CascadedShadowsTest/HDRISkyParameters_Cascaded.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: 59b6606ef2548734bb6d11b9d160bc7e, type: 3}
m_Name: HDRISkyParameters_Cascaded
m_EditorClassIdentifier:
rotation: 0
exposure: 0
multiplier: 1
resolution: 256
updateMode: 0
updatePeriod: 0
skyHDRI: {fileID: 8900000, guid: 9b513842339ef704ca63ef696691bc34, type: 3}

9
Assets/TestScenes/HDTest/CascadedShadowsTest/HDRISkyParameters_Cascaded.asset.meta


fileFormatVersion: 2
guid: e87251404948e274ab006302af9b80f8
timeCreated: 1486126252
licenseType: Pro
NativeFormatImporter:
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipeWindow.cs.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/SceneSettingsManagementWindow.cs.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyParameters.cs.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyParametersSingleton.cs.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyParameters.cs.meta → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs.meta

/Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyParameters.cs → /Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs

正在加载...
取消
保存