// 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 ) ;
RenderPyramidDepth ( camera , cmd ) ;
RenderPyramidDepth ( camera , cmd , renderContext , FullScreenDebugMode . DepthPyramid ) ;
// Required for the SSS and the shader feature classification pass.
PrepareAndBindStencilTexture ( cmd ) ;
RenderForward ( m_CullResults , camera , renderContext , cmd , ForwardPass . PreTransparent ) ;
RenderForwardError ( m_CullResults , camera , renderContext , cmd , ForwardPass . PreTransparent ) ;
RenderGaussianPyramidColor ( camera , cmd ) ;
RenderGaussianPyramidColor ( camera , cmd , renderContext , FullScreenDebugMode . PreTransparentColorPyramid ) ;
// Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects.
RenderForward ( m_CullResults , camera , renderContext , cmd , ForwardPass . Transparent ) ;
{
RenderVelocity ( m_CullResults , hdCamera , renderContext , cmd ) ; // Note we may have to render velocity earlier if we do temporalAO, temporal volumetric etc... Mean we will not take into account forward opaque in case of deferred rendering ?
RenderGaussianPyramidColor ( camera , cmd ) ;
RenderGaussianPyramidColor ( camera , cmd , renderContext , FullScreenDebugMode . FinalColorPyramid ) ;
// TODO: Check with VFX team.
// Rendering distortion here have off course lot of artifact.
}
}
void RenderGaussianPyramidColor ( Camera camera , CommandBuffer cmd )
void RenderGaussianPyramidColor ( Camera camera , CommandBuffer cmd , ScriptableRenderContext renderContext , FullScreenDebugMode debugMode )
{
if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . enableGaussianPyramid )
return ;
var last = m_GaussianPyramidColorBuffer ;
var mipSize = size ;
size > > = 1 ;
mipSize > > = 1 ;
cmd . GetTemporaryRT ( HDShaderIDs . _GaussianPyramidColorMips [ i + 1 ] , size , size , 0 , FilterMode . Bilinear , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _GaussianPyramidColorMips [ i + 1 ] , mipSize , mipSize , 0 , FilterMode . Bilinear , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ;
cmd . SetComputeVectorParam ( m_GaussianPyramidCS , "_Size" , new Vector4 ( size , size , 1f / size , 1f / size ) ) ;
cmd . DispatchCompute ( m_GaussianPyramidCS , m_GaussianPyramidKernel , size / 8 , size / 8 , 1 ) ;
cmd . SetComputeVectorParam ( m_GaussianPyramidCS , "_Size" , new Vector4 ( mipSize , mipSize , 1f / mipSize , 1f / mipSize ) ) ;
cmd . DispatchCompute ( m_GaussianPyramidCS , m_GaussianPyramidKernel , mipSize / 8 , mipSize / 8 , 1 ) ;
PushFullScreenDebugTextureMip ( cmd , m_GaussianPyramidColorBufferRT , lodCount , size , size , debugMode ) ;
cmd . SetGlobalTexture ( HDShaderIDs . _GaussianPyramidColorTexture , m_GaussianPyramidColorBuffer ) ;
for ( int i = 0 ; i < lodCount ; i + + )
void RenderPyramidDepth ( Camera camera , CommandBuffer cmd )
void RenderPyramidDepth ( Camera camera , CommandBuffer cmd , ScriptableRenderContext renderContext , FullScreenDebugMode debugMode )
{
if ( ! m_CurrentDebugDisplaySettings . renderingDebugSettings . enableGaussianPyramid )
return ;
m_GPUCopy . SampleCopyChannel_xyzw2x ( cmd , GetDepthTexture ( ) , HDShaderIDs . _DepthPyramidMips [ 0 ] , new Vector2 ( size , size ) ) ;
cmd . CopyTexture ( HDShaderIDs . _DepthPyramidMips [ 0 ] , 0 , 0 , m_DepthPyramidBuffer , 0 , 0 ) ;
var mipSize = size ;
size > > = 1 ;
mipSize > > = 1 ;
cmd . GetTemporaryRT ( HDShaderIDs . _DepthPyramidMips [ i + 1 ] , size , size , 0 , FilterMode . Bilinear , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear , 1 , true ) ;
cmd . GetTemporaryRT ( HDShaderIDs . _DepthPyramidMips [ i + 1 ] , mipSize , mipSize , 0 , FilterMode . Bilinear , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear , 1 , true ) ;
cmd . SetComputeVectorParam ( m_DepthPyramidCS , "_Size" , new Vector4 ( size , size , 1f / size , 1f / size ) ) ;
cmd . DispatchCompute ( m_DepthPyramidCS , m_DepthPyramidKernel , size / 8 , size / 8 , 1 ) ;
cmd . SetComputeVectorParam ( m_DepthPyramidCS , "_Size" , new Vector4 ( mipSize , mipSize , 1f / mipSize , 1f / mipSize ) ) ;
cmd . DispatchCompute ( m_DepthPyramidCS , m_DepthPyramidKernel , mipSize / 8 , mipSize / 8 , 1 ) ;
PushFullScreenDebugDepthMip ( cmd , m_DepthPyramidBufferRT , lodCount , size , size , debugMode ) ;
cmd . SetGlobalTexture ( HDShaderIDs . _DepthPyramidTexture , m_DepthPyramidBuffer ) ;
for ( int i = 0 ; i < lodCount + 1 ; i + + )
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.
cb . GetTemporaryRT ( m_DebugFullScreenTempRT , camera . pixelWidth , camera . pixelHeight , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
cb . Blit ( textureID , m_DebugFullScreenTempRT ) ;
}
}
void PushFullScreenDebugTextureMip ( CommandBuffer cmd , RenderTargetIdentifier textureID , int lodCount , int width , int height , FullScreenDebugMode debugMode )
{
var mipIndex = Mathf . FloorToInt ( m_CurrentDebugDisplaySettings . fullscreenDebugMip * ( lodCount ) ) ;
if ( debugMode = = m_CurrentDebugDisplaySettings . fullScreenDebugMode )
{
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.
cmd . GetTemporaryRT ( m_DebugFullScreenTempRT , width > > mipIndex , height > > mipIndex , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ;
}
}
void PushFullScreenDebugDepthMip ( CommandBuffer cmd , RenderTargetIdentifier textureID , int lodCount , int width , int height , FullScreenDebugMode debugMode )
{
var mipIndex = Mathf . FloorToInt ( m_CurrentDebugDisplaySettings . fullscreenDebugMip * ( lodCount ) ) ;
if ( debugMode = = m_CurrentDebugDisplaySettings . fullScreenDebugMode )
{
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.
cmd . GetTemporaryRT ( m_DebugFullScreenTempRT , width > > mipIndex , height > > mipIndex , 0 , FilterMode . Point , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ;
}
}