private bool m_IntermediateTextureArray ;
private bool m_RequireDepth ;
private bool m_RequireCopyColor ;
private bool m_DepthRenderBuffer ;
private MixedLightingSetup m_MixedLightingSetup ;
private const int kDepthStencilBufferBits = 3 2 ;
ShadowPass ( visibleLights , ref context , ref lightData ) ;
FrameRenderingConfiguration frameRenderingConfiguration ;
SetupFrameRendering ( out frameRenderingConfiguration , stereoEnabled ) ;
SetupFrameRenderingConfiguration ( out frameRenderingConfiguration , stereoEnabled ) ;
SetupIntermediateResources ( frameRenderingConfiguration , ref context ) ;
// SetupCameraProperties does the following:
// Setup global time properties (_Time, _SinTime, _CosTime)
context . SetupCameraProperties ( m_CurrCamera , stereoEnabled ) ;
if ( LightweightUtils . HasFlag ( frameRenderingConfiguration , FrameRenderingConfiguration . DepthPass ) )
if ( LightweightUtils . HasFlag ( frameRenderingConfiguration , FrameRenderingConfiguration . DepthPreP ass ) )
DepthPass ( ref context ) ;
ForwardPass ( visibleLights , frameRenderingConfiguration , ref context , ref lightData , stereoEnabled ) ;
CommandBuffer cmd = CommandBufferPool . Get ( "After Opaque" ) ;
cmd . SetGlobalTexture ( CameraRenderTargetID . depth , m_DepthRT ) ;
bool setRenderTarget = false ;
RenderTargetIdentifier depthRT = m_DepthRT ;
// When only have one effect in the stack. We blit to a work RT then blit it back to active color RT.
// When only have one effect in the stack we blit to a work RT then blit it back to active color RT.
// This seems like an extra blit but it saves us a depth copy/blit which has some corner cases like msaa depth resolve.
if ( m_RequireCopyColor )
{
else
RenderPostProcess ( cmd , m_CurrCameraColorRT , m_CurrCameraColorRT , true ) ;
if ( LightweightUtils . HasFlag ( config , FrameRenderingConfiguration . DepthPass ) )
cmd . SetRenderTarget ( m_CurrCameraColorRT ) ;
else
cmd . SetRenderTarget ( m_CurrCameraColorRT , m_DepthRT ) ;
setRenderTarget = true ;
SetRenderTarget ( cmd , m_CurrCameraColorRT , m_DepthRT ) ;
SetRenderTarget ( cmd , m_CurrCameraColorRT , m_CopyDepth ) ;
depthRT = m_CopyDepth ;
setRenderTarget = true ;
if ( setRenderTarget )
SetRenderTarget ( cmd , m_CurrCameraColorRT , depthRT ) ;
context . ExecuteCommandBuffer ( cmd ) ;
CommandBufferPool . Release ( cmd ) ;
}
}
}
private void SetupFrameRendering ( out FrameRenderingConfiguration configuration , bool stereoEnabled )
private void SetupFrameRenderingConfiguration ( out FrameRenderingConfiguration configuration , bool stereoEnabled )
{
configuration = ( stereoEnabled ) ? FrameRenderingConfiguration . Stereo : FrameRenderingConfiguration . None ;
if ( stereoEnabled & & XRSettings . eyeTextureDesc . dimension = = TextureDimension . Tex2DArray )
m_ColorFormat = hdrEnabled ? RenderTextureFormat . DefaultHDR : RenderTextureFormat . Default ;
m_RequireDepth = false ;
m_RequireCopyColor = false ;
m_DepthRenderBuffer = false ;
m_CameraPostProcessLayer = m_CurrCamera . GetComponent < PostProcessLayer > ( ) ;
bool msaaEnabled = m_CurrCamera . allowMSAA & & m_Asset . MSAASampleCount > 1 & & ( m_CurrCamera . targetTexture = = null | | m_CurrCamera . targetTexture . antiAliasing > 1 ) ;
if ( m_CameraPostProcessLayer . sortedBundles [ PostProcessEvent . BeforeTransparent ] . Count = = 1 )
m_RequireCopyColor = true ;
}
// Resolving depth msaa requires texture2DMS. Currently if msaa is enabled we do a depth pre-pass.
if ( msaaEnabled )
configuration | = FrameRenderingConfiguration . DepthPass ;
}
// In case of soft particles we need depth copy. If depth copy not supported fallback to depth prepass
intermediateTexture = true ;
bool supportsDepthCopy = m_CopyTextureSupport ! = CopyTextureSupport . None & & m_Asset . CopyDepthShader . isSupported ;
// currently fallback to depth prepass if msaa is enabled since. We need texture2DMS to support depth resolve.
configuration | = ( msaaEnabled | | ! supportsDepthCopy ) ? FrameRenderingConfiguration . DepthPass : FrameRenderingConfiguration . DepthCopy ;
}
if ( msaaEnabled )
}
if ( m_RequireDepth )
{
// If msaa is enabled we don't use a depth renderbuffer as we might not have support to Texture2DMS to resolve depth.
// Instead we use a depth prepass and whenever depth is needed we use the 1 sample depth from prepass.
if ( ! msaaEnabled )
{
bool supportsDepthCopy = m_CopyTextureSupport ! = CopyTextureSupport . None & & m_Asset . CopyDepthShader . isSupported ;
m_DepthRenderBuffer = true ;
// Soft particles need separate depth as it reads/write to depth at same time
if ( softParticlesEnabled )
configuration | = ( supportsDepthCopy ) ? FrameRenderingConfiguration . DepthCopy : FrameRenderingConfiguration . DepthPrePass ;
}
else
{
configuration | = FrameRenderingConfiguration . DepthPrePass ;
}
}
Rect cameraRect = m_CurrCamera . rect ;
if ( ! m_IsOffscreenCamera )
colorRT = m_CurrCameraColorRT ;
if ( m_RequireDepth & & ! LightweightUtils . HasFlag ( renderingConfig , FrameRenderingConfiguration . DepthPass ) )
if ( m_RequireDepth )
depthRT = m_DepthRT ;
}
private void SetRenderTarget ( CommandBuffer cmd , RenderTargetIdentifier colorRT , RenderTargetIdentifier depthRT , ClearFlag clearFlag = ClearFlag . None )
{
if ( depthRT = = BuiltinRenderTextureType . None )
if ( depthRT = = BuiltinRenderTextureType . None | | ! m_DepthRenderBuffer )
{
SetRenderTarget ( cmd , colorRT , clearFlag ) ;
return ;