浏览代码

Merge pull request #582 from Unity-Technologies/cleanup-parameter-setup-compute-code

Cleanup parameter setup compute code
/main
GitHub 7 年前
当前提交
cc38a4f9
共有 7 个文件被更改,包括 211 次插入369 次删除
  1. 8
      ScriptableRenderPipeline/Core/ProfilingSample.cs
  2. 14
      ScriptableRenderPipeline/HDRenderPipeline/Camera/HDCamera.cs
  3. 173
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  4. 313
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  6. 55
      ScriptableRenderPipeline/HDRenderPipeline/HDCustomSamplerId.cs
  7. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDCustomSamplerId.cs.meta

8
ScriptableRenderPipeline/Core/ProfilingSample.cs


{
public struct ProfilingSample : IDisposable
{
CommandBuffer m_Cmd;
string m_Name;
readonly CommandBuffer m_Cmd;
readonly string m_Name;
public ProfilingSample(CommandBuffer cmd, string name,CustomSampler sampler=null)
public ProfilingSample(CommandBuffer cmd, string name,CustomSampler sampler = null)
{
m_Cmd = cmd;
m_Name = name;

if ( m_Sampler != null )
if (m_Sampler != null)
m_Sampler.Begin();
}

14
ScriptableRenderPipeline/HDRenderPipeline/Camera/HDCamera.cs


material.SetVectorArray(HDShaderIDs._FrustumPlanes, frustumPlaneEquations);
}
// TODO: We should set all the value below globally and not let it under the control of Unity,
// Need to test that because we are not sure in which order these value are setup, but we need to have control on them, or rename them in our shader.
// For now, apply it for all our compute shader to make it work
cmd.SetComputeMatrixParam(cs, HDShaderIDs._ViewMatrix, viewMatrix);
cmd.SetComputeMatrixParam(cs, HDShaderIDs._InvViewMatrix, viewMatrix.inverse);
cmd.SetComputeMatrixParam(cs, HDShaderIDs._ProjMatrix, projMatrix);
cmd.SetComputeMatrixParam(cs, HDShaderIDs._InvProjMatrix, projMatrix.inverse);
cmd.SetComputeMatrixParam(cs, HDShaderIDs._NonJitteredViewProjMatrix, nonJitteredViewProjMatrix);
cmd.SetComputeMatrixParam(cs, HDShaderIDs._ViewProjMatrix, viewProjMatrix);
cmd.SetComputeMatrixParam(cs, HDShaderIDs._InvViewProjMatrix, viewProjMatrix.inverse);
cmd.SetComputeVectorParam(cs, HDShaderIDs._InvProjParam, invProjParam);
cmd.SetComputeVectorParam(cs, HDShaderIDs._ScreenSize, screenSize);
cmd.SetComputeMatrixParam(cs, HDShaderIDs._PrevViewProjMatrix, prevViewProjMatrix);
cmd.SetComputeVectorArrayParam(cs, HDShaderIDs._FrustumPlanes, frustumPlaneEquations);
// Copy values set by Unity which are not configured in scripts.
cmd.SetComputeVectorParam(cs, HDShaderIDs.unity_OrthoParams, Shader.GetGlobalVector(HDShaderIDs.unity_OrthoParams));
cmd.SetComputeVectorParam(cs, HDShaderIDs._ProjectionParams, Shader.GetGlobalVector(HDShaderIDs._ProjectionParams));

173
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


Transparent
}
public enum CustomSamplerId
{
PushGlobal_Parameters,
Copy_SetDepthBuffer,
Copydepth_stencilbuffer,
Copy_StencilBuffer,
Forward,
Build_Light_list_and_render_shadows,
Blit_to_final_RT,
Distortion,
ApplyDistortion,
Depth_Prepass,
GBuffer,
DisplayDebug_ViewMaterial,
DebugViewMaterialGBuffer,
Blit_DebugView_Material_Debug,
Subsurface_Scattering,
ForwardPassName,
Forward_Transparent_Depth_Prepass,
Render_Forward_Error,
Velocity,
Gaussian_Pyramid_Color,
Pyramid_Depth,
Post_processing,
Render_Debug,
InitAndClearBuffer,
InitGBuffers_and_clear_Depth_Stencil,
Clear_SSS_diffuse_target,
Clear_SSS_filtering_target,
Clear_stencil_texture,
Clear_HTile,
Clear_HDR_target,
Clear_GBuffer,
HDRenderPipeline_Render,
CullResults_Cull,
TP_PrepareLightsForGPU,
TP_Push_Global_Parameters,
TP_Tiled_Lighting_Debug,
TP_Deferred_Directional,
TP_m_TileSettings_enableTileAndCluster,
TP_Forward_pass,
TP_Forward_Tiled_Cluster_pass,
TP_Display_Shadows,
TP_RenderDeferredLighting,
Max
}
static readonly string[] k_ForwardPassDebugName =
{
"Forward Opaque Debug Display",

RenderTargetIdentifier m_CameraStencilBufferCopyRT;
RenderTargetIdentifier m_HTileRT;
static CustomSampler[] m_samplers = new CustomSampler[ (int)CustomSamplerId.Max ];
static CustomSampler[] m_samplers = new CustomSampler[(int)CustomSamplerId.Max];
// The pass "SRPDefaultUnlit" is a fall back to legacy unlit rendering and is required to support unity 2d + unity UI that render in the scene.
ShaderPassName[] m_ForwardAndForwardOnlyPassNames = { new ShaderPassName(), new ShaderPassName(), HDShaderPassNames.s_SRPDefaultUnlitName};

CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;
SkySettings m_SkySettings = null;
static public CustomSampler GetSampler( CustomSamplerId id )
static public CustomSampler GetSampler(CustomSamplerId id)
{
return m_samplers[(int)id];
}

// Init all samplers
for (int i=0;i<(int)CustomSamplerId.Max;i++)
for (int i = 0; i < (int)CustomSamplerId.Max; i++)
m_samplers[i] = CustomSampler.Create("C#_"+id.ToString());
m_samplers[i] = CustomSampler.Create("C#_" + id.ToString());
}
InitializeRenderStateBlocks();

public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters)
{
using (new ProfilingSample(cmd, "Push Global Parameters", GetSampler(CustomSamplerId.PushGlobal_Parameters)))
using (new ProfilingSample(cmd, "Push Global Parameters", GetSampler(CustomSamplerId.PushGlobalParameters)))
// TODO: cmd.SetGlobalInt() does not exist, so we are forced to use Shader.SetGlobalInt() instead.
m_SkyManager.SetGlobalSkyTexture();
Shader.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 1);
m_SkyManager.SetGlobalSkyTexture(cmd);
cmd.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 1);
Shader.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 0);
cmd.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 0);
Shader.SetGlobalInt( HDShaderIDs._EnableSSSAndTransmission, m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission ? 1 : 0);
Shader.SetGlobalInt( HDShaderIDs._TexturingModeFlags, sssParameters.texturingModeFlags);
Shader.SetGlobalInt( HDShaderIDs._TransmissionFlags, sssParameters.transmissionFlags);
Shader.SetGlobalInt( HDShaderIDs._UseDisneySSS, sssParameters.useDisneySSS ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._EnableSSSAndTransmission, m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission ? 1 : 0);
cmd.SetGlobalInt(HDShaderIDs._TexturingModeFlags, sssParameters.texturingModeFlags);
cmd.SetGlobalInt(HDShaderIDs._TransmissionFlags, sssParameters.transmissionFlags);
cmd.SetGlobalInt(HDShaderIDs._UseDisneySSS, sssParameters.useDisneySSS ? 1 : 0);
cmd.SetGlobalVectorArray(HDShaderIDs._ThicknessRemaps, sssParameters.thicknessRemaps);
cmd.SetGlobalVectorArray(HDShaderIDs._ShapeParams, sssParameters.shapeParams);
cmd.SetGlobalVectorArray(HDShaderIDs._HalfRcpVariancesAndWeights, sssParameters.halfRcpVariancesAndWeights);

void CopyDepthBufferIfNeeded(CommandBuffer cmd)
{
using (new ProfilingSample(cmd, NeedDepthBufferCopy() ? "Copy DepthBuffer" : "Set DepthBuffer",GetSampler(CustomSamplerId.Copy_SetDepthBuffer)))
using (new ProfilingSample(cmd, NeedDepthBufferCopy() ? "Copy DepthBuffer" : "Set DepthBuffer", GetSampler(CustomSamplerId.CopySetDepthBuffer)))
using (new ProfilingSample(cmd, "Copy depth-stencil buffer",GetSampler(CustomSamplerId.Copydepth_stencilbuffer)))
using (new ProfilingSample(cmd, "Copy depth-stencil buffer", GetSampler(CustomSamplerId.CopyDepthStencilbuffer)))
{
cmd.CopyTexture(m_CameraDepthStencilBufferRT, m_CameraDepthBufferCopyRT);
}

{
if (NeedStencilBufferCopy())
{
using (new ProfilingSample(cmd, "Copy StencilBuffer",GetSampler(CustomSamplerId.Copy_StencilBuffer)))
using (new ProfilingSample(cmd, "Copy StencilBuffer", GetSampler(CustomSamplerId.CopyStencilBuffer)))
{
cmd.SetRandomWriteTarget(1, GetHTile());
// Our method of exporting the stencil requires one pass per unique stencil value.

// This is the main command buffer used for the frame.
var cmd = CommandBufferPool.Get("");
using (new ProfilingSample(cmd, "HDRenderPipeline::Render", GetSampler(CustomSamplerId.HDRenderPipeline_Render)))
using (new ProfilingSample(cmd, "HDRenderPipeline::Render", GetSampler(CustomSamplerId.HDRenderPipelineRender)))
{
base.Render(renderContext, cameras);

m_CurrentDebugDisplaySettings = m_DebugDisplaySettings;
}
ApplyDebugDisplaySettings();
ApplyDebugDisplaySettings(cmd);
UpdateCommonSettings();
ScriptableCullingParameters cullingParams;

}
#endif
using (new ProfilingSample(cmd, "CullResults.Cull", GetSampler(CustomSamplerId.CullResults_Cull)))
using (new ProfilingSample(cmd, "CullResults.Cull", GetSampler(CustomSamplerId.CullResultsCull)))
{
CullResults.Cull(ref cullingParams, renderContext,ref m_CullResults);
}

// It mean that when we build a standalone player, if we detect a light with bake shadow mask, we generate all shader variant (with and without shadow mask) and at runtime, when a bake shadow mask light is visible, we dynamically allocate an extra GBuffer and switch the shader.
// So the first thing to do is to go through all the light: PrepareLightsForGPU
bool enableBakeShadowMask;
using (new ProfilingSample(cmd, "TP_PrepareLightsForGPU", HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_PrepareLightsForGPU)))
using (new ProfilingSample(cmd, "TP_PrepareLightsForGPU", GetSampler(CustomSamplerId.TPPrepareLightsForGPU)))
{
enableBakeShadowMask = m_LightLoop.PrepareLightsForGPU(m_ShadowSettings, m_CullResults, camera);
}

}
else
{
using (new ProfilingSample(cmd, "Build Light list and render shadows",GetSampler(CustomSamplerId.Build_Light_list_and_render_shadows)))
using (new ProfilingSample(cmd, "Render SSAO", GetSampler(CustomSamplerId.RenderSSAO)))
}
using (new ProfilingSample(cmd, "Render shadows", GetSampler(CustomSamplerId.RenderShadows)))
{
// TODO: check if statement below still apply
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after RenderShadows as it modify our view/proj matrix
}
cmd.GetTemporaryRT(m_DeferredShadowBuffer, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1 , true);
using (new ProfilingSample(cmd, "Deferred directional shadows", GetSampler(CustomSamplerId.RenderDeferredDirectionalShadow)))
{
cmd.GetTemporaryRT(m_DeferredShadowBuffer, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear, 1, true);
}
renderContext.SetupCameraProperties(camera); // Need to recall SetupCameraProperties after m_ShadowPass.Render
using (new ProfilingSample(cmd, "Build Light list", GetSampler(CustomSamplerId.BuildLightList)))
{
m_LightLoop.BuildGPULightLists(camera, cmd, m_CameraDepthStencilBufferRT, GetStencilTexture());
}

// Planar and real time cubemap doesn't need post process and render in FP16
if (camera.cameraType == CameraType.Reflection)
{
using (new ProfilingSample(cmd, "Blit to final RT",GetSampler(CustomSamplerId.Blit_to_final_RT)))
using (new ProfilingSample(cmd, "Blit to final RT", GetSampler(CustomSamplerId.BlitToFinalRT)))
{
// Simple blit
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);

if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableDistortion)
return;
using (new ProfilingSample(cmd, "Distortion",GetSampler(CustomSamplerId.Distortion)))
using (new ProfilingSample(cmd, "Distortion", GetSampler(CustomSamplerId.Distortion)))
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;

void RenderDistortion(CommandBuffer cmd, RenderPipelineResources resources)
{
using (new ProfilingSample(cmd, "ApplyDistortion",GetSampler(CustomSamplerId.ApplyDistortion)))
using (new ProfilingSample(cmd, "ApplyDistortion", GetSampler(CustomSamplerId.ApplyDistortion)))
{
var size = new Vector4(m_CurrentWidth, m_CurrentHeight, 1f / m_CurrentWidth, 1f / m_CurrentHeight);
uint x, y, z;

bool addFullDepthPrepass = m_Asset.renderingSettings.ShouldUseForwardRenderingOnly() || m_Asset.renderingSettings.useDepthPrepassWithDeferredRendering;
bool addAlphaTestedOnly = !m_Asset.renderingSettings.ShouldUseForwardRenderingOnly() && m_Asset.renderingSettings.useDepthPrepassWithDeferredRendering && m_Asset.renderingSettings.renderAlphaTestOnlyInDeferredPrepass;
using (new ProfilingSample(cmd, addAlphaTestedOnly ? "Depth Prepass alpha test" : "Depth Prepass",GetSampler(CustomSamplerId.Depth_Prepass)))
using (new ProfilingSample(cmd, addAlphaTestedOnly ? "Depth Prepass alpha test" : "Depth Prepass", GetSampler(CustomSamplerId.DepthPrepass)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraDepthStencilBufferRT);
if (addFullDepthPrepass && !addAlphaTestedOnly) // Always true in case of forward rendering, use in case of deferred rendering if requesting a full depth prepass

if (m_Asset.renderingSettings.ShouldUseForwardRenderingOnly())
return;
using (new ProfilingSample(cmd, m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer",GetSampler(CustomSamplerId.GBuffer)))
using (new ProfilingSample(cmd, m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer", GetSampler(CustomSamplerId.GBuffer)))
{
// setup GBuffer for rendering
CoreUtils.SetRenderTarget(cmd, m_GbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT);

void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
using (new ProfilingSample(cmd, "DisplayDebug ViewMaterial",GetSampler(CustomSamplerId.DisplayDebug_ViewMaterial)))
using (new ProfilingSample(cmd, "DisplayDebug ViewMaterial", GetSampler(CustomSamplerId.DisplayDebugViewMaterial)))
using (new ProfilingSample(cmd, "DebugViewMaterialGBuffer",GetSampler(CustomSamplerId.DebugViewMaterialGBuffer)))
using (new ProfilingSample(cmd, "DebugViewMaterialGBuffer", GetSampler(CustomSamplerId.DebugViewMaterialGBuffer)))
{
CoreUtils.DrawFullScreen(cmd, m_currentDebugViewMaterialGBuffer, m_CameraColorBufferRT);
}

// Last blit
{
using (new ProfilingSample(cmd, "Blit DebugView Material Debug",GetSampler(CustomSamplerId.Blit_DebugView_Material_Debug)))
using (new ProfilingSample(cmd, "Blit DebugView Material Debug", GetSampler(CustomSamplerId.BlitDebugViewMaterialDebug)))
{
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);
}

return;
}
}
// No AO applied - neutral is black, see the comment in the shaders
cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, RuntimeUtilities.blackTexture);
cmd.SetGlobalVector(HDShaderIDs._AmbientOcclusionParam, Vector4.zero);

// Output split lighting for materials asking for it (masked in the stencil buffer)
options.outputSplitLighting = true;
m_LightLoop.RenderDeferredLighting(hdCamera, cmd, m_CurrentDebugDisplaySettings, m_MRTCache2, m_CameraDepthStencilBufferRT, depthTexture, m_DeferredShadowBuffer, options);
m_LightLoop.RenderDeferredLighting(hdCamera, cmd, m_CurrentDebugDisplaySettings, m_MRTCache2, m_CameraDepthStencilBufferRT, depthTexture, options);
m_LightLoop.RenderDeferredLighting(hdCamera, cmd, m_CurrentDebugDisplaySettings, m_MRTCache2, m_CameraDepthStencilBufferRT, depthTexture, m_DeferredShadowBuffer, options);
m_LightLoop.RenderDeferredLighting(hdCamera, cmd, m_CurrentDebugDisplaySettings, m_MRTCache2, m_CameraDepthStencilBufferRT, depthTexture, options);
}
// Combines specular lighting and diffuse lighting with subsurface scattering.

if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission || m_Asset.renderingSettings.ShouldUseForwardRenderingOnly())
return;
using (new ProfilingSample(cmd, "Subsurface Scattering",GetSampler(CustomSamplerId.Subsurface_Scattering)))
using (new ProfilingSample(cmd, "Subsurface Scattering", GetSampler(CustomSamplerId.SubsurfaceScattering)))
// TODO: Remove this once fix, see comment inside the function
hdCamera.SetupComputeShader(m_SubsurfaceScatteringCS, cmd);
cmd.SetComputeIntParam( m_SubsurfaceScatteringCS, HDShaderIDs._TexturingModeFlags, sssParameters.texturingModeFlags);

profileName = k_ForwardPassName[(int)pass];
}
using (new ProfilingSample(cmd, profileName,GetSampler(CustomSamplerId.ForwardPassName)))
using (new ProfilingSample(cmd, profileName, GetSampler(CustomSamplerId.ForwardPassName)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT);

void RenderTransparentDepthPrepass(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
using (new ProfilingSample(cmd,"Forward Transparent Depth Prepass",GetSampler(CustomSamplerId.Forward_Transparent_Depth_Prepass)))
using (new ProfilingSample(cmd,"Forward Transparent Depth Prepass", GetSampler(CustomSamplerId.ForwardTransparentDepthPrepass)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraDepthStencilBufferRT);
RenderTransparentRenderList(cullResults, camera, renderContext, cmd, HDShaderPassNames.s_TransparentDepthPrepassName, preRefractionQueue: true);

[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
void RenderForwardError(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, CommandBuffer cmd, ForwardPass pass)
{
using (new ProfilingSample(cmd, "Render Forward Error",GetSampler(CustomSamplerId.Render_Forward_Error)))
using (new ProfilingSample(cmd, "Render Forward Error", GetSampler(CustomSamplerId.RenderForwardError)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT);

void RenderVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
using (new ProfilingSample(cmd, "Velocity",GetSampler(CustomSamplerId.Velocity)))
using (new ProfilingSample(cmd, "Velocity", GetSampler(CustomSamplerId.Velocity)))
{
// If opaque velocity have been render during GBuffer no need to render it here
// TODO: Currently we can't render velocity vector into GBuffer, neither during forward pass (in case of forward opaque), so it is always a separate pass

if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableGaussianPyramid)
return;
using (new ProfilingSample(cmd, "Gaussian Pyramid Color",GetSampler(CustomSamplerId.Gaussian_Pyramid_Color)))
using (new ProfilingSample(cmd, "Gaussian Pyramid Color", GetSampler(CustomSamplerId.GaussianPyramidColor)))
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;

if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableGaussianPyramid)
return;
using (new ProfilingSample(cmd, "Pyramid Depth",GetSampler(CustomSamplerId.Pyramid_Depth)))
using (new ProfilingSample(cmd, "Pyramid Depth", GetSampler(CustomSamplerId.PyramidDepth)))
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;

void RenderPostProcesses(Camera camera, CommandBuffer cmd, PostProcessLayer layer)
{
using (new ProfilingSample(cmd, "Post-processing",GetSampler(CustomSamplerId.Post_processing)))
using (new ProfilingSample(cmd, "Post-processing", GetSampler(CustomSamplerId.PostProcessing)))
{
if (CoreUtils.IsPostProcessingActive(layer))
{

}
}
public void ApplyDebugDisplaySettings()
public void ApplyDebugDisplaySettings(CommandBuffer cmd)
{
m_ShadowSettings.enabled = m_CurrentDebugDisplaySettings.lightingDebugSettings.enableShadows;

Shader.SetGlobalInt(HDShaderIDs._DebugViewMaterial, (int)m_CurrentDebugDisplaySettings.GetDebugMaterialIndex());
Shader.SetGlobalInt(HDShaderIDs._DebugLightingMode, (int)m_CurrentDebugDisplaySettings.GetDebugLightingMode());
Shader.SetGlobalVector(HDShaderIDs._DebugLightingAlbedo, debugAlbedo);
Shader.SetGlobalVector(HDShaderIDs._DebugLightingSmoothness, debugSmoothness);
cmd.SetGlobalInt(HDShaderIDs._DebugViewMaterial, (int)m_CurrentDebugDisplaySettings.GetDebugMaterialIndex());
cmd.SetGlobalInt(HDShaderIDs._DebugLightingMode, (int)m_CurrentDebugDisplaySettings.GetDebugLightingMode());
cmd.SetGlobalVector(HDShaderIDs._DebugLightingAlbedo, debugAlbedo);
cmd.SetGlobalVector(HDShaderIDs._DebugLightingSmoothness, debugSmoothness);
}
public void PushFullScreenDebugTexture(CommandBuffer cb, RenderTargetIdentifier textureID, Camera camera, ScriptableRenderContext renderContext, FullScreenDebugMode debugMode)

if (camera.camera.cameraType == CameraType.Reflection || camera.camera.cameraType == CameraType.Preview)
return;
using (new ProfilingSample(cmd, "Render Debug",GetSampler(CustomSamplerId.Render_Debug)))
using (new ProfilingSample(cmd, "Render Debug", GetSampler(CustomSamplerId.RenderDebug)))
{
// We make sure the depth buffer is bound because we need it to write depth at near plane for overlays otherwise the editor grid end up visible in them.
CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, m_CameraDepthStencilBufferRT);

void InitAndClearBuffer(HDCamera camera, bool enableBakeShadowMask, CommandBuffer cmd)
{
using (new ProfilingSample(cmd, "InitAndClearBuffer",GetSampler(CustomSamplerId.InitAndClearBuffer)))
using (new ProfilingSample(cmd, "InitAndClearBuffer", GetSampler(CustomSamplerId.InitAndClearBuffer)))
using (new ProfilingSample(cmd, "InitGBuffers and clear Depth/Stencil",GetSampler(CustomSamplerId.InitGBuffers_and_clear_Depth_Stencil)))
using (new ProfilingSample(cmd, "InitGBuffers and clear Depth/Stencil", GetSampler(CustomSamplerId.InitGBuffersAndClearDepthStencil)))
{
// Init buffer
// With scriptable render loop we must allocate ourself depth and color buffer (We must be independent of backbuffer for now, hope to fix that later).

}
// Clear the diffuse SSS lighting target
using (new ProfilingSample(cmd, "Clear SSS diffuse target",GetSampler(CustomSamplerId.Clear_SSS_diffuse_target)))
using (new ProfilingSample(cmd, "Clear SSS diffuse target", GetSampler(CustomSamplerId.ClearSSSDiffuseTarget)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraSssDiffuseLightingBufferRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}

{
// Clear the SSS filtering target
using (new ProfilingSample(cmd, "Clear SSS filtering target",GetSampler(CustomSamplerId.Clear_SSS_filtering_target)))
using (new ProfilingSample(cmd, "Clear SSS filtering target", GetSampler(CustomSamplerId.ClearSSSFilteringTarget)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraFilteringBuffer, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}

if (NeedStencilBufferCopy())
{
using (new ProfilingSample(cmd, "Clear stencil texture",GetSampler(CustomSamplerId.Clear_stencil_texture)))
using (new ProfilingSample(cmd, "Clear stencil texture", GetSampler(CustomSamplerId.ClearStencilTexture)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraStencilBufferCopyRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}

{
using (new ProfilingSample(cmd, "Clear HTile",GetSampler(CustomSamplerId.Clear_HTile)))
using (new ProfilingSample(cmd, "Clear HTile", GetSampler(CustomSamplerId.ClearHTile)))
{
CoreUtils.SetRenderTarget(cmd, m_HTileRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}

// Clear the HDR target
using (new ProfilingSample(cmd, "Clear HDR target",GetSampler(CustomSamplerId.Clear_HDR_target)))
using (new ProfilingSample(cmd, "Clear HDR target", GetSampler(CustomSamplerId.ClearHDRTarget)))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}

{
using (new ProfilingSample(cmd, "Clear GBuffer",GetSampler(CustomSamplerId.Clear_GBuffer)))
using (new ProfilingSample(cmd, "Clear GBuffer", GetSampler(CustomSamplerId.ClearGBuffer)))
{
CoreUtils.SetRenderTarget(cmd, m_GbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT, ClearFlag.Color, CoreUtils.clearColorAllBlack);
}

313
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


RenderTargetIdentifier[] tex;
sc.GetTex2DArrays(out tex, out offset, out count);
if(computeShader)
{
// bind buffers
cb.SetComputeBufferParam(computeShader, computeKernel, HDShaderIDs._ShadowDatasExp, s_ShadowDataBuffer);
cb.SetComputeBufferParam(computeShader, computeKernel, HDShaderIDs._ShadowPayloads, s_ShadowPayloadBuffer);
// bind textures
cb.SetComputeTextureParam(computeShader, computeKernel, HDShaderIDs._ShadowmapExp_VSM_0, tex[0]);
cb.SetComputeTextureParam(computeShader, computeKernel, HDShaderIDs._ShadowmapExp_VSM_1, tex[1]);
cb.SetComputeTextureParam(computeShader, computeKernel, HDShaderIDs._ShadowmapExp_VSM_2, tex[2]);
cb.SetComputeTextureParam(computeShader, computeKernel, HDShaderIDs._ShadowmapExp_PCF, tex[3]);
}
else
{
// bind buffers
cb.SetGlobalBuffer(HDShaderIDs._ShadowDatasExp, s_ShadowDataBuffer);
cb.SetGlobalBuffer(HDShaderIDs._ShadowPayloads, s_ShadowPayloadBuffer);
// bind textures
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_0, tex[0]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_1, tex[1]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_2, tex[2]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_PCF, tex[3]);
}
// bind buffers
cb.SetGlobalBuffer(HDShaderIDs._ShadowDatasExp, s_ShadowDataBuffer);
cb.SetGlobalBuffer(HDShaderIDs._ShadowPayloads, s_ShadowPayloadBuffer);
// bind textures
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_0, tex[0]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_1, tex[1]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_2, tex[2]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_PCF, tex[3]);
// TODO: Currently samplers are hard coded in ShadowContext.hlsl, so we can't really set them here
};

cmd.SetComputeBufferParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs.g_TileFeatureFlags, s_TileFeatureFlags);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs._StencilTexture, stencilTextureRT);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs._GBufferTexture0, HDShaderIDs._GBufferTexture0);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs._GBufferTexture1, HDShaderIDs._GBufferTexture1);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs._GBufferTexture2, HDShaderIDs._GBufferTexture2);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs._GBufferTexture3, HDShaderIDs._GBufferTexture3);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs._ShadowMaskTexture, HDShaderIDs._ShadowMaskTexture);
cmd.SetComputeTextureParam(buildMaterialFlagsShader, buildMaterialFlagsKernel, HDShaderIDs._VelocityTexture, HDShaderIDs._VelocityTexture);
cmd.DispatchCompute(buildMaterialFlagsShader, buildMaterialFlagsKernel, numTilesX, numTilesY, 1);
}

}
cmd.EndSample("Build Light List");
}
// This is a workaround for global properties not being accessible from compute.
// When activeComputeShader is set, all calls to SetGlobalXXX will set the property on the select compute shader instead of the global scope.
private ComputeShader activeComputeShader;
private int activeComputeKernel;
private CommandBuffer activeCommandBuffer;
private void SetGlobalPropertyRedirect(ComputeShader computeShader, int computeKernel, CommandBuffer commandBuffer)
{
activeComputeShader = computeShader;
activeComputeKernel = computeKernel;
activeCommandBuffer = commandBuffer;
}
private void SetGlobalTexture(int nameID, Texture value)
{
if (activeComputeShader)
activeCommandBuffer.SetComputeTextureParam(activeComputeShader, activeComputeKernel, nameID, value);
else
activeCommandBuffer.SetGlobalTexture(nameID, value);
}
private void SetGlobalBuffer(int nameID, ComputeBuffer buffer)
{
if (activeComputeShader)
activeCommandBuffer.SetComputeBufferParam(activeComputeShader, activeComputeKernel, nameID, buffer);
else
activeCommandBuffer.SetGlobalBuffer(nameID, buffer);
}
private void SetGlobalInt(int nameID, int value)
{
if (activeComputeShader)
activeCommandBuffer.SetComputeIntParam(activeComputeShader, nameID, value);
else
Shader.SetGlobalInt(nameID, value);
}
private void SetGlobalFloat(int nameID, float value)
{
if (activeComputeShader)
activeCommandBuffer.SetComputeFloatParam(activeComputeShader, nameID, value);
else
activeCommandBuffer.SetGlobalFloat(nameID, value);
}
private void SetGlobalVector(int nameID, Vector4 value)
{
if (activeComputeShader)
activeCommandBuffer.SetComputeVectorParam(activeComputeShader, nameID, value);
else
activeCommandBuffer.SetGlobalVector(nameID, value);
}
private void SetGlobalVectorArray(int nameID, Vector4[] values)
{
if (activeComputeShader)
{
activeCommandBuffer.SetComputeVectorArrayParam(activeComputeShader, nameID, values);
}
else
{
activeCommandBuffer.SetGlobalVectorArray(nameID, values);
}
PushGlobalParams(camera, cmd);
}
private void UpdateDataBuffers()

s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes);
}
private void BindGlobalParams(CommandBuffer cmd, Camera camera, bool forceClustered)
void PushGlobalParams(Camera camera, CommandBuffer cmd)
m_ShadowMgr.BindResources(cmd, activeComputeShader, activeComputeKernel);
using (new ProfilingSample(cmd, "Push Global Parameters", HDRenderPipeline.GetSampler(CustomSamplerId.TPPushGlobalParameters)))
{
// Shadows
m_ShadowMgr.SyncData();
m_ShadowMgr.BindResources(cmd, null, 0);
SetGlobalBuffer(HDShaderIDs.g_vLightListGlobal, (forceClustered || !usingFptl) ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)
cmd.SetGlobalTexture(HDShaderIDs._CookieTextures, m_CookieTexArray.GetTexCache());
cmd.SetGlobalTexture(HDShaderIDs._CookieCubeTextures, m_CubeCookieTexArray.GetTexCache());
cmd.SetGlobalTexture(HDShaderIDs._EnvTextures, m_CubeReflTexArray.GetTexCache());
SetGlobalTexture(HDShaderIDs._CookieTextures, m_CookieTexArray.GetTexCache());
SetGlobalTexture(HDShaderIDs._CookieCubeTextures, m_CubeCookieTexArray.GetTexCache());
SetGlobalTexture(HDShaderIDs._EnvTextures, m_CubeReflTexArray.GetTexCache());
cmd.SetGlobalBuffer(HDShaderIDs._DirectionalLightDatas, s_DirectionalLightDatas);
cmd.SetGlobalInt(HDShaderIDs._DirectionalLightCount, m_lightList.directionalLights.Count);
cmd.SetGlobalBuffer(HDShaderIDs._LightDatas, s_LightDatas);
cmd.SetGlobalInt(HDShaderIDs._PunctualLightCount, m_punctualLightCount);
cmd.SetGlobalInt(HDShaderIDs._AreaLightCount, m_areaLightCount);
cmd.SetGlobalBuffer(HDShaderIDs._EnvLightDatas, s_EnvLightDatas);
cmd.SetGlobalInt(HDShaderIDs._EnvLightCount, m_lightList.envLights.Count);
cmd.SetGlobalBuffer(HDShaderIDs._ShadowDatas, s_shadowDatas);
cmd.SetGlobalVectorArray(HDShaderIDs._DirShadowSplitSpheres, m_lightList.directionalShadowSplitSphereSqr);
SetGlobalBuffer(HDShaderIDs._DirectionalLightDatas, s_DirectionalLightDatas);
SetGlobalInt(HDShaderIDs._DirectionalLightCount, m_lightList.directionalLights.Count);
SetGlobalBuffer(HDShaderIDs._LightDatas, s_LightDatas);
SetGlobalInt(HDShaderIDs._PunctualLightCount, m_punctualLightCount);
SetGlobalInt(HDShaderIDs._AreaLightCount, m_areaLightCount);
SetGlobalBuffer(HDShaderIDs._EnvLightDatas, s_EnvLightDatas);
SetGlobalInt(HDShaderIDs._EnvLightCount, m_lightList.envLights.Count);
SetGlobalBuffer(HDShaderIDs._ShadowDatas, s_shadowDatas);
SetGlobalVectorArray(HDShaderIDs._DirShadowSplitSpheres, m_lightList.directionalShadowSplitSphereSqr);
cmd.SetGlobalInt(HDShaderIDs._NumTileFtplX, GetNumTileFtplX(camera));
cmd.SetGlobalInt(HDShaderIDs._NumTileFtplY, GetNumTileFtplY(camera));
SetGlobalInt(HDShaderIDs._NumTileFtplX, GetNumTileFtplX(camera));
SetGlobalInt(HDShaderIDs._NumTileFtplY, GetNumTileFtplY(camera));
cmd.SetGlobalInt(HDShaderIDs._NumTileClusteredX, GetNumTileClusteredX(camera));
cmd.SetGlobalInt(HDShaderIDs._NumTileClusteredY, GetNumTileClusteredY(camera));
SetGlobalInt(HDShaderIDs._NumTileClusteredX, GetNumTileClusteredX(camera));
SetGlobalInt(HDShaderIDs._NumTileClusteredY, GetNumTileClusteredY(camera));
if (m_TileSettings.enableBigTilePrepass)
cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, s_BigTileLightList);
if (m_TileSettings.enableBigTilePrepass)
SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, s_BigTileLightList);
if (m_TileSettings.enableClustered)
{
cmd.SetGlobalFloat(HDShaderIDs.g_fClustScale, m_ClustScale);
cmd.SetGlobalFloat(HDShaderIDs.g_fClustBase, k_ClustLogBase);
cmd.SetGlobalFloat(HDShaderIDs.g_fNearPlane, camera.nearClipPlane);
cmd.SetGlobalFloat(HDShaderIDs.g_fFarPlane, camera.farClipPlane);
cmd.SetGlobalInt(HDShaderIDs.g_iLog2NumClusters, k_Log2NumClusters);
cmd.SetGlobalInt(HDShaderIDs.g_isLogBaseBufferEnabled, k_UseDepthBuffer ? 1 : 0);
if (m_TileSettings.enableClustered)
{
SetGlobalFloat(HDShaderIDs.g_fClustScale, m_ClustScale);
SetGlobalFloat(HDShaderIDs.g_fClustBase, k_ClustLogBase);
SetGlobalFloat(HDShaderIDs.g_fNearPlane, camera.nearClipPlane);
SetGlobalFloat(HDShaderIDs.g_fFarPlane, camera.farClipPlane);
SetGlobalInt(HDShaderIDs.g_iLog2NumClusters, k_Log2NumClusters);
SetGlobalInt(HDShaderIDs.g_isLogBaseBufferEnabled, k_UseDepthBuffer ? 1 : 0);
SetGlobalBuffer(HDShaderIDs.g_vLayeredOffsetsBuffer, s_PerVoxelOffset);
if (k_UseDepthBuffer)
{
SetGlobalBuffer(HDShaderIDs.g_logBaseBuffer, s_PerTileLogBaseTweak);
cmd.SetGlobalBuffer(HDShaderIDs.g_vLayeredOffsetsBuffer, s_PerVoxelOffset);
if (k_UseDepthBuffer)
{
cmd.SetGlobalBuffer(HDShaderIDs.g_logBaseBuffer, s_PerTileLogBaseTweak);
}
public void PushGlobalParams(Camera camera, CommandBuffer cmd, ComputeShader computeShader, int kernelIndex, bool forceClustered = false)
{
using (new ProfilingSample(cmd, "Push Global Parameters",HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_Push_Global_Parameters)))
{
// Shadows
m_ShadowMgr.SyncData();
SetGlobalPropertyRedirect(computeShader, kernelIndex, cmd);
BindGlobalParams(cmd, camera, forceClustered);
SetGlobalPropertyRedirect(null, 0, null);
}
}
#if UNITY_EDITOR
private Vector2 m_mousePosition = Vector2.zero;

if (lightingDebug.tileDebugByCategory == TileSettings.TileDebug.None)
return;
using (new ProfilingSample(cmd, "Tiled Lighting Debug",HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_Tiled_Lighting_Debug)))
using (new ProfilingSample(cmd, "Tiled Lighting Debug", HDRenderPipeline.GetSampler(CustomSamplerId.TPTiledLightingDebug)))
{
bool bUseClusteredForDeferred = !usingFptl;

#endif
// Debug tiles
PushGlobalParams(hdCamera.camera, cmd, null, 0);
if (lightingDebug.tileDebugByCategory == TileSettings.TileDebug.FeatureVariants)
{
if (GetFeatureVariantsEnabled(m_TileSettings))

CoreUtils.DrawFullScreen(cmd, m_DebugViewTilesMaterial, 0, colorBuffer);
}
SetGlobalPropertyRedirect(null, 0, null);
}
}

if (m_CurrentSunLight == null)
return;
using (new ProfilingSample(cmd, "Deferred Directional",HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_Deferred_Directional)))
using (new ProfilingSample(cmd, "Deferred Directional Shadow", HDRenderPipeline.GetSampler(CustomSamplerId.TPDeferredDirectionalShadow)))
hdCamera.SetupComputeShader(deferredDirectionalShadowComputeShader, cmd);
m_ShadowMgr.BindResources(cmd, deferredDirectionalShadowComputeShader, s_deferredDirectionalShadowKernel);
cmd.SetComputeFloatParam(deferredDirectionalShadowComputeShader, HDShaderIDs._DirectionalShadowIndex, (float)m_CurrentSunLightShadowIndex);

public void RenderDeferredLighting( HDCamera hdCamera, CommandBuffer cmd,
DebugDisplaySettings debugDisplaySettings,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthStencilBuffer, RenderTargetIdentifier depthTexture, RenderTargetIdentifier deferredShadowTexture,
RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthStencilBuffer, RenderTargetIdentifier depthTexture,
cmd.SetGlobalBuffer(HDShaderIDs.g_vLightListGlobal, bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList);
if (m_TileSettings.enableTileAndCluster && m_TileSettings.enableComputeLightEvaluation && options.outputSplitLighting)
{

string tilePassMRTName = "TilePass - Deferred Lighting Pass MRT";
string singlePassName = "SinglePass - Deferred Lighting Pass";
string SinglePassMRTName = "SinglePass - Deferred Lighting Pass MRT";
// TODO: Check if we can remove this, when I test I can't
Texture skyTexture = Shader.GetGlobalTexture(HDShaderIDs._SkyTexture);
float skyTextureMipCount = Shader.GetGlobalFloat(HDShaderIDs._SkyTextureMipCount);
using (new ProfilingSample(cmd, sLabel,HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_RenderDeferredLighting )))
using (new ProfilingSample(cmd, sLabel, HDRenderPipeline.GetSampler(CustomSamplerId.TPRenderDeferredLighting)))
{
var camera = hdCamera.camera;

if (enableFeatureVariants)
numVariants = LightDefinitions.s_NumFeatureVariants;
int debugViewMaterial = Shader.GetGlobalInt(HDShaderIDs._DebugViewMaterial);
int debugLightingMode = Shader.GetGlobalInt(HDShaderIDs._DebugLightingMode);
Vector4 debugLightingAlbedo = Shader.GetGlobalVector(HDShaderIDs._DebugLightingAlbedo);
Vector4 debugLightingSmoothness = Shader.GetGlobalVector(HDShaderIDs._DebugLightingSmoothness);
Texture ltcData = Shader.GetGlobalTexture(HDShaderIDs._LtcData);
Texture preIntegratedFGD = Shader.GetGlobalTexture(HDShaderIDs._PreIntegratedFGD);
Texture ltcGGXMatrix = Shader.GetGlobalTexture(HDShaderIDs._LtcGGXMatrix);
Texture ltcDisneyDiffuseMatrix = Shader.GetGlobalTexture(HDShaderIDs._LtcDisneyDiffuseMatrix);
Texture ltcMultiGGXFresnelDisneyDiffuse = Shader.GetGlobalTexture(HDShaderIDs._LtcMultiGGXFresnelDisneyDiffuse);
Matrix4x4 invScrProjection = Shader.GetGlobalMatrix(HDShaderIDs.g_mInvScrProjection);
int useTileLightList = Shader.GetGlobalInt(HDShaderIDs._UseTileLightList);
Vector4 time = Shader.GetGlobalVector(HDShaderIDs._Time);
Vector4 sinTime = Shader.GetGlobalVector(HDShaderIDs._SinTime);
Vector4 cosTime = Shader.GetGlobalVector(HDShaderIDs._CosTime);
Vector4 unity_DeltaTime = Shader.GetGlobalVector(HDShaderIDs.unity_DeltaTime);
int envLightSkyEnabled = Shader.GetGlobalInt(HDShaderIDs._EnvLightSkyEnabled);
Vector4 ambientOcclusionParam = Shader.GetGlobalVector(HDShaderIDs._AmbientOcclusionParam);
int enableSSSAndTransmission = Shader.GetGlobalInt(HDShaderIDs._EnableSSSAndTransmission);
int texturingModeFlags = Shader.GetGlobalInt(HDShaderIDs._TexturingModeFlags);
int transmissionFlags = Shader.GetGlobalInt(HDShaderIDs._TransmissionFlags);
int useDisneySSS = Shader.GetGlobalInt(HDShaderIDs._UseDisneySSS);
Vector4[] thicknessRemaps = Shader.GetGlobalVectorArray(HDShaderIDs._ThicknessRemaps);
Vector4[] shapeParams = Shader.GetGlobalVectorArray(HDShaderIDs._ShapeParams);
Vector4[] transmissionTints = Shader.GetGlobalVectorArray(HDShaderIDs._TransmissionTints);
Vector4[] halfRcpVariancesAndWeights = Shader.GetGlobalVectorArray(HDShaderIDs._HalfRcpVariancesAndWeights);
Texture skyTexture = Shader.GetGlobalTexture(HDShaderIDs._SkyTexture);
float skyTextureMipCount = Shader.GetGlobalFloat(HDShaderIDs._SkyTextureMipCount);
for (int variant = 0; variant < numVariants; variant++)
{
int kernel;

if (m_enableBakeShadowMask)
{
if (debugDisplaySettings.IsDebugDisplayEnabled())
kernel = usingFptl ? s_shadeOpaqueDirectFptlDebugDisplayKernel : s_shadeOpaqueDirectClusteredDebugDisplayKernel;
kernel = usingFptl ? s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel : s_shadeOpaqueDirectShadowMaskClusteredDebugDisplayKernel;
kernel = usingFptl ? s_shadeOpaqueDirectFptlKernel : s_shadeOpaqueDirectClusteredKernel;
kernel = usingFptl ? s_shadeOpaqueDirectShadowMaskFptlKernel : s_shadeOpaqueDirectShadowMaskClusteredKernel;
kernel = usingFptl ? s_shadeOpaqueDirectShadowMaskFptlDebugDisplayKernel : s_shadeOpaqueDirectShadowMaskClusteredDebugDisplayKernel;
kernel = usingFptl ? s_shadeOpaqueDirectFptlDebugDisplayKernel : s_shadeOpaqueDirectClusteredDebugDisplayKernel;
kernel = usingFptl ? s_shadeOpaqueDirectShadowMaskFptlKernel : s_shadeOpaqueDirectShadowMaskClusteredKernel;
kernel = usingFptl ? s_shadeOpaqueDirectFptlKernel : s_shadeOpaqueDirectClusteredKernel;
// Pass global parameters to compute shader
// TODO: get rid of this by making global parameters visible to compute shaders
PushGlobalParams(camera, cmd, deferredComputeShader, kernel);
hdCamera.SetupComputeShader(deferredComputeShader, cmd);
// TODO: Update value like in ApplyDebugDisplaySettings() call. Sadly it is high likely that this will not be keep in sync. we really need to get rid of this by making global parameters visible to compute shaders
cmd.SetComputeIntParam(deferredComputeShader, HDShaderIDs._DebugViewMaterial, debugViewMaterial);
cmd.SetComputeIntParam(deferredComputeShader, HDShaderIDs._DebugLightingMode, debugLightingMode);
cmd.SetComputeVectorParam(deferredComputeShader, HDShaderIDs._DebugLightingAlbedo, debugLightingAlbedo);
cmd.SetComputeVectorParam(deferredComputeShader, HDShaderIDs._DebugLightingSmoothness, debugLightingSmoothness);
cmd.SetComputeBufferParam(deferredComputeShader, kernel, HDShaderIDs.g_vLightListGlobal, bUseClusteredForDeferred ? s_PerVoxelLightLists : s_LightList);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._DeferredShadowTexture, deferredShadowTexture);
// TODO: Don't know why but If we use Shader.GetGlobalTexture(HDShaderIDs._GBufferTexture0) instead of HDShaderIDs._GBufferTexture0 the screen start to flicker in SceneView...
// Need to investigate what is happening. But this may be unnecessary as development of SetGlobalTexture for compute shader have begin
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._GBufferTexture0, HDShaderIDs._GBufferTexture0);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._GBufferTexture1, HDShaderIDs._GBufferTexture1);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._GBufferTexture2, HDShaderIDs._GBufferTexture2);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._GBufferTexture3, HDShaderIDs._GBufferTexture3);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._ShadowMaskTexture, HDShaderIDs._ShadowMaskTexture);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._VelocityTexture, HDShaderIDs._VelocityTexture);
// TODO: Should remove this setting but can't remove it else get error: Property (_AmbientOcclusionTexture) at kernel index (32) is not set. Check why
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._LtcData, ltcData);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._PreIntegratedFGD, preIntegratedFGD);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._LtcGGXMatrix, ltcGGXMatrix);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._LtcDisneyDiffuseMatrix, ltcDisneyDiffuseMatrix);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._LtcMultiGGXFresnelDisneyDiffuse, ltcMultiGGXFresnelDisneyDiffuse);
cmd.SetComputeMatrixParam(deferredComputeShader, HDShaderIDs.g_mInvScrProjection, invScrProjection);
cmd.SetComputeIntParam(deferredComputeShader, HDShaderIDs._UseTileLightList, useTileLightList);
cmd.SetComputeVectorParam(deferredComputeShader, HDShaderIDs._Time, time);
cmd.SetComputeVectorParam(deferredComputeShader, HDShaderIDs._SinTime, sinTime);
cmd.SetComputeVectorParam(deferredComputeShader, HDShaderIDs._CosTime, cosTime);
cmd.SetComputeVectorParam(deferredComputeShader, HDShaderIDs.unity_DeltaTime, unity_DeltaTime);
cmd.SetComputeIntParam(deferredComputeShader, HDShaderIDs._EnvLightSkyEnabled, envLightSkyEnabled);
cmd.SetComputeVectorParam(deferredComputeShader, HDShaderIDs._AmbientOcclusionParam, ambientOcclusionParam);
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._SkyTexture, skyTexture ? skyTexture : m_DefaultTexture2DArray);
cmd.SetComputeFloatParam(deferredComputeShader, HDShaderIDs._SkyTextureMipCount, skyTextureMipCount);
// Set SSS parameters.
cmd.SetComputeIntParam( deferredComputeShader, HDShaderIDs._EnableSSSAndTransmission, enableSSSAndTransmission);
cmd.SetComputeIntParam( deferredComputeShader, HDShaderIDs._TexturingModeFlags, texturingModeFlags);
cmd.SetComputeIntParam( deferredComputeShader, HDShaderIDs._TransmissionFlags, transmissionFlags);
cmd.SetComputeIntParam( deferredComputeShader, HDShaderIDs._UseDisneySSS, useDisneySSS);
cmd.SetComputeVectorArrayParam(deferredComputeShader, HDShaderIDs._ThicknessRemaps, thicknessRemaps);
cmd.SetComputeVectorArrayParam(deferredComputeShader, HDShaderIDs._ShapeParams, shapeParams);
cmd.SetComputeVectorArrayParam(deferredComputeShader, HDShaderIDs._TransmissionTints, transmissionTints);
cmd.SetComputeVectorArrayParam(deferredComputeShader, HDShaderIDs._HalfRcpVariancesAndWeights, halfRcpVariancesAndWeights);
// TODO: Is it possible to setup this outside the loop ? Can figure out how, get this: Property (specularLightingUAV) at kernel index (21) is not set
// TODO: Check if we can remove this, when I test I can't
cmd.SetComputeTextureParam(deferredComputeShader, kernel, HDShaderIDs._SkyTexture, skyTexture);
cmd.SetComputeFloatParam(deferredComputeShader, HDShaderIDs._SkyTextureMipCount, skyTextureMipCount);
// always do deferred lighting in blocks of 16x16 (not same as tiled light size)

bUseClusteredForDeferred ? 1 : 0,
debugDisplaySettings.IsDebugDisplayEnabled() ? 1 : 0];
PushGlobalParams(camera, cmd, null, 0);
if (options.outputSplitLighting)
{
CoreUtils.DrawFullScreen(cmd, currentLightingMaterial, colorBuffers, depthStencilBuffer);

CoreUtils.DrawFullScreen(cmd, currentLightingMaterial, colorBuffers[0], depthStencilBuffer);
}
}
SetGlobalPropertyRedirect(null, 0, null);
PushGlobalParams(camera, cmd, null, 0);
using (new ProfilingSample(cmd, "Forward pass",HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_Forward_pass)))
using (new ProfilingSample(cmd, "Forward pass", HDRenderPipeline.GetSampler(CustomSamplerId.TPForwardPass)))
{
cmd.EnableShaderKeyword("LIGHTLOOP_SINGLE_PASS");
cmd.DisableShaderKeyword("LIGHTLOOP_TILE_PASS");

// Only opaques can use FPTL, transparent must use clustered!
bool useFptl = renderOpaque && usingFptl;
using (new ProfilingSample(cmd, useFptl ? "Forward Tiled pass" : "Forward Clustered pass",HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_Forward_Tiled_Cluster_pass)))
using (new ProfilingSample(cmd, useFptl ? "Forward Tiled pass" : "Forward Clustered pass", HDRenderPipeline.GetSampler(CustomSamplerId.TPForwardTiledClusterpass)))
{
// say that we want to use tile of single loop
cmd.EnableShaderKeyword("LIGHTLOOP_TILE_PASS");

public void RenderDebugOverlay(Camera camera, CommandBuffer cmd, DebugDisplaySettings debugDisplaySettings, ref float x, ref float y, float overlaySize, float width)
{
LightingDebugSettings lightingDebug = debugDisplaySettings.lightingDebugSettings;
using (new ProfilingSample(cmd, "Display Shadows",HDRenderPipeline.GetSampler(HDRenderPipeline.CustomSamplerId.TP_Display_Shadows)))
using (new ProfilingSample(cmd, "Display Shadows", HDRenderPipeline.GetSampler(CustomSamplerId.TPDisplayShadows)))
{
if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeShadowMap)
{

6
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


// Sets the global MIP-mapped cubemap '_SkyTexture' in the shader.
// The texture being set is the sky (environment) map pre-convolved with GGX.
public void SetGlobalSkyTexture()
public void SetGlobalSkyTexture(CommandBuffer cmd)
Shader.SetGlobalTexture(HDShaderIDs._SkyTexture, m_SkyboxGGXCubemapRT);
cmd.SetGlobalTexture(HDShaderIDs._SkyTexture, m_SkyboxGGXCubemapRT);
Shader.SetGlobalFloat(HDShaderIDs._SkyTextureMipCount, mipCount);
cmd.SetGlobalFloat(HDShaderIDs._SkyTextureMipCount, mipCount);
}
public void Resize(float nearPlane, float farPlane)

55
ScriptableRenderPipeline/HDRenderPipeline/HDCustomSamplerId.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public enum CustomSamplerId
{
PushGlobalParameters,
CopySetDepthBuffer,
CopyDepthStencilbuffer,
CopyStencilBuffer,
Forward,
RenderSSAO,
RenderShadows,
RenderDeferredDirectionalShadow,
BuildLightList,
BlitToFinalRT,
Distortion,
ApplyDistortion,
DepthPrepass,
GBuffer,
DisplayDebugViewMaterial,
DebugViewMaterialGBuffer,
BlitDebugViewMaterialDebug,
SubsurfaceScattering,
ForwardPassName,
ForwardTransparentDepthPrepass,
RenderForwardError,
Velocity,
GaussianPyramidColor,
PyramidDepth,
PostProcessing,
RenderDebug,
InitAndClearBuffer,
InitGBuffersAndClearDepthStencil,
ClearSSSDiffuseTarget,
ClearSSSFilteringTarget,
ClearStencilTexture,
ClearHTile,
ClearHDRTarget,
ClearGBuffer,
HDRenderPipelineRender,
CullResultsCull,
// Profile sampler for tile pass
TPPrepareLightsForGPU,
TPPushGlobalParameters,
TPTiledLightingDebug,
TPDeferredDirectionalShadow,
TPTileSettingsEnableTileAndCluster,
TPForwardPass,
TPForwardTiledClusterpass,
TPDisplayShadows,
TPRenderDeferredLighting,
Max
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDCustomSamplerId.cs.meta


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