浏览代码

Push second draft

/feature-ReflectionProbeFit
Sebastien Lagarde 7 年前
当前提交
b8b6dd9b
共有 18 个文件被更改,包括 284 次插入567 次删除
  1. 14
      ScriptableRenderPipeline/HDRenderPipeline/Camera/HDCamera.cs
  2. 5
      ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
  3. 1
      ScriptableRenderPipeline/HDRenderPipeline/Debug/LightingDebug.cs
  4. 152
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  5. 5
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  6. 116
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  7. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs
  8. 29
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/GlobalLightLoopSettings.cs
  9. 170
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  10. 42
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoopSettings.cs
  11. 8
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
  12. 211
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/FrameSettings.cs
  13. 42
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/GlobalFrameSettings.cs
  14. 7
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs
  15. 6
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs
  16. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  17. 18
      ScriptableRenderPipeline/HDRenderPipeline/Debug/RenderingDebug.cs
  18. 11
      ScriptableRenderPipeline/HDRenderPipeline/Debug/RenderingDebug.cs.meta

14
ScriptableRenderPipeline/HDRenderPipeline/Camera/HDCamera.cs


// avoid one-frame jumps/hiccups with temporal effects (motion blur, TAA...)
public bool isFirstFrame { get; private set; }
public bool useForwardOnly { get; private set; }
public bool stereoEnabled { get; private set; }
public Vector4 invProjParam
{
// Ref: An Efficient Depth Linearization Method for Oblique View Frustums, Eq. 6.

Reset();
}
public void Update(PostProcessLayer postProcessLayer, GlobalRenderingSettings globalRenderingSettings, bool stereoActive)
public void Update(PostProcessLayer postProcessLayer)
{
// If TAA is enabled projMatrix will hold a jittered projection matrix. The original,
// non-jittered projection matrix can be accessed via nonJitteredProjMatrix.

frustumPlaneEquations[5] = new Vector4(-camera.transform.forward.x, -camera.transform.forward.y, -camera.transform.forward.z, Vector3.Dot(camera.transform.forward, relPos) + camera.farClipPlane);
m_LastFrameActive = Time.frameCount;
stereoEnabled = stereoActive && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
useForwardOnly = globalRenderingSettings.ShouldUseForwardRenderingOnly() || stereoEnabled;
}
public void Reset()

stereoEnabled = false;
useForwardOnly = false;
public static HDCamera Get(Camera camera, PostProcessLayer postProcessLayer, GlobalRenderingSettings globalRenderingSettings, bool stereoActive)
public static HDCamera Get(Camera camera, PostProcessLayer postProcessLayer)
{
HDCamera hdcam;

s_Cameras.Add(camera, hdcam);
}
hdcam.Update(postProcessLayer, globalRenderingSettings, stereoActive);
hdcam.Update(postProcessLayer);
return hdcam;
}

5
ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs


public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings();
public LightingDebugSettings lightingDebugSettings = new LightingDebugSettings();
public RenderingDebugSettings renderingDebugSettings = new RenderingDebugSettings();
public static GUIContent[] lightingFullScreenDebugStrings = null;
public static int[] lightingFullScreenDebugValues = null;

DebugMenuManager.instance.AddDebugItem<Attributes.DebugViewProperties>("Material", "Properties", () => materialDebugSettings.debugViewProperties, (value) => SetDebugViewProperties((Attributes.DebugViewProperties)value));
DebugMenuManager.instance.AddDebugItem<int>("Material", "GBuffer",() => materialDebugSettings.debugViewGBuffer, (value) => SetDebugViewGBuffer((int)value), DebugItemFlag.None, new DebugItemHandlerIntEnum(MaterialDebugSettings.debugViewMaterialGBufferStrings, MaterialDebugSettings.debugViewMaterialGBufferValues));
/*
*/
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, ShadowMapDebugMode>(kShadowDebugMode, () => lightingDebugSettings.shadowDebugMode, (value) => lightingDebugSettings.shadowDebugMode = (ShadowMapDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>(kShadowSelectionDebug, () => lightingDebugSettings.shadowDebugUseSelection, (value) => lightingDebugSettings.shadowDebugUseSelection = (bool)value, DebugItemFlag.EditorOnly);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, uint>(kShadowMapIndexDebug, () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value, DebugItemFlag.None, new DebugItemHandlerShadowIndex(1));

DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, LightLoop.TileClusterDebug>(kTileClusterDebug,() => lightingDebugSettings.tileClusterDebug, (value) => lightingDebugSettings.tileClusterDebug = (LightLoop.TileClusterDebug)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, LightLoop.TileClusterCategoryDebug>(kTileClusterCategoryDebug,() => lightingDebugSettings.tileClusterDebugByCategory, (value) => lightingDebugSettings.tileClusterDebugByCategory = (LightLoop.TileClusterCategoryDebug)value);
/*
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Opaque",() => renderingDebugSettings.displayOpaqueObjects, (value) => renderingDebugSettings.displayOpaqueObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Transparency",() => renderingDebugSettings.displayTransparentObjects, (value) => renderingDebugSettings.displayTransparentObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Enable Atmospheric Scattering",() => renderingDebugSettings.enableAtmosphericScattering, (value) => renderingDebugSettings.enableAtmosphericScattering = (bool)value);

DebugMenuManager.instance.AddDebugItem<int>("Rendering", kFullScreenDebugMode, () => (int)fullScreenDebugMode, (value) => fullScreenDebugMode = (FullScreenDebugMode)value, DebugItemFlag.None, new DebugItemHandlerIntEnum(DebugDisplaySettings.renderingFullScreenDebugStrings, DebugDisplaySettings.renderingFullScreenDebugValues));
*/
}
public void OnValidate()

1
ScriptableRenderPipeline/HDRenderPipeline/Debug/LightingDebug.cs


}
public DebugLightingMode debugLightingMode = DebugLightingMode.None;
public bool enableShadows = true;
public ShadowMapDebugMode shadowDebugMode = ShadowMapDebugMode.None;
public bool shadowDebugUseSelection = false;
public uint shadowMapIndex = 0;

152
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


SerializedProperty m_DefaultDiffuseMaterial;
SerializedProperty m_DefaultShader;
// LightLoop settings
SerializedProperty m_enableTileAndCluster;
SerializedProperty m_enableSplitLightEvaluation;
SerializedProperty m_enableComputeLightEvaluation;
SerializedProperty m_enableComputeLightVariants;
SerializedProperty m_enableComputeMaterialVariants;
SerializedProperty m_enableFptlForForwardOpaque;
SerializedProperty m_enableBigTilePrepass;
SerializedProperty m_enableAsyncCompute;
// Rendering Settings
SerializedProperty m_RenderingUseForwardOnly;
SerializedProperty m_RenderingUseDepthPrepass;
SerializedProperty m_RenderingUseDepthPrepassAlphaTestOnly;
// Shadow Settings
SerializedProperty m_ShadowAtlasWidth;
SerializedProperty m_ShadowAtlasHeight;
// Texture Settings
SerializedProperty m_SpotCookieSize;
SerializedProperty m_PointCookieSize;
SerializedProperty m_ReflectionCubemapSize;
SerializedProperty m_ReflectionCacheCompressed;
void InitializeProperties()
{
m_RenderPipelineResources = properties.Find("m_RenderPipelineResources");

// Tile settings
m_enableTileAndCluster = properties.Find(x => x.lightLoopSettings.enableTileAndCluster);
m_enableComputeLightEvaluation = properties.Find(x => x.lightLoopSettings.enableComputeLightEvaluation);
m_enableComputeLightVariants = properties.Find(x => x.lightLoopSettings.enableComputeLightVariants);
m_enableComputeMaterialVariants = properties.Find(x => x.lightLoopSettings.enableComputeMaterialVariants);
m_enableFptlForForwardOpaque = properties.Find(x => x.lightLoopSettings.enableFptlForForwardOpaque);
m_enableBigTilePrepass = properties.Find(x => x.lightLoopSettings.enableBigTilePrepass);
m_enableAsyncCompute = properties.Find(x => x.lightLoopSettings.enableAsyncCompute);
// Shadow settings
m_ShadowAtlasWidth = properties.Find(x => x.shadowInitParams.shadowAtlasWidth);
m_ShadowAtlasHeight = properties.Find(x => x.shadowInitParams.shadowAtlasHeight);
// Texture settings
m_SpotCookieSize = properties.Find(x => x.globalTextureSettings.spotCookieSize);
m_PointCookieSize = properties.Find(x => x.globalTextureSettings.pointCookieSize);
m_ReflectionCubemapSize = properties.Find(x => x.globalTextureSettings.reflectionCubemapSize);
m_ReflectionCacheCompressed = properties.Find(x => x.globalTextureSettings.reflectionCacheCompressed);
// Rendering settings
m_RenderingUseForwardOnly = properties.Find(x => x.globalRenderingSettings.useForwardRenderingOnly);
m_RenderingUseDepthPrepass = properties.Find(x => x.globalRenderingSettings.useDepthPrepassWithDeferredRendering);
m_RenderingUseDepthPrepassAlphaTestOnly = properties.Find(x => x.globalRenderingSettings.renderAlphaTestOnlyInDeferredPrepass);
// Subsurface Scattering Settings
m_SubsurfaceScatteringSettings = properties.Find(x => x.sssSettings);
}

method.Invoke(asset, new object[0]);
}
void TileSettingsUI(HDRenderPipelineAsset renderContext)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.tileLightLoopSettings);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_enableTileAndCluster, s_Styles.enableTileAndCluster);
if (m_enableTileAndCluster.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_enableBigTilePrepass, s_Styles.enableBigTilePrepass);
// Allow to disable cluster for foward opaque when in forward only (option have no effect when MSAA is enabled)
// Deferred opaque are always tiled
EditorGUILayout.PropertyField(m_enableFptlForForwardOpaque, s_Styles.enableFptlForForwardOpaque);
EditorGUILayout.PropertyField(m_enableComputeLightEvaluation, s_Styles.enableComputeLightEvaluation);
if (m_enableComputeLightEvaluation.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_enableComputeLightVariants, s_Styles.enableComputeLightVariants);
EditorGUILayout.PropertyField(m_enableComputeMaterialVariants, s_Styles.enableComputeMaterialVariants);
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(m_enableAsyncCompute, s_Styles.enableAsyncCompute);
}
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(renderContext); // Repaint
}
EditorGUI.indentLevel--;
}
void SssSettingsUI(HDRenderPipelineAsset renderContext)
{
EditorGUILayout.PropertyField(m_SubsurfaceScatteringSettings, s_Styles.sssSettings);

EditorGUI.indentLevel++;
SssSettingsUI(renderContext);
ShadowSettingsUI(renderContext);
TextureSettingsUI(renderContext);
RendereringSettingsUI(renderContext);
TileSettingsUI(renderContext);
void ShadowSettingsUI(HDRenderPipelineAsset renderContext)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.shadowSettings);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_ShadowAtlasWidth, s_Styles.shadowsAtlasWidth);
EditorGUILayout.PropertyField(m_ShadowAtlasHeight, s_Styles.shadowsAtlasHeight);
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(renderContext); // Repaint
}
EditorGUI.indentLevel--;
}
void RendereringSettingsUI(HDRenderPipelineAsset renderContext)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.renderingSettingsLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_RenderingUseForwardOnly, s_Styles.useForwardRenderingOnly);
if (!m_RenderingUseForwardOnly.boolValue) // If we are deferred
{
EditorGUILayout.PropertyField(m_RenderingUseDepthPrepass, s_Styles.useDepthPrepassWithDeferredRendering);
if(m_RenderingUseDepthPrepass.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_RenderingUseDepthPrepassAlphaTestOnly, s_Styles.renderAlphaTestOnlyInDeferredPrepass);
EditorGUI.indentLevel--;
}
}
EditorGUI.indentLevel--;
}
void TextureSettingsUI(HDRenderPipelineAsset renderContext)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_Styles.textureSettings);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_SpotCookieSize, s_Styles.spotCookieSize);
EditorGUILayout.PropertyField(m_PointCookieSize, s_Styles.pointCookieSize);
EditorGUILayout.PropertyField(m_ReflectionCubemapSize, s_Styles.reflectionCubemapSize);
// Commented ou until we have proper realtime BC6H compression
//EditorGUILayout.PropertyField(m_ReflectionCacheCompressed, s_Styles.reflectionCacheCompressed);
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(renderContext); // Repaint
}
EditorGUI.indentLevel--;
}
protected override void OnEnable()
{
base.OnEnable();

EditorGUILayout.LabelField(s_Styles.defaults, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_RenderPipelineResources, s_Styles.renderPipelineResources);
EditorGUILayout.PropertyField(m_RenderPipelineResources, s_Styles.renderPipelineResources);
EditorGUILayout.PropertyField(m_DefaultDiffuseMaterial, s_Styles.defaultDiffuseMaterial);
EditorGUILayout.PropertyField(m_DefaultShader, s_Styles.defaultShader);
EditorGUI.indentLevel--;

5
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


}
}
[MenuItem("Internal/HDRenderPipeline/Add \"Additional Camera Data\" (if not present)")]
[MenuItem("Internal/HDRenderPipeline/Add \"Additional Camera Data- Frame Settings\" (if not present)")]
static void AddAdditionalCameraData()
{
var cameras = UnityObject.FindObjectsOfType(typeof(Camera)) as Camera[];

// Do not add a component if there already is one.
if (camera.GetComponent<HDAdditionalCameraData>() == null)
camera.gameObject.AddComponent<HDAdditionalCameraData>();
if (camera.GetComponent<FrameSettings>() == null)
camera.gameObject.AddComponent<FrameSettings>();
}
}

116
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings();
static DebugDisplaySettings s_NeutralDebugDisplaySettings = new DebugDisplaySettings();
DebugDisplaySettings m_CurrentDebugDisplaySettings;
FrameSettings m_FrameSettings;
static FrameSettings s_NeutralFrameSettings = new FrameSettings();
FrameSettings m_debugSettings = new FrameSettings();
FrameSettings m_FrameSettings; // Init every frame
int m_DebugFullScreenTempRT;
bool m_FullScreenDebugPushed;

m_IBLFilterGGX = new IBLFilterGGX(asset.renderPipelineResources);
m_LightLoop.Build(asset.renderPipelineResources, asset.lightLoopSettings, asset.globalTextureSettings, asset.shadowInitParams, m_ShadowSettings, m_IBLFilterGGX);
m_LightLoop.Build(asset.renderPipelineResources, RenderPipelineSettings.GetGlobalFrameSettings().shadowInitParams, m_ShadowSettings, m_IBLFilterGGX);
m_SkyManager.Build(asset.renderPipelineResources, m_IBLFilterGGX);
m_SkyManager.skySettings = skySettingsToUse;

void RegisterDebug()
{
// These need to be Runtime Only because those values are held by the HDRenderPipeline asset so if user change them through the editor debug menu they might change the value in the asset without noticing it.
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Forward Only", () => m_Asset.globalRenderingSettings.useForwardRenderingOnly, (value) => m_Asset.globalRenderingSettings.useForwardRenderingOnly = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Deferred Depth Prepass", () => m_Asset.globalRenderingSettings.useDepthPrepassWithDeferredRendering, (value) => m_Asset.globalRenderingSettings.useDepthPrepassWithDeferredRendering = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Deferred Depth Prepass ATest Only", () => m_Asset.globalRenderingSettings.renderAlphaTestOnlyInDeferredPrepass, (value) => m_Asset.globalRenderingSettings.renderAlphaTestOnlyInDeferredPrepass = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Forward Only", () => m_debugSettings.renderSettings.enableForwardRenderingOnly, (value) => m_debugSettings.renderSettings.enableForwardRenderingOnly = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Deferred Depth Prepass", () => m_debugSettings.renderSettings.enableDepthPrepassWithDeferredRendering, (value) => m_debugSettings.renderSettings.enableDepthPrepassWithDeferredRendering = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Deferred Depth Prepass ATest Only", () => m_debugSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass, (value) => m_debugSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Tile/Cluster", () => m_Asset.lightLoopSettings.enableTileAndCluster, (value) => m_Asset.lightLoopSettings.enableTileAndCluster = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Big Tile", () => m_Asset.lightLoopSettings.enableBigTilePrepass, (value) => m_Asset.lightLoopSettings.enableBigTilePrepass = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Compute Lighting", () => m_Asset.lightLoopSettings.enableComputeLightEvaluation, (value) => m_Asset.lightLoopSettings.enableComputeLightEvaluation = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Light Classification", () => m_Asset.lightLoopSettings.enableComputeLightVariants, (value) => m_Asset.lightLoopSettings.enableComputeLightVariants = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Material Classification", () => m_Asset.lightLoopSettings.enableComputeMaterialVariants, (value) => m_Asset.lightLoopSettings.enableComputeMaterialVariants = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Async Compute", () => m_Asset.lightLoopSettings.enableAsyncCompute, (value) => m_Asset.lightLoopSettings.enableAsyncCompute = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Tile/Cluster", () => m_debugSettings.lightLoopSettings.enableTileAndCluster, (value) => m_debugSettings.lightLoopSettings.enableTileAndCluster = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Big Tile", () => m_debugSettings.lightLoopSettings.enableBigTilePrepass, (value) => m_debugSettings.lightLoopSettings.enableBigTilePrepass = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Compute Lighting", () => m_debugSettings.lightLoopSettings.enableComputeLightEvaluation, (value) => m_debugSettings.lightLoopSettings.enableComputeLightEvaluation = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Light Classification", () => m_debugSettings.lightLoopSettings.enableComputeLightVariants, (value) => m_debugSettings.lightLoopSettings.enableComputeLightVariants = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Material Classification", () => m_debugSettings.lightLoopSettings.enableComputeMaterialVariants, (value) => m_debugSettings.lightLoopSettings.enableComputeMaterialVariants = (bool)value, DebugItemFlag.RuntimeOnly);
DebugMenuManager.instance.AddDebugItem<bool>("HDRP", "Enable Async Compute", () => m_debugSettings.renderSettings.enableAsyncCompute, (value) => m_debugSettings.renderSettings.enableAsyncCompute = (bool)value, DebugItemFlag.RuntimeOnly);
}
void InitializeDebugMaterials()

cmd.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 0);
}
m_SSSBufferManager.PushGlobalParams(cmd, sssParameters, m_CurrentDebugDisplaySettings);
m_SSSBufferManager.PushGlobalParams(cmd, sssParameters, m_FrameSettings);
}
}

m_FrameCount = Time.frameCount;
}
var stereoActive = UnityEngine.XR.XRSettings.isDeviceActive && m_DebugDisplaySettings.renderingDebugSettings.allowStereo;
var cameraFrameSettings = camera.GetComponent<FrameSettings>();
m_FrameSettings = FrameSettings.InitializeFrameSettings(RenderPipelineSettings.GetGlobalFrameSettings(), cameraFrameSettings, null);
if (camera == null)
continue;
// First, get aggregate of frame settings base on global settings, camera frame settings and debug settings
var cameraFrameSettings = camera.GetComponent<FrameSettings>(); // This will create Default FrameSettings if it doesn't exist
if (cameraFrameSettings == null)
{
// Provide a default one
cameraFrameSettings = s_NeutralFrameSettings;
}
m_FrameSettings = FrameSettings.InitializeFrameSettings(camera, RenderPipelineSettings.GetGlobalFrameSettings(), cameraFrameSettings, null);
using (new ProfilingSample(cmd, "HDRenderPipeline::Render", GetSampler(CustomSamplerId.HDRenderPipelineRender)))
{
foreach (var material in m_MaterialList)
material.RenderInit(cmd);
// Init material if needed
// TODO: this should be move outside of the camera loop but we have no command buffer, ask details to Tim or Julien to do this
if (!m_IBLFilterGGX.IsInitialized())
m_IBLFilterGGX.Initialize(cmd);
foreach (var material in m_MaterialList)
material.RenderInit(cmd);
using (new ProfilingSample(cmd, "HDRenderPipeline::Render", GetSampler(CustomSamplerId.HDRenderPipelineRender)))
{
m_LightLoop.NewFrame();
if (camera == null)
{
renderContext.Submit();
continue;
}
m_LightLoop.NewFrame(m_FrameSettings);
// If we render a reflection view or a preview we should not display any debug information
// This need to be call before ApplyDebugDisplaySettings()

ApplyDebugDisplaySettings(cmd);
UpdateCommonSettings();
if (!m_IBLFilterGGX.IsInitialized())
m_IBLFilterGGX.Initialize(cmd);
ScriptableCullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, out cullingParams))

}
var postProcessLayer = camera.GetComponent<PostProcessLayer>();
var hdCamera = HDCamera.Get(camera, postProcessLayer, m_Asset.globalRenderingSettings, stereoActive);
m_LightLoop.UpdateRenderingPathState(hdCamera.useForwardOnly);
var hdCamera = HDCamera.Get(camera, postProcessLayer);
Resize(camera);

RenderSSAO(cmd, camera, renderContext, postProcessLayer);
}
bool enableAsyncCompute = m_LightLoop.IsAsyncEnabled();
if (enableAsyncCompute)
if (m_FrameSettings.renderSettings.enableAsyncCompute)
{
GPUFence startFence = cmd.CreateGPUFence();
renderContext.ExecuteCommandBuffer(cmd);

}
}
if (enableAsyncCompute)
if (m_FrameSettings.renderSettings.enableAsyncCompute)
{
m_LightLoop.BuildGPULightListAsyncEnd(camera, cmd, buildGPULightListsCompleteFence);
}

RenderForwardError(m_CullResults, camera, renderContext, cmd, ForwardPass.Opaque);
// SSS pass here handle both SSS material from deferred and forward
m_SSSBufferManager.SubsurfaceScatteringPass(hdCamera, cmd, sssSettings, m_CurrentDebugDisplaySettings,
m_SSSBufferManager.SubsurfaceScatteringPass(hdCamera, cmd, sssSettings, m_FrameSettings,
m_CameraColorBufferRT, m_CameraSssDiffuseLightingBufferRT, m_CameraDepthStencilBufferRT, GetDepthTexture());
RenderSky(hdCamera, cmd);

RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
{
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.displayOpaqueObjects)
if (!m_FrameSettings.renderSettings.enableOpaqueObjects)
return;
// This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders

Material overrideMaterial = null
)
{
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.displayTransparentObjects)
if (!m_FrameSettings.renderSettings.enableTransparentObjects)
return;
// This is done here because DrawRenderers API lives outside command buffers so we need to make call this before doing any DrawRenders

void AccumulateDistortion(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableDistortion)
if (!m_FrameSettings.renderSettings.enableDistortion)
return;
using (new ProfilingSample(cmd, "Distortion", GetSampler(CustomSamplerId.Distortion)))

// It must also have a "DepthForwardOnly" and no "DepthOnly" pass as forward material (either deferred or forward only rendering) have always a depth pass.
// In case of forward only rendering we have a depth prepass. In case of deferred renderer, it is optional
bool addFullDepthPrepass = hdCamera.useForwardOnly || m_Asset.globalRenderingSettings.useDepthPrepassWithDeferredRendering;
bool addAlphaTestedOnly = !hdCamera.useForwardOnly && m_Asset.globalRenderingSettings.useDepthPrepassWithDeferredRendering && m_Asset.globalRenderingSettings.renderAlphaTestOnlyInDeferredPrepass;
bool addFullDepthPrepass = m_FrameSettings.renderSettings.enableForwardRenderingOnly || m_FrameSettings.renderSettings.enableDepthPrepassWithDeferredRendering;
bool addAlphaTestedOnly = !m_FrameSettings.renderSettings.enableForwardRenderingOnly && m_FrameSettings.renderSettings.enableDepthPrepassWithDeferredRendering && m_FrameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass;
var camera = hdCamera.camera;

// during Gbuffer pass. This is handled in the shader and the depth test (equal and no depth write) is done here.
void RenderGBuffer(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (hdCamera.useForwardOnly)
if (m_FrameSettings.renderSettings.enableForwardRenderingOnly)
return;
var camera = hdCamera.camera;

}
else
{
if (m_Asset.globalRenderingSettings.useDepthPrepassWithDeferredRendering)
if (m_FrameSettings.renderSettings.enableDepthPrepassWithDeferredRendering)
RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, rangeOpaqueNoAlphaTest, m_Asset.globalRenderingSettings.renderAlphaTestOnlyInDeferredPrepass ? m_DepthStateOpaque : m_DepthStateOpaqueWithPrepass);
RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, rangeOpaqueNoAlphaTest, m_FrameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass ? m_DepthStateOpaque : m_DepthStateOpaqueWithPrepass);
// but for opaque alpha tested object we use a depth equal and no depth write. And we rely on the shader pass GbufferWithDepthPrepass
RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferWithPrepassName, m_currentRendererConfigurationBakedLighting, rangeOpaqueAlphaTest, m_DepthStateOpaqueWithPrepass);
}

{
using (new ProfilingSample(cmd, "DisplayDebug ViewMaterial", GetSampler(CustomSamplerId.DisplayDebugViewMaterial)))
{
if (m_CurrentDebugDisplaySettings.materialDebugSettings.IsDebugGBufferEnabled() && !m_Asset.globalRenderingSettings.ShouldUseForwardRenderingOnly())
if (m_CurrentDebugDisplaySettings.materialDebugSettings.IsDebugGBufferEnabled() && !m_FrameSettings.renderSettings.enableForwardRenderingOnly)
{
using (new ProfilingSample(cmd, "DebugViewMaterialGBuffer", GetSampler(CustomSamplerId.DebugViewMaterialGBuffer)))
{

void RenderDeferredLighting(HDCamera hdCamera, CommandBuffer cmd)
{
if (hdCamera.useForwardOnly)
if (m_FrameSettings.renderSettings.enableForwardRenderingOnly)
return;
m_MRTCache2[0] = m_CameraColorBufferRT;

var options = new LightLoop.LightingPassOptions();
if (m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission)
if (m_FrameSettings.lightingSettings.enableSSSAndTransmission)
{
// Output split lighting for materials asking for it (masked in the stencil buffer)
options.outputSplitLighting = true;

void RenderSky(HDCamera hdCamera, CommandBuffer cmd)
{
m_SkyManager.RenderSky(hdCamera, m_LightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, cmd, m_DebugDisplaySettings);
m_SkyManager.RenderSky(hdCamera, m_LightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, cmd, m_FrameSettings);
m_SkyManager.RenderOpaqueAtmosphericScattering(cmd);
}

if (pass == ForwardPass.Opaque)
{
// In case of forward SSS we will bind all the required target. It is up to the shader to write into it or not.
if (m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission)
if (m_FrameSettings.lightingSettings.enableSSSAndTransmission)
{
RenderTargetIdentifier[] m_MRTWithSSS = new RenderTargetIdentifier[2 + m_SSSBufferManager.sssBufferCount];
m_MRTWithSSS[0] = m_CameraColorBufferRT; // Store the specular color

m_ForwardAndForwardOnlyPassNames[1] = HDShaderPassNames.s_ForwardName;
}
var passNames = hdCamera.useForwardOnly ? m_ForwardAndForwardOnlyPassNames : m_ForwardOnlyPassNames;
var passNames = m_FrameSettings.renderSettings.enableForwardRenderingOnly ? m_ForwardAndForwardOnlyPassNames : m_ForwardOnlyPassNames;
// Forward opaque material always have a prepass (whether or not we use deferred, whether or not there is option like alpha test only) so we pass the right depth state here.
RenderOpaqueRenderList(cullResults, camera, renderContext, cmd, passNames, m_currentRendererConfigurationBakedLighting, null, m_DepthStateOpaqueWithPrepass);
}

void RenderGaussianPyramidColor(Camera camera, CommandBuffer cmd, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
{
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableGaussianPyramid)
return;
using (new ProfilingSample(cmd, "Gaussian Pyramid Color", GetSampler(CustomSamplerId.GaussianPyramidColor)))
{
int w = camera.pixelWidth;

void RenderPyramidDepth(Camera camera, CommandBuffer cmd, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)
{
if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableGaussianPyramid)
return;
using (new ProfilingSample(cmd, "Pyramid Depth", GetSampler(CustomSamplerId.PyramidDepth)))
{
int w = camera.pixelWidth;

public void ApplyDebugDisplaySettings(CommandBuffer cmd)
{
m_ShadowSettings.enabled = m_CurrentDebugDisplaySettings.lightingDebugSettings.enableShadows;
m_ShadowSettings.enabled = m_FrameSettings.lightingSettings.enableShadow;
var lightingDebugSettings = m_CurrentDebugDisplaySettings.lightingDebugSettings;
var debugAlbedo = new Vector4(lightingDebugSettings.debugLightingAlbedo.r, lightingDebugSettings.debugLightingAlbedo.g, lightingDebugSettings.debugLightingAlbedo.b, 0.0f);

cmd.GetTemporaryRT(m_DepthPyramidBuffer, m_DepthPyramidBufferDesc, FilterMode.Trilinear);
// End
if (!hdCamera.useForwardOnly)
if (!m_FrameSettings.renderSettings.enableForwardRenderingOnly)
{
m_GbufferManager.InitGBuffers(w, h, m_DeferredMaterial, enableBakeShadowMask, cmd);
m_SSSBufferManager.InitSSSBuffersFromGBuffer(w, h, m_GbufferManager, cmd);

}
// Clear GBuffers
if (!hdCamera.useForwardOnly)
if (!m_FrameSettings.renderSettings.enableForwardRenderingOnly)
{
using (new ProfilingSample(cmd, "Clear GBuffer", GetSampler(CustomSamplerId.ClearGBuffer)))
{

10
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs


set { m_RenderPipelineResources = value; }
}
// NOTE: All those properties are public because of how HDRenderPipelineInspector retrieves those properties via serialization/reflection
// Doing it this way allows to change parameters name and still retrieve correct serialized values
// Global Renderer Settings
public GlobalRenderingSettings globalRenderingSettings = new GlobalRenderingSettings();
public GlobalTextureSettings globalTextureSettings = new GlobalTextureSettings();
public LightLoopSettings lightLoopSettings = new LightLoopSettings();
// Shadow Settings
public ShadowInitParameters shadowInitParams = new ShadowInitParameters();
// Default Material / Shader
[SerializeField]

29
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/GlobalLightLoopSettings.cs


// There is a dedicated RenderRenderPipelineSettings for each platform
[Serializable]
public struct GlobalLightLoopSettings
public class GlobalLightLoopSettings
public int spotCookieSize;
public int cookieTexArraySize;
public int pointCookieSize;
public int cubeCookieTexArraySize;
public int spotCookieSize = 128;
public int cookieTexArraySize = 16;
public int pointCookieSize = 512;
public int cubeCookieTexArraySize = 16;
public int reflectionProbeCacheSize;
public int reflectionCubemapSize;
public bool reflectionCacheCompressed;
public GlobalLightLoopSettings()
{
spotCookieSize = 128;
cookieTexArraySize = 16;
pointCookieSize = 512;
cubeCookieTexArraySize = 16;
reflectionProbeCacheSize = 128;
reflectionCubemapSize = 128;
reflectionCacheCompressed = false;
}
public int reflectionProbeCacheSize = 128;
public int reflectionCubemapSize = 128;
public bool reflectionCacheCompressed = false;
}
}

170
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


TextureCache2D m_CookieTexArray;
TextureCacheCubemap m_CubeCookieTexArray;
FrameSettings m_FrameSettings = new FrameSettings();
public class LightList
{
public List<DirectionalLightData> directionalLights;

static int s_GenListPerBigTileKernel;
const bool k_UseDepthBuffer = true; // only has an impact when EnableClustered is true (requires a depth-prepass)
const bool k_UseAsyncCompute = true; // should not use on mobile
const int k_Log2NumClusters = 6; // accepted range is from 0 to 6. NumClusters is 1<<g_iLog2NumClusters
const float k_ClustLogBase = 1.02f; // each slice 2% bigger than the previous

static ComputeBuffer s_GlobalLightListAtomic = null;
// clustered light list specific buffers and data end
bool m_isForwardRenderingOnly;
bool m_isFptlEnabled;
bool m_isFptlEnabledForForwardOpaque;
FrameSettings m_FrameSettings = null;
RenderPipelineResources m_Resources = null;
// Following is an array of material of size eight for all combination of keyword: OUTPUT_SPLIT_LIGHTING - LIGHTLOOP_TILE_PASS - SHADOWS_SHADOWMASK - USE_FPTL_LIGHTLIST/USE_CLUSTERED_LIGHTLIST - DEBUG_DISPLAY
Material[] m_deferredLightingMaterial;

}
}
int GetNumTileFtplX(Camera camera)
{
return (camera.pixelWidth + (LightDefinitions.s_TileSizeFptl - 1)) / LightDefinitions.s_TileSizeFptl;

public bool GetFeatureVariantsEnabled()
{
return !m_isForwardRenderingOnly && m_isFptlEnabled && m_LightLoopSettings.enableComputeLightEvaluation &&
(m_LightLoopSettings.enableComputeLightVariants || m_LightLoopSettings.enableComputeMaterialVariants);
return !m_FrameSettings.renderSettings.enableForwardRenderingOnly && m_FrameSettings.lightLoopSettings.isFptlEnabled && m_FrameSettings.lightLoopSettings.enableComputeLightEvaluation &&
(m_FrameSettings.lightLoopSettings.enableComputeLightVariants || m_FrameSettings.lightLoopSettings.enableComputeMaterialVariants);
LightLoopSettings m_LightLoopSettings = null;
RenderPipelineResources m_Resources = null;
public LightLoop()
{}

}
public void Build( RenderPipelineResources renderPipelineResources,
LightLoopSettings lightLoopSettings,
GlobalTextureSettings textureSettings,
m_LightLoopSettings = lightLoopSettings;
m_lightList = new LightList();
m_lightList.Allocate();

s_EnvLightDatas = new ComputeBuffer(k_MaxEnvLightsOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));
s_shadowDatas = new ComputeBuffer(k_MaxCascadeCount + k_MaxShadowOnScreen, System.Runtime.InteropServices.Marshal.SizeOf(typeof(ShadowData)));
GlobalLightLoopSettings gLightLoopSettings = RenderPipelineSettings.GetGlobalFrameSettings().lightLoopSettings;
m_CookieTexArray.AllocTextureArray(m_CookieTexArraySize, textureSettings.spotCookieSize, textureSettings.spotCookieSize, TextureFormat.RGBA32, true);
m_CookieTexArray.AllocTextureArray(gLightLoopSettings.cookieTexArraySize, gLightLoopSettings.spotCookieSize, gLightLoopSettings.spotCookieSize, TextureFormat.RGBA32, true);
m_CubeCookieTexArray.AllocTextureArray(m_CubeCookieTexArraySize, textureSettings.pointCookieSize, TextureFormat.RGBA32, true);
m_CubeCookieTexArray.AllocTextureArray(gLightLoopSettings.cubeCookieTexArraySize, gLightLoopSettings.pointCookieSize, TextureFormat.RGBA32, true);
TextureFormat probeCacheFormat = textureSettings.reflectionCacheCompressed ? TextureFormat.BC6H : TextureFormat.RGBAHalf;
m_ReflectionProbeCache = new ReflectionProbeCache(iblFilterGGX, m_ReflectionProbeCacheSize, textureSettings.reflectionCubemapSize, probeCacheFormat, true);
TextureFormat probeCacheFormat = gLightLoopSettings.reflectionCacheCompressed ? TextureFormat.BC6H : TextureFormat.RGBAHalf;
m_ReflectionProbeCache = new ReflectionProbeCache(iblFilterGGX, gLightLoopSettings.reflectionProbeCacheSize, gLightLoopSettings.reflectionCubemapSize, probeCacheFormat, true);
s_GenAABBKernel = buildScreenAABBShader.FindKernel("ScreenBoundsAABB");

// Cluster
{
var kernelName = m_LightLoopSettings.enableBigTilePrepass ? (k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile") : (k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT");
s_GenListPerVoxelKernel = buildPerVoxelLightListShader.FindKernel(kernelName);
if (m_LightLoopSettings.enableBigTilePrepass)
{
s_GenListPerBigTileKernel = buildPerBigTileLightListShader.FindKernel("BigTileLightListGen");
}
s_GenListPerBigTileKernel = buildPerBigTileLightListShader.FindKernel("BigTileLightListGen");
s_BuildDispatchIndirectKernel = buildDispatchIndirectShader.FindKernel("BuildDispatchIndirect");
s_ClearDispatchIndirectKernel = clearDispatchIndirectShader.FindKernel("ClearDispatchIndirect");

CoreUtils.Destroy(m_DebugViewTilesMaterial);
}
public void NewFrame()
public void NewFrame(FrameSettings frameSettings)
m_FrameSettings = frameSettings;
// Cluster
{
var kernelName = m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? (k_UseDepthBuffer ? "TileLightListGen_DepthRT_SrcBigTile" : "TileLightListGen_NoDepthRT_SrcBigTile") : (k_UseDepthBuffer ? "TileLightListGen_DepthRT" : "TileLightListGen_NoDepthRT");
s_GenListPerVoxelKernel = buildPerVoxelLightListShader.FindKernel(kernelName);
}
if (GetFeatureVariantsEnabled())
{
s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? "TileLightListGen_SrcBigTile_FeatureFlags" : "TileLightListGen_FeatureFlags");
}
else
{
s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen");
}
m_CookieTexArray.NewFrame();
m_CubeCookieTexArray.NewFrame();
m_ReflectionProbeCache.NewFrame();

{
return s_LightList == null || s_TileList == null || s_TileFeatureFlags == null ||
(s_BigTileLightList == null && m_LightLoopSettings.enableBigTilePrepass) ||
(s_BigTileLightList == null && m_FrameSettings.lightLoopSettings.enableBigTilePrepass) ||
(s_PerVoxelLightLists == null);
}

}
}
if (m_LightLoopSettings.enableBigTilePrepass)
if (m_FrameSettings.lightLoopSettings.enableBigTilePrepass)
{
var nrBigTilesX = (width + 63) / 64;
var nrBigTilesY = (height + 63) / 64;

{
var directionalLightData = new DirectionalLightData();
float diffuseDimmer = m_LightingSettings.diffuseGlobalDimmer * additionalData.lightDimmer;
float specularDimmer = m_LightingSettings.specularGlobalDimmer * additionalData.lightDimmer;
float diffuseDimmer = m_FrameSettings.lightingSettings.diffuseGlobalDimmer * additionalData.lightDimmer;
float specularDimmer = m_FrameSettings.lightingSettings.specularGlobalDimmer * additionalData.lightDimmer;
if (diffuseDimmer <= 0.0f && specularDimmer <= 0.0f)
return false;

float distanceFade = ComputeLinearDistanceFade(distanceToCamera, additionalLightData.fadeDistance);
float lightScale = additionalLightData.lightDimmer * distanceFade;
lightData.diffuseScale = additionalLightData.affectDiffuse ? lightScale * m_LightingSettings.diffuseGlobalDimmer : 0.0f;
lightData.specularScale = additionalLightData.affectSpecular ? lightScale * m_LightingSettings.specularGlobalDimmer : 0.0f;
lightData.diffuseScale = additionalLightData.affectDiffuse ? lightScale * m_FrameSettings.lightingSettings.diffuseGlobalDimmer : 0.0f;
lightData.specularScale = additionalLightData.affectSpecular ? lightScale * m_FrameSettings.lightingSettings.specularGlobalDimmer : 0.0f;
if (lightData.diffuseScale <= 0.0f && lightData.specularScale <= 0.0f)
return false;

light.bakingOutput.occlusionMaskChannel != -1; // We need to have an occlusion mask channel assign, else we have no shadow mask
}
public void UpdateRenderingPathState(bool useForwardRenderingOnly)
{
// Deferred opaque are always using Fptl. Forward opaque can use Fptl or Cluster, transparent use cluster.
// When MSAA is enabled we disable Fptl as it become expensive compare to cluster
// In HD, MSAA is only supported for forward only rendering, no MSAA in deferred mode (for code complexity reasons)
// If Deferred, enable Fptl. If we are forward renderer only and not using Fptl for forward opaque, disable Fptl
m_isForwardRenderingOnly = useForwardRenderingOnly;
m_isFptlEnabled = !m_isForwardRenderingOnly || m_LightLoopSettings.enableFptlForForwardOpaque; // TODO: Disable if MSAA
m_isFptlEnabledForForwardOpaque = m_LightLoopSettings.enableFptlForForwardOpaque; // TODO: Disable if MSAA
if (GetFeatureVariantsEnabled())
{
s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(m_LightLoopSettings.enableBigTilePrepass ? "TileLightListGen_SrcBigTile_FeatureFlags" : "TileLightListGen_FeatureFlags");
}
else
{
s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(m_LightLoopSettings.enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen");
}
}
// Return true if BakedShadowMask are enabled
public bool PrepareLightsForGPU(CommandBuffer cmd, ShadowSettings shadowSettings, CullResults cullResults, Camera camera)
{

{
m_ShadowIndices.Add(shadowRequests[i], shadowDataIndices[i]);
}
}
float oldSpecularGlobalDimmer = m_LightingSettings.specularGlobalDimmer;
// Change some parameters in case of "special" rendering (can be preview, reflection, etc.)
if (camera.cameraType == CameraType.Reflection)
{
m_LightingSettings.specularGlobalDimmer = 0.0f;
}
// 1. Count the number of lights and sort all lights by category, type and volume - This is required for the fptl/cluster shader code

if (GetEnvLightData(cmd, camera, probe))
{
GetEnvLightVolumeDataAndBound(probe, lightVolumeType, worldToView);
GetEnvLightVolumeDataAndBound(probe, lightVolumeType, worldToView);
// We make the light position camera-relative as late as possible in order
// to allow the preceding code to work with the absolute world space coordinates.
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Caution: 'EnvLightData.positionWS' is camera-relative after this point.
int n = m_lightList.envLights.Count;
EnvLightData envLightData = m_lightList.envLights[n - 1];
envLightData.positionWS -= camPosWS;
m_lightList.envLights[n - 1] = envLightData;
// We make the light position camera-relative as late as possible in order
// to allow the preceding code to work with the absolute world space coordinates.
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Caution: 'EnvLightData.positionWS' is camera-relative after this point.
int n = m_lightList.envLights.Count;
EnvLightData envLightData = m_lightList.envLights[n - 1];
envLightData.positionWS -= camPosWS;
m_lightList.envLights[n - 1] = envLightData;
}
}
// Restore values after "special rendering"
m_LightingSettings.specularGlobalDimmer = oldSpecularGlobalDimmer;
}
m_lightCount = m_lightList.lights.Count + m_lightList.envLights.Count;

cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, HDShaderIDs.g_vLayeredLightList, s_PerVoxelLightLists);
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, HDShaderIDs.g_LayeredOffset, s_PerVoxelOffset);
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, HDShaderIDs.g_LayeredSingleIdxBuffer, s_GlobalLightListAtomic);
if (m_LightLoopSettings.enableBigTilePrepass)
if (m_FrameSettings.lightLoopSettings.enableBigTilePrepass)
cmd.SetComputeBufferParam(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, HDShaderIDs.g_vBigTileLightList, s_BigTileLightList);
if (k_UseDepthBuffer)

var numTilesX = GetNumTileClusteredX(camera);
var numTilesY = GetNumTileClusteredY(camera);
cmd.DispatchCompute(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, numTilesX, numTilesY, 1);
}
public bool IsAsyncEnabled()
{
return m_LightLoopSettings.enableAsyncCompute;
}
public void BuildGPULightListsCommon(Camera camera, CommandBuffer cmd, RenderTargetIdentifier cameraDepthBufferRT, RenderTargetIdentifier stencilTextureRT)

}
// enable coarse 2D pass on 64x64 tiles (used for both fptl and clustered).
if (m_LightLoopSettings.enableBigTilePrepass)
if (m_FrameSettings.lightLoopSettings.enableBigTilePrepass)
{
cmd.SetComputeIntParam(buildPerBigTileLightListShader, HDShaderIDs.g_isOrthographic, isOrthographic ? 1 : 0);
cmd.SetComputeIntParams(buildPerBigTileLightListShader, HDShaderIDs.g_viDimensions, w, h);

bool enableFeatureVariants = GetFeatureVariantsEnabled();
// optimized for opaques only
if (m_isFptlEnabled)
if (m_FrameSettings.lightLoopSettings.isFptlEnabled)
{
cmd.SetComputeIntParam(buildPerTileLightListShader, HDShaderIDs.g_isOrthographic, isOrthographic ? 1 : 0);
cmd.SetComputeIntParams(buildPerTileLightListShader, HDShaderIDs.g_viDimensions, w, h);

cmd.SetComputeMatrixParam(buildPerTileLightListShader, HDShaderIDs.g_mInvScrProjection, invProjscr);
cmd.SetComputeTextureParam(buildPerTileLightListShader, s_GenListPerTileKernel, HDShaderIDs.g_depth_tex, cameraDepthBufferRT);
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, HDShaderIDs.g_vLightList, s_LightList);
if (m_LightLoopSettings.enableBigTilePrepass)
if (m_FrameSettings.lightLoopSettings.enableBigTilePrepass)
cmd.SetComputeBufferParam(buildPerTileLightListShader, s_GenListPerTileKernel, HDShaderIDs.g_vBigTileLightList, s_BigTileLightList);
if (enableFeatureVariants)

{
baseFeatureFlags |= (uint)LightFeatureFlags.Sky;
}
if (!m_LightLoopSettings.enableComputeMaterialVariants)
if (!m_FrameSettings.lightLoopSettings.enableComputeMaterialVariants)
{
baseFeatureFlags |= LightDefinitions.s_MaterialFeatureMaskFlags;
}

if (enableFeatureVariants)
{
// material classification
if (m_LightLoopSettings.enableComputeMaterialVariants)
if (m_FrameSettings.lightLoopSettings.enableComputeMaterialVariants)
if (!m_LightLoopSettings.enableComputeLightVariants)
if (!m_FrameSettings.lightLoopSettings.enableComputeLightVariants)
{
buildMaterialFlagsKernel = s_BuildMaterialFlagsWriteKernel;
baseFeatureFlags |= LightDefinitions.s_LightFeatureMaskFlags;

s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes);
}
void PushGlobalParams(Camera camera, CommandBuffer cmd)
void PushGlobalParams(Camera camera, CommandBuffer cmd)
{
using (new ProfilingSample(cmd, "Push Global Parameters", HDRenderPipeline.GetSampler(CustomSamplerId.TPPushGlobalParameters)))
{

cmd.SetGlobalInt(HDShaderIDs._NumTileClusteredX, GetNumTileClusteredX(camera));
cmd.SetGlobalInt(HDShaderIDs._NumTileClusteredY, GetNumTileClusteredY(camera));
if (m_LightLoopSettings.enableBigTilePrepass)
if (m_FrameSettings.lightLoopSettings.enableBigTilePrepass)
{
{
cmd.SetGlobalFloat(HDShaderIDs.g_fClustScale, m_ClustScale);
cmd.SetGlobalFloat(HDShaderIDs.g_fClustBase, k_ClustLogBase);
cmd.SetGlobalFloat(HDShaderIDs.g_fNearPlane, camera.nearClipPlane);

cmd.SetGlobalBuffer(HDShaderIDs.g_vLayeredOffsetsBuffer, s_PerVoxelOffset);
if (k_UseDepthBuffer)
{
if (k_UseDepthBuffer)
{
}
}
}
}
}
}

}
}
public void RenderDeferredLighting( HDCamera hdCamera, CommandBuffer cmd,
DebugDisplaySettings debugDisplaySettings,
public void RenderDeferredLighting( HDCamera hdCamera, CommandBuffer cmd, DebugDisplaySettings debugDisplaySettings,
if (m_LightLoopSettings.enableTileAndCluster && m_LightLoopSettings.enableComputeLightEvaluation && options.outputSplitLighting)
if (m_FrameSettings.lightLoopSettings.enableTileAndCluster && m_FrameSettings.lightLoopSettings.enableComputeLightEvaluation && options.outputSplitLighting)
{
// The CS is always in the MRT mode. Do not execute the same shader twice.
return;

Texture skyTexture = Shader.GetGlobalTexture(HDShaderIDs._SkyTexture);
float skyTextureMipCount = Shader.GetGlobalFloat(HDShaderIDs._SkyTextureMipCount);
string sLabel = m_LightLoopSettings.enableTileAndCluster ?
string sLabel = m_FrameSettings.lightLoopSettings.enableTileAndCluster ?
(options.outputSplitLighting ? tilePassMRTName : tilePassName) :
(options.outputSplitLighting ? SinglePassMRTName : singlePassName);

// Compute path
if (m_LightLoopSettings.enableTileAndCluster && m_LightLoopSettings.enableComputeLightEvaluation)
if (m_FrameSettings.lightLoopSettings.enableTileAndCluster && m_FrameSettings.lightLoopSettings.enableComputeLightEvaluation)
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;

else // Pixel shader evaluation
{
int index = GetDeferredLightingMaterialIndex( options.outputSplitLighting ? 1 : 0,
m_LightLoopSettings.enableTileAndCluster ? 1 : 0,
m_FrameSettings.lightLoopSettings.enableTileAndCluster ? 1 : 0,
m_enableBakeShadowMask ? 1 : 0,
debugDisplaySettings.IsDebugDisplayEnabled() ? 1 : 0);

{
// If SSS is disable, do lighting for both split lighting and no split lighting
// This is for debug purpose, so fine to use immediate material mode here to modify render state
if (!debugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission)
if (!m_FrameSettings.lightingSettings.enableSSSAndTransmission)
{
currentLightingMaterial.SetInt(HDShaderIDs._StencilRef, (int)StencilLightingUsage.NoLighting);
currentLightingMaterial.SetInt(HDShaderIDs._StencilCmp, (int)CompareFunction.NotEqual);

// Note: SHADOWS_SHADOWMASK keyword is enabled in HDRenderPipeline.cs ConfigureForShadowMask
// Note: if we use render opaque with deferred tiling we need to render a opaque depth pass for these opaque objects
if (!m_LightLoopSettings.enableTileAndCluster)
if (!m_FrameSettings.lightLoopSettings.enableTileAndCluster)
{
using (new ProfilingSample(cmd, "Forward pass", HDRenderPipeline.GetSampler(CustomSamplerId.TPForwardPass)))
{

else
{
// Only opaques can use FPTL, transparent must use clustered!
bool useFptl = renderOpaque && m_isFptlEnabledForForwardOpaque;
bool useFptl = renderOpaque && m_FrameSettings.lightLoopSettings.enableFptlForForwardOpaque;
using (new ProfilingSample(cmd, useFptl ? "Forward Tiled pass" : "Forward Clustered pass", HDRenderPipeline.GetSampler(CustomSamplerId.TPForwardTiledClusterpass)))
{

42
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoopSettings.cs


using System;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]

public bool enableBigTilePrepass;
// Setup by system
public bool isFTPLEnabled;
public bool isFptlEnabled;
public LightLoopSettings()
{

enableFptlForForwardOpaque = true;
enableBigTilePrepass = true;
isFTPLEnabled = true;
isFptlEnabled = true;
static public LightLoopSettings InitializeLightLoopSettings(FrameSettings aggregateFrameSettings, RenderPipelineSettings renderPipelineSettings, FrameSettings frameSettings, FrameSettings debugSettings = null)
static public LightLoopSettings InitializeLightLoopSettings(Camera camera, FrameSettings aggregateFrameSettings,
GlobalFrameSettings globalFrameSettings, FrameSettings frameSettings, FrameSettings debugSettings)
LightLoopSettings aggregate;
LightLoopSettings aggregate = new LightLoopSettings();
aggregate.enableTileAndCluster = frameSettings.enableTileAndCluster;
aggregate.enableComputeLightEvaluation = frameSettings.enableComputeLightEvaluation;
aggregate.enableComputeLightVariants = frameSettings.enableComputeLightVariants;
aggregate.enableComputeMaterialVariants = frameSettings.enableComputeMaterialVariants;
aggregate.enableFptlForForwardOpaque = frameSettings.enableFptlForForwardOpaque;
aggregate.enableBigTilePrepass = frameSettings.enableBigTilePrepass;
aggregate.enableTileAndCluster = frameSettings.lightLoopSettings.enableTileAndCluster;
aggregate.enableComputeLightEvaluation = frameSettings.lightLoopSettings.enableComputeLightEvaluation;
aggregate.enableComputeLightVariants = frameSettings.lightLoopSettings.enableComputeLightVariants;
aggregate.enableComputeMaterialVariants = frameSettings.lightLoopSettings.enableComputeMaterialVariants;
aggregate.enableFptlForForwardOpaque = frameSettings.lightLoopSettings.enableFptlForForwardOpaque;
aggregate.enableBigTilePrepass = frameSettings.lightLoopSettings.enableBigTilePrepass;
if (debugSettings != null && !camera.cameraType == CameraType.Reflection && camera.cameraType != CameraType.Preview)
if (debugSettings != null && camera.cameraType != CameraType.Reflection && camera.cameraType != CameraType.Preview)
aggregate.enableTileAndCluster = aggregate.enableTileAndCluster && debugSettings.enableTileAndCluster;
aggregate.enableComputeLightEvaluation = aggregate.enableComputeLightEvaluation && debugSettings.enableComputeLightEvaluation;
aggregate.enableComputeLightVariants = aggregate.enableComputeLightVariants && debugSettings.enableComputeLightVariants;
aggregate.enableComputeMaterialVariants = aggregate.enableComputeMaterialVariants && debugSettings.enableComputeMaterialVariants;
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && debugSettings.enableFptlForForwardOpaque;
aggregate.enableBigTilePrepass = aggregate.enableBigTilePrepass && debugSettings.enableBigTilePrepass;
aggregate.enableTileAndCluster = aggregate.enableTileAndCluster && debugSettings.lightLoopSettings.enableTileAndCluster;
aggregate.enableComputeLightEvaluation = aggregate.enableComputeLightEvaluation && debugSettings.lightLoopSettings.enableComputeLightEvaluation;
aggregate.enableComputeLightVariants = aggregate.enableComputeLightVariants && debugSettings.lightLoopSettings.enableComputeLightVariants;
aggregate.enableComputeMaterialVariants = aggregate.enableComputeMaterialVariants && debugSettings.lightLoopSettings.enableComputeMaterialVariants;
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && debugSettings.lightLoopSettings.enableFptlForForwardOpaque;
aggregate.enableBigTilePrepass = aggregate.enableBigTilePrepass && debugSettings.lightLoopSettings.enableBigTilePrepass;
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && aggregateFrameSettings.enableMSAA;
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && aggregateFrameSettings.renderSettings.enableMSAA;
aggregate.isFTPLEnabled = !aggregateFrameSettings.enableForwardRenderingOnly || aggregate.enableFptlForForwardOpaque;
aggregate.isFptlEnabled = !aggregateFrameSettings.renderSettings.enableForwardRenderingOnly || aggregate.enableFptlForForwardOpaque;
return aggregate;
}

8
ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs


m_HTileRT = new RenderTargetIdentifier(m_HTile);
}
public void PushGlobalParams(CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters, DebugDisplaySettings debugDisplaySettings)
public void PushGlobalParams(CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters, FrameSettings frameSettings)
cmd.SetGlobalInt(HDShaderIDs._EnableSSSAndTransmission, debugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._EnableSSSAndTransmission, frameSettings.lightingSettings.enableSSSAndTransmission ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._UseDisneySSS, sssParameters.useDisneySSS ? 1 : 0);
unsafe
{

}
// Combines specular lighting and diffuse lighting with subsurface scattering.
public void SubsurfaceScatteringPass(HDCamera hdCamera, CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters, DebugDisplaySettings debugDisplaySettings,
public void SubsurfaceScatteringPass(HDCamera hdCamera, CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters, FrameSettings frameSettings,
if (m_sssSettings == null || !debugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission)
if (m_sssSettings == null || !frameSettings.lightingSettings.enableSSSAndTransmission)
return;
using (new ProfilingSample(cmd, "Subsurface Scattering", HDRenderPipeline.GetSampler(CustomSamplerId.SubsurfaceScattering)))

211
ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/FrameSettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// The settings here are per frame settings.
// Each camera must have its own per frame settings
[Serializable]
public struct LightingSettings
// FrameSettings contain settings for a given camera / render. This settings can change from one frame to the other
[DisallowMultipleComponent, ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
public class FrameSettings : MonoBehaviour
// Setup by users
public bool enableShadow;
public bool enableSSR; // Depends on DepthPyramid
public bool enableSSAO;
public bool enableSSSAndTransmission;
// Setup by system
public float diffuseGlobalDimmer;
public float specularGlobalDimmer;
public LightingSettings()
// The settings here are per frame settings.
// Each camera must have its own per frame settings
[Serializable]
public class LightingSettings
enableShadow = true;
enableSSR = true;
enableSSAO = true;
enableSSSAndTransmission = true;
// Setup by users
public bool enableShadow = true;
public bool enableSSR = true; // Depends on DepthPyramid
public bool enableSSAO = true;
public bool enableSSSAndTransmission = true;
diffuseGlobalDimmer = 1.0f;
specularGlobalDimmer = 1.0f;
// Setup by system
public float diffuseGlobalDimmer = 1.0f;
public float specularGlobalDimmer = 1.0f;
}
[Serializable]
public struct RenderSettings
{
// Setup by users
public bool enableForwardRenderingOnly; // TODO: Currently there is no way to strip the extra forward shaders generated by the shaders compiler, so we can switch dynamically.
public bool enableDepthPrepassWithDeferredRendering;
public bool enableAlphaTestOnlyInDeferredPrepass;
public bool enableTransparentPrePass;
public bool enableMotionVectors;
public bool enableDBuffer;
public bool enableAtmosphericScattering;
public bool enableRoughRefraction; // Depends on DepthPyramid - If not enable, just do a copy of the scene color (?) - how to disable rough refraction ?
public bool enableTransparentPostPass;
public bool enableDistortion;
public bool enablePostprocess;
public bool enableStereo;
public bool enableAsyncCompute;
public bool enableOpaqueObjects;
public bool enableTransparentObjects;
public bool enableMSAA;
// Setup by system
public bool enableMaterialDisplayDebug;
public bool enableShadowMask;
public RenderSettings()
[Serializable]
public class RenderSettings
enableForwardRenderingOnly = false;
enableDepthPrepassWithDeferredRendering = false;
enableAlphaTestOnlyInDeferredPrepass = false;
// Setup by users
public bool enableForwardRenderingOnly = 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 enableDepthPrepassWithDeferredRendering = false;
public bool enableAlphaTestOnlyInDeferredPrepass = false;
enableTransparentPrePass = true;
enableMotionVectors = true;
enableDBuffer = true;
enableAtmosphericScattering = true;
enableRoughRefraction = true;
enableTransparentPostPass = true;
enableDistortion = true;
enablePostprocess = true;
public bool enableTransparentPrePass = true;
public bool enableMotionVectors = true;
public bool enableDBuffer = true;
public bool enableAtmosphericScattering = true;
public bool enableRoughRefraction = true; // Depends on DepthPyramid - If not enable, just do a copy of the scene color (?) - how to disable rough refraction ?
public bool enableTransparentPostPass = true;
public bool enableDistortion = true;
public bool enablePostprocess = true;
enableStereo = false;
enableAsyncCompute = false;
public bool enableStereo = false;
public bool enableAsyncCompute = false;
enableOpaqueObjects = true;
enableTransparentObjects = true;
public bool enableOpaqueObjects = true;
public bool enableTransparentObjects = true;
enableMSAA = false;
public bool enableMSAA = false;
enableMaterialDisplayDebug = false;
enableShadowMask = false;
// Setup by system
public bool enableMaterialDisplayDebug = false;
public bool enableShadowMask = false;
}
// FrameSettings contain settings for a given camera / render. This settings can change from one frame to the other
[Serializable]
public class FrameSettings
{
public LightingSettings lightingSettings;
public RenderSettings renderSettings;
public LightLoopSettings lightLoopSettings;
public LightingSettings lightingSettings = new LightingSettings();
public RenderSettings renderSettings = new RenderSettings();
public LightLoopSettings lightLoopSettings = new LightLoopSettings();
static public FrameSettings InitializeFrameSettings(RenderPipelineSettings renderPipelineSettings, FrameSettings frameSettings, FrameSettings debugSettings = null)
static public FrameSettings InitializeFrameSettings(Camera camera, GlobalFrameSettings globalFrameSettings, FrameSettings frameSettings, FrameSettings debugSettings)
FrameSettings aggregate;
FrameSettings aggregate = new FrameSettings();
// When rendering reflection probe we disable specular as it is view dependent
if (camera.cameraType == CameraType.Reflection)

aggregate.lightingSettings.specularGlobalDimmer = 1.0f;
}
aggregate.lightingSettings.enableShadow = frameSettings.enableShadow;
aggregate.lightingSettings.enableSSR = frameSettings.enableSSR && renderPipelineSettings.supportSSR;
aggregate.lightingSettings.enableSSAO = frameSettings.enableSSAO && renderPipelineSettings.supportSSAO;
aggregate.lightingSettings.enableSSSAndTransmission = frameSettings.enableSSSAndTransmission && renderPipelineSettings.supportSSSAndTransmission;
aggregate.lightingSettings.enableShadow = frameSettings.lightingSettings.enableShadow;
aggregate.lightingSettings.enableSSR = frameSettings.lightingSettings.enableSSR && globalFrameSettings.lightingSettings.supportSSR;
aggregate.lightingSettings.enableSSAO = frameSettings.lightingSettings.enableSSAO && globalFrameSettings.lightingSettings.supportSSAO;
aggregate.lightingSettings.enableSSSAndTransmission = frameSettings.lightingSettings.enableSSSAndTransmission && globalFrameSettings.lightingSettings.supportSSSAndTransmission;
aggregate.renderSettings.enableForwardRenderingOnly = frameSettings.enableForwardRenderingOnly || GL.wireframe;
aggregate.renderSettings.enableDepthPrepassWithDeferredRendering = frameSettings.enableDepthPrepassWithDeferredRendering;
aggregate.renderSettings.enableAlphaTestOnlyInDeferredPrepass = frameSettings.enableAlphaTestOnlyInDeferredPrepass;
aggregate.renderSettings.enableForwardRenderingOnly = frameSettings.renderSettings.enableForwardRenderingOnly || GL.wireframe;
aggregate.renderSettings.enableDepthPrepassWithDeferredRendering = frameSettings.renderSettings.enableDepthPrepassWithDeferredRendering;
aggregate.renderSettings.enableAlphaTestOnlyInDeferredPrepass = frameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass;
aggregate.renderSettings.enableTransparentPrePass = frameSettings.enableTransparentPrePass;
aggregate.renderSettings.enableMotionVectors = frameSettings.enableMotionVectors;
aggregate.renderSettings.enableDBuffer = frameSettings.enableDBuffer && renderPipelineSettings.supportDBuffer;
aggregate.renderSettings.enableAtmosphericScattering = frameSettings.enableAtmosphericScattering;
aggregate.renderSettings.enableRoughRefraction = frameSettings.enableRoughRefraction;
aggregate.renderSettings.enableTransparentPostPass = frameSettings.enableTransparentPostPass;
aggregate.renderSettings.enableDistortion = frameSettings.enableDistortion;
aggregate.renderSettings.enablePostprocess = frameSettings.enablePostprocess;
aggregate.renderSettings.enableTransparentPrePass = frameSettings.renderSettings.enableTransparentPrePass;
aggregate.renderSettings.enableMotionVectors = frameSettings.renderSettings.enableMotionVectors;
aggregate.renderSettings.enableDBuffer = frameSettings.renderSettings.enableDBuffer && globalFrameSettings.renderSettings.supportDBuffer;
aggregate.renderSettings.enableAtmosphericScattering = frameSettings.renderSettings.enableAtmosphericScattering;
aggregate.renderSettings.enableRoughRefraction = frameSettings.renderSettings.enableRoughRefraction;
aggregate.renderSettings.enableTransparentPostPass = frameSettings.renderSettings.enableTransparentPostPass;
aggregate.renderSettings.enableDistortion = frameSettings.renderSettings.enableDistortion;
aggregate.renderSettings.enablePostprocess = frameSettings.renderSettings.enablePostprocess;
aggregate.renderSettings.enableStereo = frameSettings.enableStereo && UnityEngine.XR.XRSettings.isDeviceActive;
aggregate.renderSettings.enableAsyncCompute = frameSettings.enableAsyncCompute;
aggregate.renderSettings.enableStereo = frameSettings.renderSettings.enableStereo && UnityEngine.XR.XRSettings.isDeviceActive && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
// Force forward if we request stereo. TODO: We should not enforce that, users should be able to chose deferred
aggregate.renderSettings.enableForwardRenderingOnly = aggregate.renderSettings.enableForwardRenderingOnly || aggregate.renderSettings.enableStereo;
aggregate.renderSettings.enableAsyncCompute = frameSettings.renderSettings.enableAsyncCompute;
aggregate.renderSettings.enableOpaqueObjects = frameSettings.enableOpaqueObjects;
aggregate.renderSettings.enableTransparentObjects = frameSettings.enableTransparentObjects;
aggregate.renderSettings.enableOpaqueObjects = frameSettings.renderSettings.enableOpaqueObjects;
aggregate.renderSettings.enableTransparentObjects = frameSettings.renderSettings.enableTransparentObjects;
aggregate.renderSettings.enableMSAA = frameSettings.enableMSAA && renderPipelineSettings.supportMSAA;
aggregate.renderSettings.enableMSAA = frameSettings.renderSettings.enableMSAA && globalFrameSettings.renderSettings.supportMSAA;
aggregate.renderSettings.enableShadowMask = renderPipelineSettings.supportShadowMask;
aggregate.renderSettings.enableShadowMask = globalFrameSettings.lightingSettings.supportShadowMask;
if (debugSettings != null && !camera.cameraType == CameraType.Reflection && camera.cameraType != CameraType.Preview)
if (debugSettings != null && camera.cameraType != CameraType.Reflection && camera.cameraType != CameraType.Preview)
aggregate.lightingSettings.enableShadow = aggregate.lightingSettings.enableShadow && debugSettings.enableShadow;
aggregate.lightingSettings.enableSSR = aggregate.lightingSettings.enableSSR && debugSettings.enableSSR;
aggregate.lightingSettings.enableSSAO = aggregate.lightingSettings.enableSSAO && debugSettings.enableSSAO;
aggregate.lightingSettings.enableSSSAndTransmission = aggregate.lightingSettings.enableSSSAndTransmission && debugSettings.enableSSSAndTransmission;
aggregate.lightingSettings.enableShadow = aggregate.lightingSettings.enableShadow && debugSettings.lightingSettings.enableShadow;
aggregate.lightingSettings.enableSSR = aggregate.lightingSettings.enableSSR && debugSettings.lightingSettings.enableSSR;
aggregate.lightingSettings.enableSSAO = aggregate.lightingSettings.enableSSAO && debugSettings.lightingSettings.enableSSAO;
aggregate.lightingSettings.enableSSSAndTransmission = aggregate.lightingSettings.enableSSSAndTransmission && debugSettings.lightingSettings.enableSSSAndTransmission;
aggregate.renderSettings.enableForwardRenderingOnly = aggregate.lightingSettings.enableForwardRenderingOnly && debugSettings.enableForwardRenderingOnly;
aggregate.renderSettings.enableDepthPrepassWithDeferredRendering = aggregate.lightingSettings.enableDepthPrepassWithDeferredRendering && debugSettings.enableDepthPrepassWithDeferredRendering;
aggregate.renderSettings.enableAlphaTestOnlyInDeferredPrepass = aggregate.lightingSettings.enableAlphaTestOnlyInDeferredPrepass && debugSettings.enableAlphaTestOnlyInDeferredPrepass;
aggregate.renderSettings.enableForwardRenderingOnly = aggregate.renderSettings.enableForwardRenderingOnly && debugSettings.renderSettings.enableForwardRenderingOnly;
aggregate.renderSettings.enableDepthPrepassWithDeferredRendering = aggregate.renderSettings.enableDepthPrepassWithDeferredRendering && debugSettings.renderSettings.enableDepthPrepassWithDeferredRendering;
aggregate.renderSettings.enableAlphaTestOnlyInDeferredPrepass = aggregate.renderSettings.enableAlphaTestOnlyInDeferredPrepass && debugSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass;
aggregate.renderSettings.enableTransparentPrePass = aggregate.lightingSettings.enableTransparentPrePass && debugSettings.enableTransparentPrePass;
aggregate.renderSettings.enableMotionVectors = aggregate.lightingSettings.enableMotionVectors && debugSettings.enableMotionVectors;
aggregate.renderSettings.enableDBuffer = aggregate.lightingSettings.enableDBuffer && debugSettings.enableDBuffer;
aggregate.renderSettings.enableAtmosphericScattering = aggregate.lightingSettings.enableAtmosphericScattering && debugSettings.enableAtmosphericScattering;
aggregate.renderSettings.enableRoughRefraction = aggregate.lightingSettings.enableRoughRefraction && debugSettings.enableRoughRefraction;
aggregate.renderSettings.enableTransparentPostPass = aggregate.lightingSettings.enableTransparentPostPass && debugSettings.enableTransparentPostPass;
aggregate.renderSettings.enableDistortion = aggregate.lightingSettings.enableDistortion && debugSettings.enableDistortion;
aggregate.renderSettings.enablePostprocess = aggregate.lightingSettings.enablePostprocess && debugSettings.enablePostprocess;
aggregate.renderSettings.enableTransparentPrePass = aggregate.renderSettings.enableTransparentPrePass && debugSettings.renderSettings.enableTransparentPrePass;
aggregate.renderSettings.enableMotionVectors = aggregate.renderSettings.enableMotionVectors && debugSettings.renderSettings.enableMotionVectors;
aggregate.renderSettings.enableDBuffer = aggregate.renderSettings.enableDBuffer && debugSettings.renderSettings.enableDBuffer;
aggregate.renderSettings.enableAtmosphericScattering = aggregate.renderSettings.enableAtmosphericScattering && debugSettings.renderSettings.enableAtmosphericScattering;
aggregate.renderSettings.enableRoughRefraction = aggregate.renderSettings.enableRoughRefraction && debugSettings.renderSettings.enableRoughRefraction;
aggregate.renderSettings.enableTransparentPostPass = aggregate.renderSettings.enableTransparentPostPass && debugSettings.renderSettings.enableTransparentPostPass;
aggregate.renderSettings.enableDistortion = aggregate.renderSettings.enableDistortion && debugSettings.renderSettings.enableDistortion;
aggregate.renderSettings.enablePostprocess = aggregate.renderSettings.enablePostprocess && debugSettings.renderSettings.enablePostprocess;
aggregate.renderSettings.enableStereo = aggregate.lightingSettings.enableStereo && debugSettings.enableStereo && UnityEngine.XR.XRSettings.isDeviceActive;
aggregate.renderSettings.enableAsyncCompute = aggregate.lightingSettings.enableAsyncCompute && debugSettings.enableAsyncCompute;
aggregate.renderSettings.enableStereo = aggregate.renderSettings.enableStereo && debugSettings.renderSettings.enableStereo && UnityEngine.XR.XRSettings.isDeviceActive;
aggregate.renderSettings.enableAsyncCompute = aggregate.renderSettings.enableAsyncCompute && debugSettings.renderSettings.enableAsyncCompute;
aggregate.renderSettings.enableOpaqueObjects = aggregate.lightingSettings.enableOpaqueObjects && debugSettings.enableOpaqueObjects;
aggregate.renderSettings.enableTransparentObjects = aggregate.lightingSettings.enableTransparentObjects && debugSettings.enableTransparentObjects;
aggregate.renderSettings.enableOpaqueObjects = aggregate.renderSettings.enableOpaqueObjects && debugSettings.renderSettings.enableOpaqueObjects;
aggregate.renderSettings.enableTransparentObjects = aggregate.renderSettings.enableTransparentObjects && debugSettings.renderSettings.enableTransparentObjects;
aggregate.lightLoopSettings = LightLoopSettings.InitializeLightLoopSettings(aggregate, renderPipelineSettings, frameSettings, debugSettings);
aggregate.lightLoopSettings = LightLoopSettings.InitializeLightLoopSettings(camera, aggregate, globalFrameSettings, frameSettings, debugSettings);
return aggregate;
}

42
ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/GlobalFrameSettings.cs


{
// GlobalFrameSettings represent settings that are immutable at runtime.
// There is a dedicated RenderRenderPipelineSettings for each platform
public struct GlobalRenderSettings
public class GlobalFrameSettings : ScriptableObject
public bool supportShadowMask;
public bool supportSSSAndTransmission;
public bool supportDBuffer;
public bool supportSSR;
public bool supportSSAO;
public bool supportMSAA;
public GlobalRenderSettings()
[Serializable]
public class GlobalLightingSettings
supportShadowMask = true;
supportSSSAndTransmission = true;
supportDBuffer = false;
public bool supportShadowMask = true;
public bool supportSSR = true;
public bool supportSSAO = true;
public bool supportSSSAndTransmission = true;
}
supportSSR = true;
supportSSAO = true;
supportMSAA = false;
[Serializable]
public class GlobalRenderSettings
{
public bool supportDBuffer = false;
public bool supportMSAA = false;
}
[Serializable]
public class GlobalFrameSettings : ScriptableObject
{
public GlobalRenderSettings renderSettings;
public GlobalLightLoopSettings lightLoopSettings;
public GlobalLightingSettings lightingSettings = new GlobalLightingSettings();
public GlobalRenderSettings renderSettings = new GlobalRenderSettings();
public GlobalLightLoopSettings lightLoopSettings = new GlobalLightLoopSettings();
public ShadowInitParameters shadowInitParams = new ShadowInitParameters();
}
}

7
ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class RenderPipelineSettings : ScriptableSingleton<RenderPipelineSettings>
public class RenderPipelineSettings : Singleton<RenderPipelineSettings>
{
[SerializeField]
GlobalFrameSettings m_globalFrameSettings;

if (m_globalFrameSettings == null)
if (instance.m_globalFrameSettings == null)
m_globalFrameSettings = new GlobalFrameSettings();
instance.m_globalFrameSettings = new GlobalFrameSettings();
return instance.m_globalFrameSettings;
}
}

6
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs


return type != FogType.None;
}
public void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
public void PushShaderParameters(CommandBuffer cmd, FrameSettings frameSettings)
if(renderingDebug.enableAtmosphericScattering)
if(frameSettings.renderSettings.enableAtmosphericScattering)
cmd.SetGlobalFloat(m_TypeParam, (float)type);
else
cmd.SetGlobalFloat(m_TypeParam, (float)FogType.None);

}
}
}
}

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


}
}
public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd, DebugDisplaySettings debugSettings)
public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd, FrameSettings m_frameSettings)
{
using (new ProfilingSample(cmd, "Sky Pass"))
{

m_SkySettings.atmosphericScatteringSettings.PushShaderParameters(cmd, debugSettings.renderingDebugSettings);
m_SkySettings.atmosphericScatteringSettings.PushShaderParameters(cmd, m_frameSettings);
m_BuiltinParameters.commandBuffer = cmd;
m_BuiltinParameters.sunLight = sunLight;

18
ScriptableRenderPipeline/HDRenderPipeline/Debug/RenderingDebug.cs


using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public class RenderingDebugSettings
{
public bool displayOpaqueObjects = true;
public bool displayTransparentObjects = true;
public bool enableDistortion = true;
public bool enableGaussianPyramid = true;
public bool enableSSSAndTransmission = true;
public bool enableAtmosphericScattering = true;
public bool allowStereo = true;
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Debug/RenderingDebug.cs.meta


fileFormatVersion: 2
guid: 1e64277580777ed4fae930253871a755
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存