m_IBLFilterGGX = new IBLFilterGGX ( asset . renderPipelineResources ) ;
m_LightLoop . Build ( asset . renderPipelineResources , asset . globalRenderingSettings , asset . tileSettings , asset . globalTextureSettings , asset . shadowInitParams , m_ShadowSettings , m_IBLFilterGGX ) ;
m_LightLoop . Build ( asset . renderPipelineResources , asset . tileSettings , asset . globalTextureSettings , asset . shadowInitParams , m_ShadowSettings , m_IBLFilterGGX ) ;
m_SkyManager . Build ( asset . renderPipelineResources , m_IBLFilterGGX ) ;
m_SkyManager . skySettings = skySettingsToUse ;
m_FrameCount = Time . frameCount ;
}
var stereoActive = UnityEngine . XR . XRSettings . isDeviceActive & & m_DebugDisplaySettings . renderingDebugSettings . allowStereo ;
foreach ( var camera in cameras )
{
// This is the main command buffer used for the frame.
CullResults . Cull ( ref cullingParams , renderContext , ref m_CullResults ) ;
}
var postProcessLayer = camera . GetComponent < PostProcessLayer > ( ) ;
var hdCamera = HDCamera . Get ( camera , postProcessLayer , m_Asset . globalRenderingSettings , stereoActive ) ;
m_LightLoop . UpdateRenderingPathState ( hdCamera . useForwardOnly ) ;
var postProcessLayer = camera . GetComponent < PostProcessLayer > ( ) ;
var hdCamera = HDCamera . Get ( camera , postProcessLayer ) ;
PushGlobalParams ( hdCamera , cmd , sssSettings ) ;
// TODO: Find a correct place to bind these material textures
InitAndClearBuffer ( hdCamera , enableBakeShadowMask , cmd ) ;
RenderDepthPrepass ( m_CullResults , c amera, renderContext , cmd ) ;
RenderDepthPrepass ( m_CullResults , hdC amera, renderContext , cmd ) ;
RenderGBuffer ( m_CullResults , c amera, renderContext , cmd ) ;
RenderGBuffer ( m_CullResults , hdC amera, renderContext , cmd ) ;
// In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing.
CopyDepthBufferIfNeeded ( cmd ) ;
// therefore, forward-rendered objects do not output split lighting required for the SSS pass.
SubsurfaceScatteringPass ( hdCamera , cmd , sssSettings ) ;
RenderForward ( m_CullResults , c amera, renderContext , cmd , ForwardPass . Opaque ) ;
RenderForward ( m_CullResults , hdC amera, renderContext , cmd , ForwardPass . Opaque ) ;
RenderForward ( m_CullResults , c amera, renderContext , cmd , ForwardPass . PreRefraction ) ;
RenderForward ( m_CullResults , hdC amera, renderContext , cmd , ForwardPass . PreRefraction ) ;
RenderForward ( m_CullResults , c amera, renderContext , cmd , ForwardPass . Transparent ) ;
RenderForward ( m_CullResults , hdC amera, renderContext , cmd , ForwardPass . Transparent ) ;
RenderForwardError ( m_CullResults , camera , renderContext , cmd , ForwardPass . Transparent ) ;
PushFullScreenDebugTexture ( cmd , m_CameraColorBuffer , camera , renderContext , FullScreenDebugMode . NanTracker ) ;
// Forward only renderer: We always render everything
// Deferred renderer: We render a depth prepass only if engine request it. We can decide if we render everything or only opaque alpha tested object.
// Forward opaque with deferred renderer (DepthForwardOnly pass): We always render everything
void RenderDepthPrepass ( CullResults cull , Camera c amera, ScriptableRenderContext renderContext , CommandBuffer cmd )
void RenderDepthPrepass ( CullResults cull , HDCamera hdC amera, ScriptableRenderContext renderContext , CommandBuffer cmd )
{
// In case of deferred renderer, we can have forward opaque material. These materials need to be render in the depth buffer to correctly build the light list.
// And they will tag the stencil to not be lit during the deferred lighting pass.
// 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_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) | | m_Asset . globalRenderingSettings . useDepthPrepassWithDeferredRendering ;
bool addAlphaTestedOnly = ! m_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) & & m_Asset . globalRenderingSettings . useDepthPrepassWithDeferredRendering & & m_Asset . globalRenderingSettings . renderAlphaTestOnlyInDeferredPrepass ;
bool addFullDepthPrepass = hdCamera . useForwardOnly | | m_Asset . globalRenderingSettings . useDepthPrepassWithDeferredRendering ;
bool addAlphaTestedOnly = ! hdCamera . useForwardOnly & & m_Asset . globalRenderingSettings . useDepthPrepassWithDeferredRendering & & m_Asset . globalRenderingSettings . renderAlphaTestOnlyInDeferredPrepass ;
var camera = hdCamera . camera ;
using ( new ProfilingSample ( cmd , addAlphaTestedOnly ? "Depth Prepass alpha test" : "Depth Prepass" , GetSampler ( CustomSamplerId . DepthPrepass ) ) )
{
// RenderGBuffer do the gbuffer pass. This is solely call with deferred. If we use a depth prepass, then the depth prepass will perform the alpha testing for opaque apha tested and we don't need to do it anymore
// 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 , Camera camera , ScriptableRenderContext renderContext , CommandBuffer cmd )
void RenderGBuffer ( CullResults cull , HDCamera hdCamera , ScriptableRenderContext renderContext , CommandBuffer cmd )
if ( m_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) )
if ( hdCamera . useForwardOnly )
var camera = hdCamera . camera ;
using ( new ProfilingSample ( cmd , m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) ? "GBufferDebugDisplay" : "GBuffer" , GetSampler ( CustomSamplerId . GBuffer ) ) )
{
void RenderDeferredLighting ( HDCamera hdCamera , CommandBuffer cmd )
{
if ( m_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) )
if ( hdCamera . useForwardOnly )
return ;
m_MRTCache2 [ 0 ] = m_CameraColorBufferRT ;
void SubsurfaceScatteringPass ( HDCamera hdCamera , CommandBuffer cmd , SubsurfaceScatteringSettings sssParameters )
{
// Currently, forward-rendered objects do not output split lighting required for the SSS pass.
if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission | | m_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) )
if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . enableSSSAndTransmission | | hdCamera . useForwardOnly )
return ;
using ( new ProfilingSample ( cmd , "Subsurface Scattering" , GetSampler ( CustomSamplerId . SubsurfaceScattering ) ) )
}
// Render forward is use for both transparent and opaque objects. In case of deferred we can still render opaque object in forward.
void RenderForward ( CullResults cullResults , Camera c amera, ScriptableRenderContext renderContext , CommandBuffer cmd , ForwardPass pass )
void RenderForward ( CullResults cullResults , HDCamera hdC amera, ScriptableRenderContext renderContext , CommandBuffer cmd , ForwardPass pass )
{
// Guidelines: In deferred by default there is no opaque in forward. However it is possible to force an opaque material to render in forward
// by using the pass "ForwardOnly". In this case the .shader should not have "Forward" but only a "ForwardOnly" pass.
{
CoreUtils . SetRenderTarget ( cmd , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT ) ;
var camera = hdCamera . camera ;
m_LightLoop . RenderForward ( camera , cmd , pass = = ForwardPass . Opaque ) ;
if ( pass = = ForwardPass . Opaque )
m_ForwardAndForwardOnlyPassNames [ 1 ] = HDShaderPassNames . s_ForwardName ;
}
var passNames = m_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) ? m_ForwardAndForwardOnlyPassNames : m_ForwardOnlyPassNames ;
var passNames = hdCamera . useForwardOnly ? 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 ) ;
}
cmd . GetTemporaryRT ( m_DepthPyramidBuffer , m_DepthPyramidBufferDesc , FilterMode . Trilinear ) ;
// End
if ( ! m_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) )
if ( ! camera . useForwardOnly )
m_GbufferManager . InitGBuffers ( w , h , m_DeferredMaterial , enableBakeShadowMask , cmd ) ;
CoreUtils . SetRenderTarget ( cmd , m_CameraColorBufferRT , m_CameraDepthStencilBufferRT , ClearFlag . Depth ) ;
}
// Clear GBuffers
if ( ! m_Asset . globalRenderingSettings . ShouldUseForwardRenderingOnly ( ) )
if ( ! camera . useForwardOnly )
{
using ( new ProfilingSample ( cmd , "Clear GBuffer" , GetSampler ( CustomSamplerId . ClearGBuffer ) ) )
{