// Detect when windows size is changing
int m_CurrentWidth ;
int m_CurrentHeight ;
int m_CurrentMSAASampleCount ;
// Use to detect frame changes
int m_FrameCount ;
if ( m_CameraStencilBufferCopy ! = null )
m_CameraStencilBufferCopy . Release ( ) ;
// TODO: This might fail allocation with MSAA
m_CameraStencilBufferCopy = CoreUtils . CreateRenderTexture ( hdCamera . renderTextureDesc , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear ) ; // DXGI_FORMAT_R8_UINT is not supported by Unity
m_CameraStencilBufferCopy . filterMode = FilterMode . Point ;
m_CameraStencilBufferCopy . Create ( ) ;
var desc = hdCamera . renderTextureDesc ;
var texWidth = desc . width ;
var texHeight = desc . height ;
var sampleCount = desc . msaaSamples ;
bool resolutionChanged = ( texWidth ! = m_CurrentWidth ) | | ( texHeight ! = m_CurrentHeight ) ;
bool resolutionChanged = ( texWidth ! = m_CurrentWidth ) | |
( texHeight ! = m_CurrentHeight ) | |
( sampleCount ! = m_CurrentMSAASampleCount ) ;
m_SSSBufferManager . Resize ( hdCamera ) ;
if ( m_FrameSettings . enableSubsurfaceScattering )
{
// TODO: The R8 target doesn't allocate with MSAA support...
m_SSSBufferManager . Resize ( hdCamera ) ;
}
}
if ( resolutionChanged | | m_LightLoop . NeedResize ( ) )
// update recorded window resolution
m_CurrentWidth = texWidth ;
m_CurrentHeight = texHeight ;
m_CurrentMSAASampleCount = sampleCount ;
}
public void PushGlobalParams ( HDCamera hdCamera , CommandBuffer cmd , DiffusionProfileSettings sssParameters )
using ( new ProfilingSample ( cmd , "Deferred directional shadows" , CustomSamplerId . RenderDeferredDirectionalShadow . GetSampler ( ) ) )
{
cmd . ReleaseTemporaryRT ( m_DeferredShadowBuffer ) ;
// TODO: For MSAA, we are overriding to 1x, but we'll need to add a Draw path in order to support MSAA properly
CoreUtils . CreateCmdTemporaryRT ( 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 , FullScreenDebugMode . DeferredShadows ) ;
if ( settings . IsEnabledAndSupported ( null ) )
{
cmd . ReleaseTemporaryRT ( HDShaderIDs . _AmbientOcclusionTexture ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera . renderTextureDesc , 0 , FilterMode . Bilinear , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear , msaaSamples : 1 , enableRandomWrite : true ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , HDShaderIDs . _AmbientOcclusionTexture , hdCamera . renderTextureDesc , 0 , FilterMode . Bilinear , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear , msaaSamplesOverride : 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 , FullScreenDebugMode . SSAO ) ;
cmd . ReleaseTemporaryRT ( m_CameraColorBuffer ) ;
cmd . ReleaseTemporaryRT ( m_CameraSssDiffuseLightingBuffer ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraColorBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraSssDiffuseLightingBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
if ( m_FrameSettings . enableMSAA )
{
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraColorBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear ) ;
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraSssDiffuseLightingBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear ) ;
}
else
{
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraColorBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . ARGBHalf , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
CoreUtils . CreateCmdTemporaryRT ( cmd , m_CameraSssDiffuseLightingBuffer , hdCamera . renderTextureDesc , 0 , FilterMode . Point , RenderTextureFormat . RGB111110Float , RenderTextureReadWrite . Linear , 1 , true ) ; // Enable UAV
}
// Color and depth pyramids
m_GaussianPyramidColorBufferDesc = BuildPyramidDescriptor ( hdCamera , PyramidType . Color , m_FrameSettings . enableStereo ) ;
desc . depthBufferBits = 0 ;
desc . useMipMap = true ;
desc . autoGenerateMips = false ;
desc . msaaSamples = 1 ; // These are approximation textures, they don't need MSAA
var pyramidSize = CalculatePyramidSize ( ( int ) hdCamera . screenSize . x , ( int ) hdCamera . screenSize . y ) ;