浏览代码

Merge pull request #691 from Unity-Technologies/Update-FrameSettings

Update frame settings - adress various feedback
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
e97ba4d0
共有 16 个文件被更改,包括 388 次插入322 次删除
  1. 66
      ScriptableRenderPipeline/HDRenderPipeline/Camera/HDAdditionalCameraData.cs
  2. 4
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.Styles.cs
  3. 38
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  4. 115
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  5. 22
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs
  6. 16
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  7. 30
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoopSettings.cs
  8. 4
      ScriptableRenderPipeline/HDRenderPipeline/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
  9. 286
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/FrameSettings.cs
  10. 2
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs.meta
  11. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs
  12. 36
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs
  13. 43
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/GlobalFrameSettings.cs
  14. 35
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineSettings.cs
  15. 11
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineSettings.cs.meta
  16. 0
      /ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs.meta

66
ScriptableRenderPipeline/HDRenderPipeline/Camera/HDAdditionalCameraData.cs


public class HDAdditionalCameraData : MonoBehaviour
{
// This struct allow to add specialized path in HDRenderPipeline (can be use to render mini map or planar reflection etc...)
// A rendering path is the list of rendering pass that will be executed at runtime and depends on the associated FrameSettings
// Default is the default rendering path define by the HDRendeRPipelineAsset FrameSettings.
// Custom allow users to define the FrameSettigns for this path
// Then enum can contain either preset of FrameSettings or hard coded path
// Unlit below is a hard coded path (a path that can't be implemented only with FrameSettings)
Unlit, // Preset
Custom // Fine grained
Custom, // Fine grained
Unlit // Hard coded path
// we create a runtime copy (m_effectiveFrameSettings that is used, and any parametrization is done on serialized frameSettings)
public FrameSettings frameSettings = new FrameSettings(); // Serialize frameSettings
// we create a runtime copy (m_ActiveFrameSettings that is used, and any parametrization is done on serialized frameSettings)
public FrameSettings serializedFrameSettings = new FrameSettings(); // Serialize frameSettings
FrameSettings m_effectiveFrameSettings = new FrameSettings();
public FrameSettings GetEffectiveFrameSettings()
FrameSettings m_FrameSettings = new FrameSettings();
public FrameSettings GetFrameSettings()
return m_effectiveFrameSettings;
return m_FrameSettings;
string m_CameraRegisterName;
void RegisterDebug()
{
if (!isRegisterDebug)
{
FrameSettings.RegisterDebug(m_camera.name, GetFrameSettings());
m_CameraRegisterName = m_camera.name;
isRegisterDebug = true;
}
}
void UnRegisterDebug()
{
if (isRegisterDebug)
{
FrameSettings.UnRegisterDebug(m_CameraRegisterName);
isRegisterDebug = false;
}
}
void OnEnable()
{

m_camera = GetComponent<Camera>();
m_camera.allowHDR = false;
frameSettings.CopyTo(m_effectiveFrameSettings);
serializedFrameSettings.CopyTo(m_FrameSettings);
RegisterDebug();
}
if (!isRegisterDebug)
void Update()
{
#if UNITY_EDITOR
if (m_camera.name != m_CameraRegisterName)
FrameSettings.RegisterDebug(m_camera.name, GetEffectiveFrameSettings());
isRegisterDebug = true;
UnRegisterDebug();
RegisterDebug();
#endif
}
void OnValidate()
{
// Modification of frameSettings in the inspector will call OnValidate().
// We do a copy of the settings to those effectively used
serializedFrameSettings.CopyTo(m_FrameSettings);
}
void OnDisable()
{
UnRegisterDebug();
}
}
}

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


{
public sealed partial class HDRenderPipelineInspector
{
// TODO: missing tooltips
sealed class Styles
{
public readonly GUIContent defaults = new GUIContent("Defaults");

public readonly GUIContent settingsLabel = new GUIContent("Settings");
public readonly GUIContent globalFrameSettings = new GUIContent("Global Frame Settings");
public readonly GUIContent renderPipelineSettings = new GUIContent("Render Pipeline Settings");
// Shadow Settings
public readonly GUIContent supportDBuffer = new GUIContent("Support Decal buffer");
public readonly GUIContent supportMSAA = new GUIContent("Support MSAA");
// Shadow Settings

38
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


// Global FrameSettings
// Global Render settings
m_supportDBuffer = properties.Find(x => x.globalFrameSettings.renderSettings.supportDBuffer);
m_supportMSAA = properties.Find(x => x.globalFrameSettings.renderSettings.supportMSAA);
m_supportDBuffer = properties.Find(x => x.renderPipelineSettings.supportDBuffer);
m_supportMSAA = properties.Find(x => x.renderPipelineSettings.supportMSAA);
m_ShadowAtlasWidth = properties.Find(x => x.globalFrameSettings.shadowInitParams.shadowAtlasWidth);
m_ShadowAtlasHeight = properties.Find(x => x.globalFrameSettings.shadowInitParams.shadowAtlasHeight);
m_ShadowAtlasWidth = properties.Find(x => x.renderPipelineSettings.shadowInitParams.shadowAtlasWidth);
m_ShadowAtlasHeight = properties.Find(x => x.renderPipelineSettings.shadowInitParams.shadowAtlasHeight);
m_SpotCookieSize = properties.Find(x => x.globalFrameSettings.lightLoopSettings.spotCookieSize);
m_PointCookieSize = properties.Find(x => x.globalFrameSettings.lightLoopSettings.pointCookieSize);
m_ReflectionCubemapSize = properties.Find(x => x.globalFrameSettings.lightLoopSettings.reflectionCubemapSize);
m_ReflectionCacheCompressed = properties.Find(x => x.globalFrameSettings.lightLoopSettings.reflectionCacheCompressed);
m_SpotCookieSize = properties.Find(x => x.renderPipelineSettings.lightLoopSettings.spotCookieSize);
m_PointCookieSize = properties.Find(x => x.renderPipelineSettings.lightLoopSettings.pointCookieSize);
m_ReflectionCubemapSize = properties.Find(x => x.renderPipelineSettings.lightLoopSettings.reflectionCubemapSize);
m_ReflectionCacheCompressed = properties.Find(x => x.renderPipelineSettings.lightLoopSettings.reflectionCacheCompressed);
m_enableTileAndCluster = properties.Find(x => x.defaultFrameSettings.lightLoopSettings.enableTileAndCluster);
m_enableComputeLightEvaluation = properties.Find(x => x.defaultFrameSettings.lightLoopSettings.enableComputeLightEvaluation);
m_enableComputeLightVariants = properties.Find(x => x.defaultFrameSettings.lightLoopSettings.enableComputeLightVariants);
m_enableComputeMaterialVariants = properties.Find(x => x.defaultFrameSettings.lightLoopSettings.enableComputeMaterialVariants);
m_enableFptlForForwardOpaque = properties.Find(x => x.defaultFrameSettings.lightLoopSettings.enableFptlForForwardOpaque);
m_enableBigTilePrepass = properties.Find(x => x.defaultFrameSettings.lightLoopSettings.enableBigTilePrepass);
m_enableTileAndCluster = properties.Find(x => x.serializedFrameSettings.lightLoopSettings.enableTileAndCluster);
m_enableComputeLightEvaluation = properties.Find(x => x.serializedFrameSettings.lightLoopSettings.enableComputeLightEvaluation);
m_enableComputeLightVariants = properties.Find(x => x.serializedFrameSettings.lightLoopSettings.enableComputeLightVariants);
m_enableComputeMaterialVariants = properties.Find(x => x.serializedFrameSettings.lightLoopSettings.enableComputeMaterialVariants);
m_enableFptlForForwardOpaque = properties.Find(x => x.serializedFrameSettings.lightLoopSettings.enableFptlForForwardOpaque);
m_enableBigTilePrepass = properties.Find(x => x.serializedFrameSettings.lightLoopSettings.enableBigTilePrepass);
m_enableAsyncCompute = properties.Find(x => x.defaultFrameSettings.renderSettings.enableAsyncCompute);
m_RenderingUseForwardOnly = properties.Find(x => x.defaultFrameSettings.renderSettings.enableForwardRenderingOnly);
m_RenderingUseDepthPrepass = properties.Find(x => x.defaultFrameSettings.renderSettings.enableDepthPrepassWithDeferredRendering);
m_RenderingUseDepthPrepassAlphaTestOnly = properties.Find(x => x.defaultFrameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass);
m_enableAsyncCompute = properties.Find(x => x.serializedFrameSettings.enableAsyncCompute);
m_RenderingUseForwardOnly = properties.Find(x => x.serializedFrameSettings.enableForwardRenderingOnly);
m_RenderingUseDepthPrepass = properties.Find(x => x.serializedFrameSettings.enableDepthPrepassWithDeferredRendering);
m_RenderingUseDepthPrepassAlphaTestOnly = properties.Find(x => x.serializedFrameSettings.enableAlphaTestOnlyInDeferredPrepass);
// Subsurface Scattering Settings
m_SubsurfaceScatteringSettings = properties.Find(x => x.sssSettings);

EditorGUILayout.LabelField(s_Styles.settingsLabel, EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.LabelField(s_Styles.globalFrameSettings, EditorStyles.boldLabel);
EditorGUILayout.LabelField(s_Styles.renderPipelineSettings, EditorStyles.boldLabel);
GlobalRenderSettingsUI(hdAsset);
GlobalShadowSettingsUI(hdAsset);

115
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


m_SkyManager.skySettings = skySettingsToUse;
m_DebugDisplaySettings.RegisterDebug();
FrameSettings.RegisterDebug("Default Camera", m_Asset.GetEffectiveDefaultFrameSettings());
FrameSettings.RegisterDebug("Default Camera", m_Asset.GetFrameSettings());
m_DebugFullScreenTempRT = HDShaderIDs._DebugFullScreenTexture;
// Init all samplers

// First, get aggregate of frame settings base on global settings, camera frame settings and debug settings
var additionalCameraData = camera.GetComponent<HDAdditionalCameraData>();
// Note: the scene view camera will never have additionalCameraData
m_FrameSettings = FrameSettings.InitializeFrameSettings( camera, m_Asset.GetGlobalFrameSettings(),
(additionalCameraData && additionalCameraData.renderingPath != HDAdditionalCameraData.RenderingPath.Default) ? additionalCameraData.GetEffectiveFrameSettings() : m_Asset.GetEffectiveDefaultFrameSettings());
m_FrameSettings = FrameSettings.InitializeFrameSettings( camera, m_Asset.GetRenderPipelineSettings(),
(additionalCameraData && additionalCameraData.renderingPath != HDAdditionalCameraData.RenderingPath.Default) ? additionalCameraData.GetFrameSettings() : m_Asset.GetFrameSettings());
// This is the main command buffer used for the frame.
var cmd = CommandBufferPool.Get("");

bool enableBakeShadowMask;
using (new ProfilingSample(cmd, "TP_PrepareLightsForGPU", GetSampler(CustomSamplerId.TPPrepareLightsForGPU)))
{
enableBakeShadowMask = m_LightLoop.PrepareLightsForGPU(cmd, m_ShadowSettings, m_CullResults, camera) && m_FrameSettings.renderSettings.enableShadowMask;
enableBakeShadowMask = m_LightLoop.PrepareLightsForGPU(cmd, m_ShadowSettings, m_CullResults, camera) && m_FrameSettings.enableShadowMask;
}
ConfigureForShadowMask(enableBakeShadowMask, cmd);

}
GPUFence buildGPULightListsCompleteFence = new GPUFence();
if (m_FrameSettings.renderSettings.enableAsyncCompute)
if (m_FrameSettings.enableAsyncCompute)
{
GPUFence startFence = cmd.CreateGPUFence();
renderContext.ExecuteCommandBuffer(cmd);

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

AccumulateDistortion(m_CullResults, camera, renderContext, cmd);
RenderDistortion(cmd, m_Asset.renderPipelineResources);
RenderFinal(hdCamera, cmd, postProcessLayer);
// Final blit
if (m_FrameSettings.enablePostprocess && CoreUtils.IsPostProcessingActive(postProcessLayer))
{
RenderPostProcess(hdCamera, cmd, postProcessLayer);
}
else
{
using (new ProfilingSample(cmd, "Blit to final RT", GetSampler(CustomSamplerId.BlitToFinalRT)))
{
// Simple blit
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);
}
}
}
RenderDebug(hdCamera, cmd);

RenderStateBlock? stateBlock = null,
Material overrideMaterial = null)
{
if (!m_FrameSettings.renderSettings.enableOpaqueObjects)
if (!m_FrameSettings.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_FrameSettings.renderSettings.enableTransparentObjects)
if (!m_FrameSettings.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_FrameSettings.renderSettings.enableDistortion)
if (!m_FrameSettings.enableDistortion)
return;
using (new ProfilingSample(cmd, "Distortion", GetSampler(CustomSamplerId.Distortion)))

void RenderDistortion(CommandBuffer cmd, RenderPipelineResources resources)
{
if (!m_FrameSettings.renderSettings.enableDistortion)
if (!m_FrameSettings.enableDistortion)
return;
using (new ProfilingSample(cmd, "ApplyDistortion", GetSampler(CustomSamplerId.ApplyDistortion)))

// 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 = m_FrameSettings.renderSettings.enableForwardRenderingOnly || m_FrameSettings.renderSettings.enableDepthPrepassWithDeferredRendering;
bool addAlphaTestedOnly = !m_FrameSettings.renderSettings.enableForwardRenderingOnly && m_FrameSettings.renderSettings.enableDepthPrepassWithDeferredRendering && m_FrameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass;
bool addFullDepthPrepass = m_FrameSettings.enableForwardRenderingOnly || m_FrameSettings.enableDepthPrepassWithDeferredRendering;
bool addAlphaTestedOnly = !m_FrameSettings.enableForwardRenderingOnly && m_FrameSettings.enableDepthPrepassWithDeferredRendering && m_FrameSettings.enableAlphaTestOnlyInDeferredPrepass;
var camera = hdCamera.camera;

}
}
if (m_FrameSettings.renderSettings.enableTransparentPrePass)
if (m_FrameSettings.enableTransparentPrePass)
{
// Render transparent depth prepass after opaque one
using (new ProfilingSample(cmd, "Transparent Depth Prepass", GetSampler(CustomSamplerId.TransparentDepthPrepass)))

// 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 (m_FrameSettings.renderSettings.enableForwardRenderingOnly)
if (m_FrameSettings.enableForwardRenderingOnly)
return;
var camera = hdCamera.camera;

}
else
{
if (m_FrameSettings.renderSettings.enableDepthPrepassWithDeferredRendering)
if (m_FrameSettings.enableDepthPrepassWithDeferredRendering)
RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, rangeOpaqueNoAlphaTest, m_FrameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass ? m_DepthStateOpaque : m_DepthStateOpaqueWithPrepass);
RenderOpaqueRenderList(cull, camera, renderContext, cmd, HDShaderPassNames.s_GBufferName, m_currentRendererConfigurationBakedLighting, rangeOpaqueNoAlphaTest, m_FrameSettings.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);
}

void RenderDBuffer(Vector3 cameraPos, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_FrameSettings.renderSettings.enableDBuffer)
if (!m_FrameSettings.enableDBuffer)
return ;
using (new ProfilingSample(cmd, "DBuffer", GetSampler(CustomSamplerId.DBuffer)))

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

void RenderSSAO(CommandBuffer cmd, Camera camera, ScriptableRenderContext renderContext, PostProcessLayer postProcessLayer)
{
// Apply SSAO from PostProcessLayer
if (m_FrameSettings.lightingSettings.enableSSAO && postProcessLayer != null && postProcessLayer.enabled)
if (m_FrameSettings.enableSSAO && postProcessLayer != null && postProcessLayer.enabled)
{
var settings = postProcessLayer.GetSettings<AmbientOcclusion>();

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

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

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_FrameSettings.lightingSettings.enableSSSAndTransmission)
if (m_FrameSettings.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 = m_FrameSettings.renderSettings.enableForwardRenderingOnly ? m_ForwardAndForwardOnlyPassNames : m_ForwardOnlyPassNames;
var passNames = m_FrameSettings.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 RenderTransparentDepthPostPass(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, CommandBuffer cmd, ForwardPass pass)
{
if (!m_FrameSettings.renderSettings.enableTransparentPostPass)
if (!m_FrameSettings.enableTransparentPostPass)
return;
using (new ProfilingSample(cmd, "Render Transparent Depth Post ", GetSampler(CustomSamplerId.TransparentDepthPostPass)))

void RenderVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_FrameSettings.renderSettings.enableMotionVectors)
if (!m_FrameSettings.enableMotionVectors)
return;
using (new ProfilingSample(cmd, "Velocity", GetSampler(CustomSamplerId.Velocity)))

{
if (debugMode == FullScreenDebugMode.PreRefractionColorPyramid)
{
if (!m_FrameSettings.renderSettings.enableRoughRefraction)
if (!m_FrameSettings.enableRoughRefraction)
if (!m_FrameSettings.renderSettings.enableDistortion && !m_FrameSettings.renderSettings.enablePostprocess && !m_FrameSettings.lightingSettings.enableSSR)
if (!m_FrameSettings.enableDistortion && !m_FrameSettings.enablePostprocess && !m_FrameSettings.enableSSR)
return;
}

}
}
void RenderFinal(HDCamera hdcamera, CommandBuffer cmd, PostProcessLayer layer)
void RenderPostProcess(HDCamera hdcamera, CommandBuffer cmd, PostProcessLayer layer)
if (m_FrameSettings.renderSettings.enablePostprocess && CoreUtils.IsPostProcessingActive(layer))
using (new ProfilingSample(cmd, "Post-processing", GetSampler(CustomSamplerId.PostProcessing)))
using (new ProfilingSample(cmd, "Post-processing", GetSampler(CustomSamplerId.PostProcessing)))
{
// Note: Here we don't use GetDepthTexture() to get the depth texture but m_CameraDepthStencilBuffer as the Forward transparent pass can
// write extra data to deal with DOF/MB
cmd.SetGlobalTexture(HDShaderIDs._CameraDepthTexture, m_CameraDepthStencilBuffer);
cmd.SetGlobalTexture(HDShaderIDs._CameraMotionVectorsTexture, m_VelocityBufferRT);
// Note: Here we don't use GetDepthTexture() to get the depth texture but m_CameraDepthStencilBuffer as the Forward transparent pass can
// write extra data to deal with DOF/MB
cmd.SetGlobalTexture(HDShaderIDs._CameraDepthTexture, m_CameraDepthStencilBuffer);
cmd.SetGlobalTexture(HDShaderIDs._CameraMotionVectorsTexture, m_VelocityBufferRT);
var context = hdcamera.postprocessRenderContext;
context.Reset();
context.source = m_CameraColorBufferRT;
context.destination = BuiltinRenderTextureType.CameraTarget;
context.command = cmd;
context.camera = hdcamera.camera;
context.sourceFormat = RenderTextureFormat.ARGBHalf;
context.flip = true;
var context = hdcamera.postprocessRenderContext;
context.Reset();
context.source = m_CameraColorBufferRT;
context.destination = BuiltinRenderTextureType.CameraTarget;
context.command = cmd;
context.camera = hdcamera.camera;
context.sourceFormat = RenderTextureFormat.ARGBHalf;
context.flip = true;
layer.Render(context);
}
}
else
{
using (new ProfilingSample(cmd, "Blit to final RT", GetSampler(CustomSamplerId.BlitToFinalRT)))
{
// Simple blit
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);
}
layer.Render(context);
m_ShadowSettings.enabled = m_FrameSettings.lightingSettings.enableShadow;
m_ShadowSettings.enabled = m_FrameSettings.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 (!m_FrameSettings.renderSettings.enableForwardRenderingOnly)
if (!m_FrameSettings.enableForwardRenderingOnly)
{
m_GbufferManager.InitGBuffers(w, h, m_DeferredMaterial, enableBakeShadowMask, cmd);
m_SSSBufferManager.InitSSSBuffersFromGBuffer(w, h, m_GbufferManager, cmd);

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

22
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.cs


}
// To be able to turn on/off FrameSettings properties at runtime for debugging purpose without affecting the original one
// we create a runtime copy (m_effectiveFrameSettings that is used, and any parametrization is done on serialized frameSettings)
public FrameSettings defaultFrameSettings = new FrameSettings(); // This are the defaultFrameSettings for all the camera and apply to sceneView, public to be visible in the inspector
// we create a runtime copy (m_ActiveFrameSettings that is used, and any parametrization is done on serialized frameSettings)
public FrameSettings serializedFrameSettings = new FrameSettings(); // This are the defaultFrameSettings for all the camera and apply to sceneView, public to be visible in the inspector
FrameSettings m_defaultEffectiveFrameSettings = new FrameSettings();
FrameSettings m_FrameSettings = new FrameSettings();
public FrameSettings GetEffectiveDefaultFrameSettings()
public FrameSettings GetFrameSettings()
return m_defaultEffectiveFrameSettings;
return m_FrameSettings;
}
public void OnValidate()

defaultFrameSettings.CopyTo(m_defaultEffectiveFrameSettings);
serializedFrameSettings.CopyTo(m_FrameSettings);
// Store the various GlobalFrameSettings for each platform (for now only one)
public GlobalFrameSettings globalFrameSettings = new GlobalFrameSettings();
// Store the various RenderPipelineSettings for each platform (for now only one)
public RenderPipelineSettings renderPipelineSettings = new RenderPipelineSettings();
// Return the current use GlobalFrameSettings (i.e for the current platform)
public GlobalFrameSettings GetGlobalFrameSettings()
// Return the current use RenderPipelineSettings (i.e for the current platform)
public RenderPipelineSettings GetRenderPipelineSettings()
return globalFrameSettings;
return renderPipelineSettings;
}
[SerializeField]

16
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


public bool GetFeatureVariantsEnabled()
{
return !m_FrameSettings.renderSettings.enableForwardRenderingOnly && m_FrameSettings.lightLoopSettings.isFptlEnabled && m_FrameSettings.lightLoopSettings.enableComputeLightEvaluation &&
return !m_FrameSettings.enableForwardRenderingOnly && m_FrameSettings.lightLoopSettings.isFptlEnabled && m_FrameSettings.lightLoopSettings.enableComputeLightEvaluation &&
(m_FrameSettings.lightLoopSettings.enableComputeLightVariants || m_FrameSettings.lightLoopSettings.enableComputeMaterialVariants);
}

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 = hdAsset.GetGlobalFrameSettings().lightLoopSettings;
GlobalLightLoopSettings gLightLoopSettings = hdAsset.GetRenderPipelineSettings().lightLoopSettings;
m_CookieTexArray = new TextureCache2D();
m_CookieTexArray.AllocTextureArray(gLightLoopSettings.cookieTexArraySize, gLightLoopSettings.spotCookieSize, gLightLoopSettings.spotCookieSize, TextureFormat.RGBA32, true);
m_CubeCookieTexArray = new TextureCacheCubemap();

UnityEditor.SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
InitShadowSystem(hdAsset.GetGlobalFrameSettings().shadowInitParams, shadowSettings);
InitShadowSystem(hdAsset.GetRenderPipelineSettings().shadowInitParams, shadowSettings);
}
public void Cleanup()

{
var directionalLightData = new DirectionalLightData();
float diffuseDimmer = m_FrameSettings.lightingSettings.diffuseGlobalDimmer * additionalData.lightDimmer;
float specularDimmer = m_FrameSettings.lightingSettings.specularGlobalDimmer * additionalData.lightDimmer;
float diffuseDimmer = m_FrameSettings.diffuseGlobalDimmer * additionalData.lightDimmer;
float specularDimmer = m_FrameSettings.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_FrameSettings.lightingSettings.diffuseGlobalDimmer : 0.0f;
lightData.specularScale = additionalLightData.affectSpecular ? lightScale * m_FrameSettings.lightingSettings.specularGlobalDimmer : 0.0f;
lightData.diffuseScale = additionalLightData.affectDiffuse ? lightScale * m_FrameSettings.diffuseGlobalDimmer : 0.0f;
lightData.specularScale = additionalLightData.affectSpecular ? lightScale * m_FrameSettings.specularGlobalDimmer : 0.0f;
if (lightData.diffuseScale <= 0.0f && lightData.specularScale <= 0.0f)
return false;

{
// 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 (!m_FrameSettings.lightingSettings.enableSSSAndTransmission)
if (!m_FrameSettings.enableSSSAndTransmission)
{
currentLightingMaterial.SetInt(HDShaderIDs._StencilRef, (int)StencilLightingUsage.NoLighting);
currentLightingMaterial.SetInt(HDShaderIDs._StencilCmp, (int)CompareFunction.NotEqual);

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


[Serializable]
public class LightLoopSettings
{
public static string kEnableTileCluster = "Enable Tile/Cluster";
public static string kEnableBigTile = "Enable Big Tile";
public static string kEnableComputeLighting = "Enable Compute Lighting";
public static string kEnableLightclassification = "Enable Light Classification";
public static string kEnableMaterialClassification = "Enable Material Classification";
// Setup by the users
public bool enableTileAndCluster = true;
public bool enableComputeLightEvaluation = true;

// aggregateFrameSettings already contain the aggregation of RenderPipelineSettings and FrameSettings (regular and/or debug)
static public LightLoopSettings InitializeLightLoopSettings(Camera camera, FrameSettings aggregateFrameSettings,
GlobalFrameSettings globalFrameSettings, FrameSettings frameSettings)
RenderPipelineSettings renderPipelineSettings, FrameSettings frameSettings)
{
LightLoopSettings aggregate = new LightLoopSettings();

// 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)
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && aggregateFrameSettings.renderSettings.enableMSAA;
aggregate.enableFptlForForwardOpaque = aggregate.enableFptlForForwardOpaque && aggregateFrameSettings.enableMSAA;
aggregate.isFptlEnabled = !aggregateFrameSettings.renderSettings.enableForwardRenderingOnly || aggregate.enableFptlForForwardOpaque;
aggregate.isFptlEnabled = !aggregateFrameSettings.enableForwardRenderingOnly || aggregate.enableFptlForForwardOpaque;
}
static public void RegisterDebug(String menuName, LightLoopSettings lightLoopSettings)
{
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableTileCluster, () => lightLoopSettings.enableTileAndCluster, (value) => lightLoopSettings.enableTileAndCluster = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableBigTile, () => lightLoopSettings.enableBigTilePrepass, (value) => lightLoopSettings.enableBigTilePrepass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableComputeLighting, () => lightLoopSettings.enableComputeLightEvaluation, (value) => lightLoopSettings.enableComputeLightEvaluation = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableLightclassification, () => lightLoopSettings.enableComputeLightVariants, (value) => lightLoopSettings.enableComputeLightVariants = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableMaterialClassification, () => lightLoopSettings.enableComputeMaterialVariants, (value) => lightLoopSettings.enableComputeMaterialVariants = (bool)value);
}
static public void UnRegisterDebug(String menuName)
{
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableTileCluster);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableBigTile);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableComputeLighting);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableLightclassification);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableMaterialClassification);
}
}
}

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


public void PushGlobalParams(CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters, FrameSettings frameSettings)
{
// Broadcast SSS parameters to all shaders.
cmd.SetGlobalInt(HDShaderIDs._EnableSSSAndTransmission, frameSettings.lightingSettings.enableSSSAndTransmission ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._EnableSSSAndTransmission, frameSettings.enableSSSAndTransmission ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._UseDisneySSS, sssParameters.useDisneySSS ? 1 : 0);
unsafe
{

public void SubsurfaceScatteringPass(HDCamera hdCamera, CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters, FrameSettings frameSettings,
RenderTargetIdentifier colorBufferRT, RenderTargetIdentifier diffuseBufferRT, RenderTargetIdentifier depthStencilBufferRT, RenderTargetIdentifier depthTextureRT)
{
if (sssParameters == null || !frameSettings.lightingSettings.enableSSSAndTransmission)
if (sssParameters == null || !frameSettings.enableSSSAndTransmission)
return;
using (new ProfilingSample(cmd, "Subsurface Scattering", HDRenderPipeline.GetSampler(CustomSamplerId.SubsurfaceScattering)))

286
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
// The settings here are per frame settings.
// Each camera must have its own per frame settings
[Serializable]
public class LightingSettings
{
// Setup by users
public bool enableShadow = true;
public bool enableSSR = true; // Depends on DepthPyramid
public bool enableSSAO = true;
public bool enableSSSAndTransmission = true;
public static string kEnableShadow = "Enable Shadow";
public static string kEnableSSR = "Enable SSR";
public static string kEnableSSAO = "Enable SSAO";
public static string kEnableSSSAndTransmission = "Enable SSS and Transmission";
// Setup by system
public float diffuseGlobalDimmer = 1.0f;
public float specularGlobalDimmer = 1.0f;
}
public static string kForwardOnly = "Forward Only";
public static string kDeferredDepthPrePass = "Deferred Depth Prepass";
public static string kDeferredDepthPrepassATestOnly = "Deferred Depth Prepass ATest Only";
[Serializable]
public class RenderSettings
{
// 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;
public static string KEnableTransparentPrepass = "Enable Transparent Prepass";
public static string kEnableMotionVectors = "Enable Motion Vectors";
public static string KEnableObjectMotionVectors = "Enable Object Motion Vectors";
public static string kEnableDBuffer = "Enable DBuffer";
public static string kEnableAtmosphericScattering = "Enable Atmospheric Scattering";
public static string kEnableRoughRefraction = "Enable Rough Refraction";
public static string kEnableTransparentPostpass = "Enable Transparent Postpass";
public static string kEnableDistortion = "Enable Distortion";
public static string kEnablePostprocess = "Enable Postprocess";
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;
public static string kEnableStereoRendering = "Enable Stereo Rendering";
public static string kEnableAsyncCompute = "Enable Async Compute";
public static string kEnableOpaqueObjects = "Enable Opaque Objects";
public static string kEnableTransparentObjects = "Enable Transparent Objects";
public static string kEnableMSAA = "Enable MSAA";
public static string kEnableShadowMask = "Enable ShadowMask";
// Lighting
// Setup by users
public bool enableShadow = true;
public bool enableSSR = true; // Depends on DepthPyramid
public bool enableSSAO = true;
public bool enableSSSAndTransmission = true;
// Setup by system
public float diffuseGlobalDimmer = 1.0f;
public float specularGlobalDimmer = 1.0f;
// View
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;
public bool enableTransparentPrePass = true;
public bool enableMotionVectors = true; // Enable/disable whole motion vectors pass (Camera + Object).
public bool enableObjectMotionVectors = 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;
public bool enableStereo = false;
public bool enableAsyncCompute = false;
public bool enableStereo = false;
public bool enableAsyncCompute = false;
public bool enableOpaqueObjects = true;
public bool enableTransparentObjects = true;
public bool enableOpaqueObjects = true;
public bool enableTransparentObjects = true;
public bool enableMSAA = false;
public bool enableMSAA = false;
// Setup by system
public bool enableShadowMask = false;
}
public bool enableShadowMask = false;
public LightingSettings lightingSettings = new LightingSettings();
public RenderSettings renderSettings = new RenderSettings();
frameSettings.lightingSettings.enableShadow = this.lightingSettings.enableShadow;
frameSettings.lightingSettings.enableSSR = this.lightingSettings.enableSSR;
frameSettings.lightingSettings.enableSSAO = this.lightingSettings.enableSSAO;
frameSettings.lightingSettings.enableSSSAndTransmission = this.lightingSettings.enableSSSAndTransmission;
frameSettings.enableShadow = this.enableShadow;
frameSettings.enableSSR = this.enableSSR;
frameSettings.enableSSAO = this.enableSSAO;
frameSettings.enableSSSAndTransmission = this.enableSSSAndTransmission;
frameSettings.lightingSettings.diffuseGlobalDimmer = this.lightingSettings.diffuseGlobalDimmer;
frameSettings.lightingSettings.specularGlobalDimmer = this.lightingSettings.specularGlobalDimmer;
frameSettings.diffuseGlobalDimmer = this.diffuseGlobalDimmer;
frameSettings.specularGlobalDimmer = this.specularGlobalDimmer;
frameSettings.renderSettings.enableForwardRenderingOnly = this.renderSettings.enableForwardRenderingOnly;
frameSettings.renderSettings.enableDepthPrepassWithDeferredRendering = this.renderSettings.enableDepthPrepassWithDeferredRendering;
frameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass = this.renderSettings.enableAlphaTestOnlyInDeferredPrepass;
frameSettings.enableForwardRenderingOnly = this.enableForwardRenderingOnly;
frameSettings.enableDepthPrepassWithDeferredRendering = this.enableDepthPrepassWithDeferredRendering;
frameSettings.enableAlphaTestOnlyInDeferredPrepass = this.enableAlphaTestOnlyInDeferredPrepass;
frameSettings.renderSettings.enableTransparentPrePass = this.renderSettings.enableTransparentPrePass;
frameSettings.renderSettings.enableMotionVectors = this.renderSettings.enableMotionVectors;
frameSettings.renderSettings.enableDBuffer = this.renderSettings.enableDBuffer;
frameSettings.renderSettings.enableAtmosphericScattering = this.renderSettings.enableAtmosphericScattering;
frameSettings.renderSettings.enableRoughRefraction = this.renderSettings.enableRoughRefraction;
frameSettings.renderSettings.enableTransparentPostPass = this.renderSettings.enableTransparentPostPass;
frameSettings.renderSettings.enableDistortion = this.renderSettings.enableDistortion;
frameSettings.renderSettings.enablePostprocess = this.renderSettings.enablePostprocess;
frameSettings.enableTransparentPrePass = this.enableTransparentPrePass;
frameSettings.enableMotionVectors = this.enableMotionVectors;
frameSettings.enableObjectMotionVectors = this.enableObjectMotionVectors;
frameSettings.enableDBuffer = this.enableDBuffer;
frameSettings.enableAtmosphericScattering = this.enableAtmosphericScattering;
frameSettings.enableRoughRefraction = this.enableRoughRefraction;
frameSettings.enableTransparentPostPass = this.enableTransparentPostPass;
frameSettings.enableDistortion = this.enableDistortion;
frameSettings.enablePostprocess = this.enablePostprocess;
frameSettings.renderSettings.enableStereo = this.renderSettings.enableStereo;
frameSettings.renderSettings.enableForwardRenderingOnly = this.renderSettings.enableForwardRenderingOnly;
frameSettings.enableStereo = this.enableStereo;
frameSettings.enableForwardRenderingOnly = this.enableForwardRenderingOnly;
frameSettings.renderSettings.enableOpaqueObjects = this.renderSettings.enableOpaqueObjects;
frameSettings.renderSettings.enableTransparentObjects = this.renderSettings.enableTransparentObjects;
frameSettings.enableOpaqueObjects = this.enableOpaqueObjects;
frameSettings.enableTransparentObjects = this.enableTransparentObjects;
frameSettings.renderSettings.enableAsyncCompute = this.renderSettings.enableAsyncCompute;
frameSettings.enableAsyncCompute = this.enableAsyncCompute;
frameSettings.renderSettings.enableMSAA = this.renderSettings.enableMSAA;
frameSettings.enableMSAA = this.enableMSAA;
frameSettings.renderSettings.enableShadowMask = this.renderSettings.enableShadowMask;
frameSettings.enableShadowMask = this.enableShadowMask;
this.lightLoopSettings.CopyTo(frameSettings.lightLoopSettings);
}

static public FrameSettings InitializeFrameSettings(Camera camera, GlobalFrameSettings globalFrameSettings, FrameSettings frameSettings)
static public FrameSettings InitializeFrameSettings(Camera camera, RenderPipelineSettings renderPipelineSettings, FrameSettings frameSettings)
{
FrameSettings aggregate = new FrameSettings();

aggregate.lightingSettings.diffuseGlobalDimmer = 1.0f;
aggregate.lightingSettings.specularGlobalDimmer = 0.0f;
aggregate.diffuseGlobalDimmer = 1.0f;
aggregate.specularGlobalDimmer = 0.0f;
aggregate.lightingSettings.diffuseGlobalDimmer = 1.0f;
aggregate.lightingSettings.specularGlobalDimmer = 1.0f;
aggregate.diffuseGlobalDimmer = 1.0f;
aggregate.specularGlobalDimmer = 1.0f;
aggregate.lightingSettings.enableShadow = frameSettings.lightingSettings.enableShadow;
aggregate.lightingSettings.enableSSR = camera.cameraType == CameraType.Reflection ? false : frameSettings.lightingSettings.enableSSR && globalFrameSettings.lightingSettings.supportSSR;
aggregate.lightingSettings.enableSSAO = frameSettings.lightingSettings.enableSSAO && globalFrameSettings.lightingSettings.supportSSAO;
aggregate.lightingSettings.enableSSSAndTransmission = camera.cameraType == CameraType.Reflection ? false : frameSettings.lightingSettings.enableSSSAndTransmission && globalFrameSettings.lightingSettings.supportSSSAndTransmission;
aggregate.enableShadow = frameSettings.enableShadow;
aggregate.enableSSR = camera.cameraType == CameraType.Reflection ? false : frameSettings.enableSSR && renderPipelineSettings.supportSSR;
aggregate.enableSSAO = frameSettings.enableSSAO && renderPipelineSettings.supportSSAO;
aggregate.enableSSSAndTransmission = camera.cameraType == CameraType.Reflection ? false : frameSettings.enableSSSAndTransmission && renderPipelineSettings.supportSSSAndTransmission;
aggregate.renderSettings.enableForwardRenderingOnly = frameSettings.renderSettings.enableForwardRenderingOnly || GL.wireframe;
aggregate.renderSettings.enableDepthPrepassWithDeferredRendering = frameSettings.renderSettings.enableDepthPrepassWithDeferredRendering;
aggregate.renderSettings.enableAlphaTestOnlyInDeferredPrepass = frameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass;
aggregate.enableForwardRenderingOnly = frameSettings.enableForwardRenderingOnly || GL.wireframe;
aggregate.enableDepthPrepassWithDeferredRendering = frameSettings.enableDepthPrepassWithDeferredRendering;
aggregate.enableAlphaTestOnlyInDeferredPrepass = frameSettings.enableAlphaTestOnlyInDeferredPrepass;
aggregate.renderSettings.enableTransparentPrePass = frameSettings.renderSettings.enableTransparentPrePass;
aggregate.renderSettings.enableMotionVectors = camera.cameraType == CameraType.Reflection ? false : 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 = camera.cameraType == CameraType.Reflection ? false : frameSettings.renderSettings.enableDistortion;
aggregate.enableTransparentPrePass = frameSettings.enableTransparentPrePass;
aggregate.enableMotionVectors = camera.cameraType == CameraType.Reflection ? false : frameSettings.enableMotionVectors;
aggregate.enableObjectMotionVectors = camera.cameraType == CameraType.Reflection ? false : frameSettings.enableObjectMotionVectors;
aggregate.enableDBuffer = frameSettings.enableDBuffer && renderPipelineSettings.supportDBuffer;
aggregate.enableAtmosphericScattering = frameSettings.enableAtmosphericScattering;
aggregate.enableRoughRefraction = frameSettings.enableRoughRefraction;
aggregate.enableTransparentPostPass = frameSettings.enableTransparentPostPass;
aggregate.enableDistortion = camera.cameraType == CameraType.Reflection ? false : frameSettings.enableDistortion;
aggregate.renderSettings.enablePostprocess = camera.cameraType == CameraType.Reflection ? false : frameSettings.renderSettings.enablePostprocess;
aggregate.enablePostprocess = camera.cameraType == CameraType.Reflection ? false : frameSettings.enablePostprocess;
aggregate.renderSettings.enableStereo = camera.cameraType == CameraType.Reflection ? false : frameSettings.renderSettings.enableStereo && UnityEngine.XR.XRSettings.isDeviceActive && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
aggregate.enableStereo = camera.cameraType == CameraType.Reflection ? false : frameSettings.enableStereo && UnityEngine.XR.XRSettings.isDeviceActive && (camera.stereoTargetEye == StereoTargetEyeMask.Both);
aggregate.renderSettings.enableForwardRenderingOnly = aggregate.renderSettings.enableForwardRenderingOnly || aggregate.renderSettings.enableStereo;
aggregate.enableForwardRenderingOnly = aggregate.enableForwardRenderingOnly || aggregate.enableStereo;
aggregate.renderSettings.enableAsyncCompute = frameSettings.renderSettings.enableAsyncCompute;
aggregate.enableAsyncCompute = frameSettings.enableAsyncCompute && renderPipelineSettings.supportAsyncCompute;
aggregate.renderSettings.enableOpaqueObjects = frameSettings.renderSettings.enableOpaqueObjects;
aggregate.renderSettings.enableTransparentObjects = frameSettings.renderSettings.enableTransparentObjects;
aggregate.enableOpaqueObjects = frameSettings.enableOpaqueObjects;
aggregate.enableTransparentObjects = frameSettings.enableTransparentObjects;
aggregate.renderSettings.enableMSAA = frameSettings.renderSettings.enableMSAA && globalFrameSettings.renderSettings.supportMSAA;
aggregate.enableMSAA = frameSettings.enableMSAA && renderPipelineSettings.supportMSAA;
aggregate.renderSettings.enableShadowMask = globalFrameSettings.lightingSettings.supportShadowMask;
aggregate.enableShadowMask = renderPipelineSettings.supportShadowMask;
aggregate.lightLoopSettings = LightLoopSettings.InitializeLightLoopSettings(camera, aggregate, globalFrameSettings, frameSettings);
aggregate.lightLoopSettings = LightLoopSettings.InitializeLightLoopSettings(camera, aggregate, renderPipelineSettings, frameSettings);
return aggregate;
}

// Register the camera into the debug menu
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Shadow", () => frameSettings.lightingSettings.enableShadow, (value) => frameSettings.lightingSettings.enableShadow = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable SSR", () => frameSettings.lightingSettings.enableSSR, (value) => frameSettings.lightingSettings.enableSSR = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable SSAO", () => frameSettings.lightingSettings.enableSSR, (value) => frameSettings.lightingSettings.enableSSR = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable SSS and Transmission", () => frameSettings.lightingSettings.enableSSSAndTransmission, (value) => frameSettings.lightingSettings.enableSSSAndTransmission = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableShadow, () => frameSettings.enableShadow, (value) => frameSettings.enableShadow = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableSSR, () => frameSettings.enableSSR, (value) => frameSettings.enableSSR = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableSSAO, () => frameSettings.enableSSAO, (value) => frameSettings.enableSSAO = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableSSSAndTransmission, () => frameSettings.enableSSSAndTransmission, (value) => frameSettings.enableSSSAndTransmission = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kForwardOnly, () => frameSettings.enableForwardRenderingOnly, (value) => frameSettings.enableForwardRenderingOnly = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kDeferredDepthPrepassATestOnly, () => frameSettings.enableDepthPrepassWithDeferredRendering, (value) => frameSettings.enableDepthPrepassWithDeferredRendering = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, KEnableTransparentPrepass, () => frameSettings.enableAlphaTestOnlyInDeferredPrepass, (value) => frameSettings.enableAlphaTestOnlyInDeferredPrepass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, KEnableTransparentPrepass, () => frameSettings.enableTransparentPrePass, (value) => frameSettings.enableTransparentPrePass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableMotionVectors, () => frameSettings.enableMotionVectors, (value) => frameSettings.enableMotionVectors = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, KEnableObjectMotionVectors, () => frameSettings.enableObjectMotionVectors, (value) => frameSettings.enableObjectMotionVectors = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableDBuffer, () => frameSettings.enableDBuffer, (value) => frameSettings.enableDBuffer = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableAtmosphericScattering, () => frameSettings.enableAtmosphericScattering, (value) => frameSettings.enableAtmosphericScattering = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableRoughRefraction, () => frameSettings.enableRoughRefraction, (value) => frameSettings.enableRoughRefraction = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableTransparentPostpass, () => frameSettings.enableTransparentPostPass, (value) => frameSettings.enableTransparentPostPass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableDistortion, () => frameSettings.enableDistortion, (value) => frameSettings.enableDistortion = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnablePostprocess, () => frameSettings.enablePostprocess, (value) => frameSettings.enablePostprocess = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Forward Only", () => frameSettings.renderSettings.enableForwardRenderingOnly, (value) => frameSettings.renderSettings.enableForwardRenderingOnly = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Deferred Depth Prepass", () => frameSettings.renderSettings.enableDepthPrepassWithDeferredRendering, (value) => frameSettings.renderSettings.enableDepthPrepassWithDeferredRendering = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Deferred Depth Prepass ATest Only", () => frameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass, (value) => frameSettings.renderSettings.enableAlphaTestOnlyInDeferredPrepass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableStereoRendering, () => frameSettings.enableStereo, (value) => frameSettings.enableStereo = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableAsyncCompute, () => frameSettings.enableAsyncCompute, (value) => frameSettings.enableAsyncCompute = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableOpaqueObjects, () => frameSettings.enableOpaqueObjects, (value) => frameSettings.enableOpaqueObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableTransparentObjects, () => frameSettings.enableTransparentObjects, (value) => frameSettings.enableTransparentObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableMSAA, () => frameSettings.enableMSAA, (value) => frameSettings.enableMSAA = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, kEnableShadowMask, () => frameSettings.enableShadowMask, (value) => frameSettings.enableShadowMask = (bool)value);
LightLoopSettings.RegisterDebug(menuName, frameSettings.lightLoopSettings);
}
static public void UnRegisterDebug(String menuName)
{
// Register the camera into the debug menu
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableShadow);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableSSR);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableSSAO);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableSSSAndTransmission);
DebugMenuManager.instance.RemoveDebugItem(menuName, kForwardOnly);
DebugMenuManager.instance.RemoveDebugItem(menuName, kDeferredDepthPrepassATestOnly);
DebugMenuManager.instance.RemoveDebugItem(menuName, KEnableTransparentPrepass);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Transparent Prepass", () => frameSettings.renderSettings.enableTransparentPrePass, (value) => frameSettings.renderSettings.enableTransparentPrePass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Motion Vectors", () => frameSettings.renderSettings.enableMotionVectors, (value) => frameSettings.renderSettings.enableMotionVectors = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable DBuffer", () => frameSettings.renderSettings.enableDBuffer, (value) => frameSettings.renderSettings.enableDBuffer = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Atmospheric Scattering", () => frameSettings.renderSettings.enableAtmosphericScattering, (value) => frameSettings.renderSettings.enableAtmosphericScattering = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Rough Refraction", () => frameSettings.renderSettings.enableRoughRefraction, (value) => frameSettings.renderSettings.enableRoughRefraction = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Transparent Postpass", () => frameSettings.renderSettings.enableTransparentPostPass, (value) => frameSettings.renderSettings.enableTransparentPostPass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Distortion", () => frameSettings.renderSettings.enableDistortion, (value) => frameSettings.renderSettings.enableDistortion = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Postprocess", () => frameSettings.renderSettings.enablePostprocess, (value) => frameSettings.renderSettings.enablePostprocess = (bool)value);
DebugMenuManager.instance.RemoveDebugItem(menuName, KEnableTransparentPrepass);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableMotionVectors);
DebugMenuManager.instance.RemoveDebugItem(menuName, KEnableObjectMotionVectors);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableDBuffer);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableAtmosphericScattering);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableRoughRefraction);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableTransparentPostpass);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableDistortion);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnablePostprocess);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Stereo Rendering", () => frameSettings.renderSettings.enableStereo, (value) => frameSettings.renderSettings.enableStereo = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Async Compute", () => frameSettings.renderSettings.enableAsyncCompute, (value) => frameSettings.renderSettings.enableAsyncCompute = (bool)value);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableStereoRendering);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableAsyncCompute);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Opaque Objects", () => frameSettings.renderSettings.enableOpaqueObjects, (value) => frameSettings.renderSettings.enableOpaqueObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Transparent Objects", () => frameSettings.renderSettings.enableTransparentObjects, (value) => frameSettings.renderSettings.enableTransparentObjects = (bool)value);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableOpaqueObjects);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableTransparentObjects);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable MSAA", () => frameSettings.renderSettings.enableMSAA, (value) => frameSettings.renderSettings.enableMSAA = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable ShadowMask", () => frameSettings.renderSettings.enableShadowMask, (value) => frameSettings.renderSettings.enableShadowMask = (bool)value);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableMSAA);
DebugMenuManager.instance.RemoveDebugItem(menuName, kEnableShadowMask);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Tile/Cluster", () => frameSettings.lightLoopSettings.enableTileAndCluster, (value) => frameSettings.lightLoopSettings.enableTileAndCluster = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Big Tile", () => frameSettings.lightLoopSettings.enableBigTilePrepass, (value) => frameSettings.lightLoopSettings.enableBigTilePrepass = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Compute Lighting", () => frameSettings.lightLoopSettings.enableComputeLightEvaluation, (value) => frameSettings.lightLoopSettings.enableComputeLightEvaluation = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Light Classification", () => frameSettings.lightLoopSettings.enableComputeLightVariants, (value) => frameSettings.lightLoopSettings.enableComputeLightVariants = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>(menuName, "Enable Material Classification", () => frameSettings.lightLoopSettings.enableComputeMaterialVariants, (value) => frameSettings.lightLoopSettings.enableComputeMaterialVariants = (bool)value);
LightLoopSettings.UnRegisterDebug(menuName);
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs.meta


fileFormatVersion: 2
guid: 19f344eae864d8a49a57cc3d20dc61fc
guid: 189e7ccf6292277448e6cecbfead78b8
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs


public void PushShaderParameters(CommandBuffer cmd, FrameSettings frameSettings)
{
if(frameSettings.renderSettings.enableAtmosphericScattering)
if(frameSettings.enableAtmosphericScattering)
cmd.SetGlobalFloat(m_TypeParam, (float)type);
else
cmd.SetGlobalFloat(m_TypeParam, (float)FogType.None);

36
ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs


using System;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// RenderPipelineSettings define settings that can't be change during runtime. It is equivalent to the GraphicsSettings of Unity (Tiers + shader variant removal).
// This allow to allocate resource or not for a given feature.
// FrameSettings control within a frame what is enable or not(enableShadow, enableStereo, enableDistortion...).
// HDRenderPipelineAsset reference the current RenderPipelineSettings use, there is one per supported platform(Currently this feature is not implemented and only one GlobalFrameSettings is available).
// A Camera with HDAdditionalData have one FrameSettings that configure how it will render.For example a camera use for reflection will disable distortion and postprocess.
// Additionally on a Camera there is another FrameSettings call ActiveFrameSettings that is created on the fly based on FrameSettings and allow modification for debugging purpose at runtime without being serialized on disk.
// The ActiveFrameSettings is register in the debug windows at the creation of the camera.
// A Camera with HDAdditionalData have a RenderPath that define if it use a "Default" FrameSettings, a preset of FrameSettings or a custom one.
// HDRenderPipelineAsset contain a "Default" FrameSettings that can be reference by any camera with RenderPath.Defaut or when the camera don't have HDAdditionalData like the camera of the Editor.
// It also contain a DefaultActiveFrameSettings
// RenderPipelineSettings represent settings that are immutable at runtime.
// There is a dedicated RenderPipelineSettings for each platform
[Serializable]
public class RenderPipelineSettings
{
// Lighting
public bool supportShadowMask = true;
public bool supportSSR = true;
public bool supportSSAO = true;
public bool supportSSSAndTransmission = true;
// Engine
public bool supportDBuffer = false;
public bool supportMSAA = false;
public bool supportAsyncCompute = false;
public GlobalLightLoopSettings lightLoopSettings = new GlobalLightLoopSettings();
public ShadowInitParameters shadowInitParams = new ShadowInitParameters();
}
}

43
ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/GlobalFrameSettings.cs


using System;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// GlobalFrameSettings define settings that can't be change during runtime. It is equivalent to the GraphicsSettings of Unity (Tiers + shader variant removal).
// This allow to allocate resource or not for a given feature.
// FrameSettings control within a frame what is enable or not(enableShadow, enableStereo, enableDistortion...).
// HDRenderPipelineAsset reference the current GlobalFrameSettings use, there is one per supported platform(Currently this feature is not implemented and only one GlobalFrameSettings is available).
// A Camera with HDAdditionalData have one FrameSettings that configure how it will render.For example a camera use for reflection will disable distortion and postprocess.
// Additionaly on a Camera there is another Framesettings call EffectiveFrameSettings that is created on the fly based on FrameSettings and allow modificaiton for debugging purpose at runtime without being serialized on disk.
// The EffectiveFrameSettings is register in the debug windows at the creation of the camera.
// A Camera with HDAdditionalData have a RenderPath that define if it use a "Default" FrameSettings, a preset of FrameSettings or a custom one.
// HDRenderPipelineAsset contain a "Default" FrameSettings that can be reference by any camera with RenderPath.Defaut or when the camera don't have HDAdditionalData like the camera of the Editor.
// It also contain a DefaultEffectiveFrameSettings
// GlobalFrameSettings represent settings that are immutable at runtime.
// There is a dedicated RenderRenderPipelineSettings for each platform
[Serializable]
public class GlobalFrameSettings
{
[Serializable]
public class GlobalLightingSettings
{
public bool supportShadowMask = true;
public bool supportSSR = true;
public bool supportSSAO = true;
public bool supportSSSAndTransmission = true;
}
[Serializable]
public class GlobalRenderSettings
{
public bool supportDBuffer = false;
public bool supportMSAA = false;
}
public GlobalLightingSettings lightingSettings = new GlobalLightingSettings();
public GlobalRenderSettings renderSettings = new GlobalRenderSettings();
public GlobalLightLoopSettings lightLoopSettings = new GlobalLightLoopSettings();
public ShadowInitParameters shadowInitParams = new ShadowInitParameters();
}
}

35
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineSettings.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// All the structures here represent global engine settings.
// It means that they are supposed to be setup once and not changed during the game.
// All of these will be serialized in the HDRenderPipelineInstance used for the project.
[Serializable]
public class GlobalTextureSettings
{
public const int kHDDefaultSpotCookieSize = 128;
public const int kHDDefaultPointCookieSize = 512;
public const int kHDDefaultReflectionCubemapSize = 128;
public int spotCookieSize = kHDDefaultSpotCookieSize;
public int pointCookieSize = kHDDefaultPointCookieSize;
public int reflectionCubemapSize = kHDDefaultReflectionCubemapSize;
public bool reflectionCacheCompressed = false;
}
[Serializable]
public class GlobalRenderingSettings
{
public bool supportShadowMask;
public bool supportSSSAndTransmission;
public bool supportDBuffer;
public bool supportSSR;
public bool supportSSAO;
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineSettings.cs.meta


fileFormatVersion: 2
guid: c10772362225f1341a0ca4b3e29f5a6c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/GlobalFrameSettings.cs.meta → /ScriptableRenderPipeline/HDRenderPipeline/RenderPipeline/RenderPipelineSettings.cs.meta

正在加载...
取消
保存