} ;
#endif
// TODO: Might be worth migrating these to CoreUtils, couldn't use HDCamera anymore
RenderTexture CreateRenderTexture ( RenderTextureDescriptor baseDesc , int depthBufferBits , RenderTextureFormat format ,
RenderTextureReadWrite readWrite = RenderTextureReadWrite . Default )
{
baseDesc . depthBufferBits = depthBufferBits ;
baseDesc . colorFormat = format ;
baseDesc . sRGB = ( readWrite ! = RenderTextureReadWrite . Linear ) ;
// TODO: Explicit MSAA support will come in later
return new RenderTexture ( baseDesc ) ;
}
void CreateCmdTemporaryRT ( CommandBuffer cmd , int nameID , RenderTextureDescriptor baseDesc ,
int depthBufferBits , FilterMode filter , RenderTextureFormat format ,
RenderTextureReadWrite readWrite = RenderTextureReadWrite . Default , int msaaSamples = 1 , bool enableRandomWrite = false )
{
baseDesc . depthBufferBits = depthBufferBits ;
baseDesc . colorFormat = format ;
baseDesc . sRGB = ( readWrite ! = RenderTextureReadWrite . Linear ) ;
baseDesc . msaaSamples = msaaSamples ;
baseDesc . enableRandomWrite = enableRandomWrite ;
cmd . GetTemporaryRT ( nameID , baseDesc , filter ) ;
}
void CreateDepthStencilBuffer ( HDCamera hdCamera )
{
var camera = hdCamera . camera ;
m_CameraDepthStencilBuffer = CreateRenderTexture ( hdCamera . renderTextureDesc , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthStencilBuffer = CoreUtils . C reateRenderTexture ( hdCamera . renderTextureDesc , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthStencilBuffer . filterMode = FilterMode . Point ;
m_CameraDepthStencilBuffer . Create ( ) ;
m_CameraDepthStencilBufferRT = new RenderTargetIdentifier ( m_CameraDepthStencilBuffer ) ;
if ( m_CameraDepthBufferCopy ! = null )
m_CameraDepthBufferCopy . Release ( ) ;
m_CameraDepthBufferCopy = CreateRenderTexture ( hdCamera . renderTextureDesc , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthBufferCopy = CoreUtils . C reateRenderTexture ( hdCamera . renderTextureDesc , 2 4 , RenderTextureFormat . Depth ) ;
m_CameraDepthBufferCopy . filterMode = FilterMode . Point ;
m_CameraDepthBufferCopy . Create ( ) ;
m_CameraDepthBufferCopyRT = new RenderTargetIdentifier ( m_CameraDepthBufferCopy ) ;
if ( m_CameraStencilBufferCopy ! = null )
m_CameraStencilBufferCopy . Release ( ) ;
m_CameraStencilBufferCopy = CreateRenderTexture ( hdCamera . renderTextureDesc , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_CameraStencilBufferCopy = CoreUtils . C reateRenderTexture ( hdCamera . renderTextureDesc , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_CameraStencilBufferCopy . filterMode = FilterMode . Point ;
m_CameraStencilBufferCopy . Create ( ) ;
m_CameraStencilBufferCopyRT = new RenderTargetIdentifier ( m_CameraStencilBufferCopy ) ;
var desc = hdCamera . renderTextureDesc ;
desc . width = ( desc . width + 7 ) / 8 ;
desc . height = ( desc . height + 7 ) / 8 ;
m_HTile = CreateRenderTexture ( desc , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_HTile = CoreUtils . C reateRenderTexture ( desc , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_HTile . filterMode = FilterMode . Point ;
m_HTile . enableRandomWrite = true ;
m_HTile . Create ( ) ;
using ( new ProfilingSample ( cmd , "Deferred directional shadows" , GetSampler ( CustomSamplerId . RenderDeferredDirectionalShadow ) ) )
{
cmd . ReleaseTemporaryRT ( m_DeferredShadowBuffer ) ;
CreateCmdTemporaryRT ( cmd , m_DeferredShadowBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGB32 , RenderTextureReadWrite . Linear , 1 , true ) ;
CoreUtils . C reateCmdTemporaryRT ( cmd , m_DeferredShadowBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGB32 , RenderTextureReadWrite . Linear , 1 , true ) ;
m_LightLoop . RenderDeferredDirectionalShadow ( hdCamera , m_DeferredShadowBufferRT , GetDepthTexture ( ) , cmd ) ;
PushFullScreenDebugTexture ( cmd , m_DeferredShadowBuffer , hdCamera , renderContext , FullScreenDebugMode . DeferredShadows ) ;
}
using ( new ProfilingSample ( cmd , "Distortion" , GetSampler ( CustomSamplerId . Distortion ) ) )
{
cmd . ReleaseTemporaryRT ( m_DistortionBuffer ) ;
CreateCmdTemporaryRT ( cmd , m_DistortionBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , Builtin . GetDistortionBufferFormat ( ) , Builtin . GetDistortionBufferReadWrite ( ) ) ;
CoreUtils . C reateCmdTemporaryRT ( cmd , m_DistortionBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , Builtin . GetDistortionBufferFormat ( ) , Builtin . GetDistortionBufferReadWrite ( ) ) ;
cmd . SetRenderTarget ( m_DistortionBufferRT , m_CameraDepthStencilBufferRT ) ;
cmd . ClearRenderTarget ( false , true , Color . clear ) ;
if ( settings . IsEnabledAndSupported ( null ) )
{
cmd . ReleaseTemporaryRT ( HDShaderIDs . _AmbientOcclusionTexture ) ;
CreateCmdTemporaryRT ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera . renderTextureDesc , 0 , FilterMode . Bilinear , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear , msaaSamples : 1 , enableRandomWrite : true ) ;
CoreUtils . C reateCmdTemporaryRT ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera . renderTextureDesc , 0 , FilterMode . Bilinear , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear , msaaSamples : 1 , enableRandomWrite : true ) ;
postProcessLayer . BakeMSVOMap ( cmd , camera , HDShaderIDs . _AmbientOcclusionTexture , GetDepthTexture ( ) , true ) ;
cmd . SetGlobalVector ( HDShaderIDs . _AmbientOcclusionParam , new Vector4 ( settings . color . value . r , settings . color . value . g , settings . color . value . b , settings . directLightingStrength . value ) ) ;
PushFullScreenDebugTexture ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera , renderContext , FullScreenDebugMode . SSAO ) ;
m_CameraMotionVectorsMaterial . SetVector ( HDShaderIDs . _CameraPosDiff , hdcam . prevCameraPos - hdcam . cameraPos ) ;
cmd . ReleaseTemporaryRT ( m_VelocityBuffer ) ;
CreateCmdTemporaryRT ( cmd , m_VelocityBuffer , hdcam . renderTextureDesc , 0 , FilterMode . Point , Builtin . GetVelocityBufferFormat ( ) , Builtin . GetVelocityBufferReadWrite ( ) ) ;
CoreUtils . C reateCmdTemporaryRT ( cmd , m_VelocityBuffer , hdcam . renderTextureDesc , 0 , FilterMode . Point , Builtin . GetVelocityBufferFormat ( ) , Builtin . GetVelocityBufferReadWrite ( ) ) ;
CoreUtils . DrawFullScreen ( cmd , m_CameraMotionVectorsMaterial , m_VelocityBufferRT , null , 0 ) ;
cmd . SetRenderTarget ( m_VelocityBufferRT , m_CameraDepthStencilBufferRT ) ;
{
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 . ReleaseTemporaryRT ( m_DebugFullScreenTempRT ) ;
CreateCmdTemporaryRT ( cb , m_DebugFullScreenTempRT , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
CoreUtils . C reateCmdTemporaryRT ( cb , m_DebugFullScreenTempRT , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
cb . Blit ( textureID , m_DebugFullScreenTempRT ) ;
}
}
desc . width = desc . width > > mipIndex ;
desc . height = desc . height > > mipIndex ;
CreateCmdTemporaryRT ( cmd , m_DebugFullScreenTempRT , desc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
CoreUtils . C reateCmdTemporaryRT ( cmd , m_DebugFullScreenTempRT , desc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ; // TODO: Support tex arrays
}
desc . width = desc . width > > mipIndex ;
desc . height = desc . height > > mipIndex ;
CreateCmdTemporaryRT ( cmd , m_DebugFullScreenTempRT , desc , 0 , FilterMode . Point , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear ) ;
CoreUtils . C reateCmdTemporaryRT ( cmd , m_DebugFullScreenTempRT , desc , 0 , FilterMode . Point , RenderTextureFormat . RFloat , RenderTextureReadWrite . Linear ) ;
cmd . CopyTexture ( textureID , 0 , mipIndex , m_DebugFullScreenTempRT , 0 , 0 ) ; // TODO: Support tex arrays
}
cmd . ReleaseTemporaryRT ( m_CameraColorBuffer ) ;
cmd . ReleaseTemporaryRT ( m_CameraSssDiffuseLightingBuffer ) ;
CreateCmdTemporaryRT ( cmd , m_CameraColorBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CreateCmdTemporaryRT ( cmd , m_CameraSssDiffuseLightingBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CoreUtils . C reateCmdTemporaryRT ( cmd , m_CameraColorBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CoreUtils . C reateCmdTemporaryRT ( cmd , m_CameraSssDiffuseLightingBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CreateCmdTemporaryRT ( cmd , m_CameraFilteringBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CoreUtils . C reateCmdTemporaryRT ( cmd , m_CameraFilteringBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
}
// Color and depth pyramids