using ( new ProfilingSample ( cmd , "Forward" , CustomSamplerId . Forward . GetSampler ( ) ) )
{
Core Utils. SetRenderTarget ( cmd , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . Color | ClearFlag . Depth ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . Color | ClearFlag . Depth ) ;
RenderOpaqueRenderList ( m_CullResults , camera , renderContext , cmd , HDShaderPassNames . s_ForwardName ) ;
RenderTransparentRenderList ( m_CullResults , camera , renderContext , cmd , HDShaderPassNames . s_ForwardName ) ;
}
// For material classification we use compute shader and so can't read into the stencil, so prepare it.
using ( new ProfilingSample ( cmd , "Clear and copy stencil texture" , CustomSamplerId . ClearAndCopyStencilTexture . GetSampler ( ) ) )
{
Core Utils. SetRenderTarget ( cmd , m_CameraStencilBufferCopy , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraStencilBufferCopy , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
// In the material classification shader we will simply test is we are no lighting
// Use ShaderPassID 1 => "Pass 1 - Write 1 if value different from stencilRef to output"
RenderDeferredLighting ( hdCamera , cmd ) ;
RenderForward ( m_CullResults , hdCamera , renderContext , cmd , ForwardPass . Opaque ) ;
RenderForwardError ( m_CullResults , c amera, renderContext , cmd , ForwardPass . Opaque ) ;
RenderForwardError ( m_CullResults , hdC amera, renderContext , cmd , ForwardPass . Opaque ) ;
// SSS pass here handle both SSS material from deferred and forward
m_SSSBufferManager . SubsurfaceScatteringPass ( hdCamera , cmd , diffusionProfileSettings , m_FrameSettings ,
// Render pre refraction objects
RenderForward ( m_CullResults , hdCamera , renderContext , cmd , ForwardPass . PreRefraction ) ;
RenderForwardError ( m_CullResults , c amera, renderContext , cmd , ForwardPass . PreRefraction ) ;
RenderForwardError ( m_CullResults , hdC amera, renderContext , cmd , ForwardPass . PreRefraction ) ;
RenderForwardError ( m_CullResults , c amera, renderContext , cmd , ForwardPass . Transparent ) ;
RenderForwardError ( m_CullResults , hdC amera, renderContext , cmd , ForwardPass . Transparent ) ;
RenderTransparentDepthPostpass ( m_CullResults , c amera, renderContext , cmd , ForwardPass . Transparent ) ;
RenderTransparentDepthPostpass ( m_CullResults , hdC amera, renderContext , cmd , ForwardPass . Transparent ) ;
PushFullScreenDebugTexture ( cmd , m_CameraColorBuffer , hdCamera , FullScreenDebugMode . NanTracker ) ;
}
else
{
using ( new ProfilingSample ( cmd , "Blit to final RT" , CustomSamplerId . BlitToFinalRT . GetSampler ( ) ) )
using ( new ProfilingSample ( cmd , "Blit to final RT" , CustomSamplerId . CopyDepthForSceneView . GetSampler ( ) ) )
cmd . Blit ( m_CameraColorBuffer , BuiltinRenderTextureType . CameraTarget ) ;
HDUtils . BlitCameraTexture ( cmd , hdCamera , m_CameraColorBuffer , BuiltinRenderTextureType . CameraTarget ) ;
}
}
}
// Make sure RenderDebug does not change the current Render Target
if ( camera . cameraType = = CameraType . SceneView )
{
m_CopyDepth . SetTexture ( HDShaderIDs . _InputDepth , m_CameraDepthStencilBuffer ) ;
cmd . Blit ( null , BuiltinRenderTextureType . CameraTarget , m_CopyDepth ) ;
using ( new ProfilingSample ( cmd , "Copy Depth For SceneView" , CustomSamplerId . BlitToFinalRT . GetSampler ( ) ) )
{
m_CopyDepth . SetTexture ( HDShaderIDs . _InputDepth , m_CameraDepthStencilBuffer ) ;
cmd . Blit ( null , BuiltinRenderTextureType . CameraTarget , m_CopyDepth ) ;
}
}
#endif
using ( new ProfilingSample ( cmd , addAlphaTestedOnly ? "Depth Prepass alpha test" : "Depth Prepass" , CustomSamplerId . DepthPrepass . GetSampler ( ) ) )
{
Core Utils. SetRenderTarget ( cmd , m_CameraDepthStencilBuffer ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraDepthStencilBuffer ) ;
if ( forcePrepass | | ( addFullDepthPrepass & & ! addAlphaTestedOnly ) ) // Always true in case of forward rendering, use in case of deferred rendering if requesting a full depth prepass
{
// We render first the opaque object as opaque alpha tested are more costly to render and could be reject by early-z (but not Hi-z as it is disable with clip instruction)
using ( new ProfilingSample ( cmd , m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) ? "GBufferDebugDisplay" : "GBuffer" , CustomSamplerId . GBuffer . GetSampler ( ) ) )
{
// setup GBuffer for rendering
Core Utils. SetRenderTarget ( cmd , m_GbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_GbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer ) ;
// Render opaque objects into GBuffer
if ( m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) )
// Depth texture is now ready, bind it.
cmd . SetGlobalTexture ( HDShaderIDs . _MainDepthTexture , GetDepthTexture ( ) ) ;
Core Utils. SetRenderTarget ( cmd , m_DbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
HD Utils. SetRenderTarget ( cmd , camera , m_DbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
DecalSystem . instance . Render ( renderContext , camera , cmd ) ;
}
}
}
else
{
Core Utils. SetRenderTarget ( cmd , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . All , CoreUtils . clearColorAllBlack ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . All , CoreUtils . clearColorAllBlack ) ;
// Render Opaque forward
RenderOpaqueRenderList ( cull , hdCamera . camera , renderContext , cmd , m_AllForwardDebugDisplayPassNames , m_currentRendererConfigurationBakedLighting ) ;
{
using ( new ProfilingSample ( cmd , "Blit DebugView Material Debug" , CustomSamplerId . BlitDebugViewMaterialDebug . GetSampler ( ) ) )
{
cmd . Blit ( m_CameraColorBuffer , BuiltinRenderTextureType . CameraTarget ) ;
HDUtils . BlitCameraTexture ( cmd , hdCamera , m_CameraColorBuffer , BuiltinRenderTextureType . CameraTarget ) ;
}
}
}
if ( settings . IsEnabledAndSupported ( null ) )
{
postProcessLayer . BakeMSVOMap ( cmd , camera , HDShaderIDs . _AmbientOcclusionTexture , GetDepthTexture ( ) , true ) ;
postProcessLayer . BakeMSVOMap ( cmd , camera , m_AmbientOcclusionBuffer , GetDepthTexture ( ) , true ) ;
PushFullScreenDebugTexture ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera , FullScreenDebugMode . SSAO ) ;
PushFullScreenDebugTexture ( cmd , m_AmbientOcclusionBuffer , hdCamera , FullScreenDebugMode . SSAO ) ;
return ;
}
}
m_MRTWithSSS [ i + 2 ] = m_SSSBufferManager . GetSSSBuffer ( i ) ;
}
Core Utils. SetRenderTarget ( cmd , m_MRTWithSSS , m_CameraDepthStencilBuffer ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_MRTWithSSS , m_CameraDepthStencilBuffer ) ;
Core Utils. SetRenderTarget ( cmd , m_CameraColorBuffer , m_CameraDepthStencilBuffer ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer ) ;
}
if ( m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) )
}
else
{
Core Utils. SetRenderTarget ( cmd , m_CameraColorBuffer , m_CameraDepthStencilBuffer ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer ) ;
var passNames = m_CurrentDebugDisplaySettings . IsDebugDisplayEnabled ( ) ? m_AllTransparentDebugDisplayPassNames : m_AllTransparentPassNames ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , passNames , m_currentRendererConfigurationBakedLighting , pass = = ForwardPass . PreRefraction ? k_RenderQueue_PreRefraction : k_RenderQueue_Transparent ) ;
// This is use to Display legacy shader with an error shader
[Conditional("DEVELOPMENT_BUILD"), Conditional("UNITY_EDITOR")]
void RenderForwardError ( CullResults cullResults , Camera c amera, ScriptableRenderContext renderContext , CommandBuffer cmd , ForwardPass pass )
void RenderForwardError ( CullResults cullResults , HDCamera hdC amera, ScriptableRenderContext renderContext , CommandBuffer cmd , ForwardPass pass )
Core Utils. SetRenderTarget ( cmd , m_CameraColorBuffer , m_CameraDepthStencilBuffer ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer ) ;
RenderOpaqueRenderList ( cullResults , camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , null , null , m_ErrorMaterial ) ;
RenderOpaqueRenderList ( cullResults , hdCamera . camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , null , null , m_ErrorMaterial ) ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , pass = = ForwardPass . PreRefraction ? k_RenderQueue_PreRefraction : k_RenderQueue_Transparent , null , m_ErrorMaterial ) ;
RenderTransparentRenderList ( cullResults , hdCamera . camera , renderContext , cmd , m_ForwardErrorPassNames , 0 , pass = = ForwardPass . PreRefraction ? k_RenderQueue_PreRefraction : k_RenderQueue_Transparent , null , m_ErrorMaterial ) ;
void RenderTransparentDepthPostpass ( CullResults cullResults , Camera c amera, ScriptableRenderContext renderContext , CommandBuffer cmd , ForwardPass pass )
void RenderTransparentDepthPostpass ( CullResults cullResults , HDCamera hdC amera, ScriptableRenderContext renderContext , CommandBuffer cmd , ForwardPass pass )
{
if ( ! m_FrameSettings . enableTransparentPostpass )
return ;
CoreUtils . SetRenderTarget ( cmd , m_CameraDepthStencilBuffer ) ;
RenderTransparentRenderList ( cullResults , camera , renderContext , cmd , m_TransparentDepthPostpassNames ) ;
HDUtils . SetRenderTarget ( cmd , hdCamera , m_CameraDepthStencilBuffer ) ;
RenderTransparentRenderList ( cullResults , hdCamera . camera , renderContext , cmd , m_TransparentDepthPostpassNames ) ;
}
}
}
}
public void PushColorPickerDebugTexture ( CommandBuffer cmd , RenderTargetIdentifier textureID , HDCamera hdCamera )
public void PushColorPickerDebugTexture ( CommandBuffer cmd , RTHandle textureID , HDCamera hdCamera )
cmd . Blit ( textureID , m_DebugColorPickerBuffer ) ;
HDUtils . BlitCameraTexture ( cmd , hdCamera , textureID , m_DebugColorPickerBuffer ) ;
public void PushFullScreenDebugTexture ( CommandBuffer cmd , RenderTargetIdentifier textureID , HDCamera hdCamera , FullScreenDebugMode debugMode )
public void PushFullScreenDebugTexture ( CommandBuffer cmd , RTHandle textureID , HDCamera hdCamera , FullScreenDebugMode debugMode )
m_FullScreenDebugPushed = true ; // We need this flag because otherwise if no full screen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
cmd . Blit ( textureID , m_DebugFullScreenTempBuffer ) ;
m_FullScreenDebugPushed = true ; // We need this flag because otherwise if no full screen debug is pushed (like for example if the corresponding pass is disabled), when we render the result in RenderDebug m_DebugFullScreenTempBuffer will contain potential garbage
HDUtils . BlitCameraTexture ( cmd , hdCamera , textureID , m_DebugFullScreenTempBuffer ) ;
}
}
{
var mipIndex = Mathf . FloorToInt ( m_CurrentDebugDisplaySettings . fullscreenDebugMip * ( lodCount ) ) ;
m_FullScreenDebugPushed = true ; // We need this flag because otherwise if no full screen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
m_FullScreenDebugPushed = true ; // We need this flag because otherwise if no full screen debug is pushed (like for example if the corresponding pass is disabled), when we render the result in RenderDebug m_DebugFullScreenTempBuffer will contain potential garbage
cmd . CopyTexture ( texture , 0 , mipIndex , m_DebugFullScreenTempBuffer , 0 , 0 ) ; // TODO: Support tex arrays
}
}
{
var mipIndex = Mathf . FloorToInt ( m_CurrentDebugDisplaySettings . fullscreenDebugMip * ( lodCount ) ) ;
m_FullScreenDebugPushed = true ; // We need this flag because otherwise if no fullscreen debug is pushed, when we render the result in RenderDebug the temporary RT will not exist.
m_FullScreenDebugPushed = true ; // We need this flag because otherwise if no full screen debug is pushed (like for example if the corresponding pass is disabled), when we render the result in RenderDebug m_DebugFullScreenTempBuffer will contain potential garbage
}
public void PushFullScreenDebugTexture ( CommandBuffer cb , int textureID , HDCamera hdCamera , FullScreenDebugMode debugMode )
{
PushFullScreenDebugTexture ( cb , new RenderTargetIdentifier ( textureID ) , hdCamera , debugMode ) ;
}
void RenderDebug ( HDCamera hdCamera , CommandBuffer cmd )
// Clear depth/stencil and init buffers
using ( new ProfilingSample ( cmd , "Clear Depth/Stencil" , CustomSamplerId . ClearDepthStencil . GetSampler ( ) ) )
{
Core Utils. SetRenderTarget ( cmd , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . Depth ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . Depth ) ;
Core Utils. SetRenderTarget ( cmd , m_CameraSssDiffuseLightingBuffer , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraSssDiffuseLightingBuffer , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
}
// TODO: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
{
Color clearColor = hdCamera . camera . backgroundColor . linear ; // Need it in linear because we clear a linear fp16 texture.
Core Utils. SetRenderTarget ( cmd , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . Color , clearColor ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_CameraColorBuffer , m_CameraDepthStencilBuffer , ClearFlag . Color , clearColor ) ;
}
// Clear GBuffers
{
Core Utils. SetRenderTarget ( cmd , m_GbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
HD Utils. SetRenderTarget ( cmd , hdCamera , m_GbufferManager . GetBuffersRTI ( ) , m_CameraDepthStencilBuffer , ClearFlag . Color , CoreUtils . clearColorAllBlack ) ;
}
}
// END TEMP