}
Material m_Material ;
CommandBuffer m_Command ;
// For the AO buffer, use R8 or RHalf if available.
static RenderTextureFormat GetAOBufferFormat ( )
m_Material . hideFlags = HideFlags . DontSave ;
}
public void Render ( ScreenSpaceAmbientOcclusionSettings . Settings settings , HDRenderPipeline hdRP , HDCamera hdCamera , ScriptableRenderContext renderContext , bool isForward )
public void Render ( ScreenSpaceAmbientOcclusionSettings . Settings settings , HDRenderPipeline hdRP , HDCamera hdCamera , ScriptableRenderContext renderContext , CommandBuffer cmd , bool isForward )
if ( m_Command = = null )
{
m_Command = new CommandBuffer ( ) ;
m_Command . name = "Ambient Occlusion" ;
}
else
{
m_Command . Clear ( ) ;
}
m_Command . SetGlobalTexture ( Uniforms . _AOBuffer , UnityEngine . Rendering . PostProcessing . RuntimeUtilities . blackTexture ) ; // Neutral is black, see the comment in the shaders
renderContext . ExecuteCommandBuffer ( m_Command ) ;
cmd . SetGlobalTexture ( Uniforms . _AOBuffer , UnityEngine . Rendering . PostProcessing . RuntimeUtilities . blackTexture ) ; // Neutral is black, see the comment in the shaders
renderContext . ExecuteCommandBuffer ( cmd ) ;
return ;
}
m_Material . SetFloat ( Uniforms . _Downsample , 1.0f / downsize ) ;
m_Material . SetFloat ( Uniforms . _SampleCount , settings . sampleCount ) ;
// AO estimation.
m_Command . GetTemporaryRT ( Uniforms . _TempTex1 , width / downsize , height / downsize , 0 , kFilter , kTempFormat , kRWMode ) ;
Utilities . DrawFullScreen ( m_Command , m_Material , Uniforms . _TempTex1 , null , 0 ) ;
hdRP . PushFullScreenDebugTexture ( m_Command , Uniforms . _TempTex1 , hdCamera . camera , renderContext , FullScreenDebugMode . SSAOBeforeFiltering ) ;
renderContext . ExecuteCommandBuffer ( cmd ) ;
cmd . Clear ( ) ;
// Denoising (horizontal pass).
m_Command . GetTemporaryRT ( Uniforms . _TempTex2 , width , height , 0 , kFilter , kTempFormat , kRWMode ) ;
m_Command . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex1 ) ;
Utilities . DrawFullScreen ( m_Command , m_Material , Uniforms . _TempTex2 , null , 1 ) ;
m_Command . ReleaseTemporaryRT ( Uniforms . _TempTex1 ) ;
using ( new Utilities . ProfilingSample ( "Screenspace ambient occlusion" , cmd ) )
{
// AO estimation.
cmd . GetTemporaryRT ( Uniforms . _TempTex1 , width / downsize , height / downsize , 0 , kFilter , kTempFormat , kRWMode ) ;
Utilities . DrawFullScreen ( cmd , m_Material , Uniforms . _TempTex1 , null , 0 ) ;
hdRP . PushFullScreenDebugTexture ( cmd , Uniforms . _TempTex1 , hdCamera . camera , renderContext , FullScreenDebugMode . SSAOBeforeFiltering ) ;
// Denoising (vertical pass).
m_Command . GetTemporaryRT ( Uniforms . _TempTex1 , width , height , 0 , kFilter , kTempFormat , kRWMode ) ;
m_Command . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex2 ) ;
Utilities . DrawFullScreen ( m_Command , m_Material , Uniforms . _TempTex1 , null , 2 ) ;
m_Command . ReleaseTemporaryRT ( Uniforms . _TempTex2 ) ;
// Denoising (horizontal pass).
cmd . GetTemporaryRT ( Uniforms . _TempTex2 , width , height , 0 , kFilter , kTempFormat , kRWMode ) ;
cmd . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex1 ) ;
Utilities . DrawFullScreen ( cmd , m_Material , Uniforms . _TempTex2 , null , 1 ) ;
cmd . ReleaseTemporaryRT ( Uniforms . _TempTex1 ) ;
// Final filtering
m_Command . GetTemporaryRT ( Uniforms . _AOBuffer , width , height , 0 , kFilter , GetAOBufferFormat ( ) , kRWMode ) ;
m_Command . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex1 ) ;
Utilities . DrawFullScreen ( m_Command , m_Material , Uniforms . _AOBuffer , null , 3 ) ;
m_Command . ReleaseTemporaryRT ( Uniforms . _TempTex1 ) ;
// Denoising (vertical pass).
cmd . GetTemporaryRT ( Uniforms . _TempTex1 , width , height , 0 , kFilter , kTempFormat , kRWMode ) ;
cmd . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex2 ) ;
Utilities . DrawFullScreen ( cmd , m_Material , Uniforms . _TempTex1 , null , 2 ) ;
cmd . ReleaseTemporaryRT ( Uniforms . _TempTex2 ) ;
// Setup texture for lighting pass (automagic of unity)
m_Command . SetGlobalTexture ( "_AmbientOcclusionTexture" , Uniforms . _AOBuffer ) ;
hdRP . PushFullScreenDebugTexture ( m_Command , Uniforms . _AOBuffer , hdCamera . camera , renderContext , FullScreenDebugMode . SSAO ) ;
// Final filtering
cmd . GetTemporaryRT ( Uniforms . _AOBuffer , width , height , 0 , kFilter , GetAOBufferFormat ( ) , kRWMode ) ;
cmd . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex1 ) ;
Utilities . DrawFullScreen ( cmd , m_Material , Uniforms . _AOBuffer , null , 3 ) ;
cmd . ReleaseTemporaryRT ( Uniforms . _TempTex1 ) ;
// Register the command buffer and release it.
renderContext . ExecuteCommandBuffer ( m_Command ) ;
// Setup texture for lighting pass (automagic of unity)
cmd . SetGlobalTexture ( "_AmbientOcclusionTexture" , Uniforms . _AOBuffer ) ;
hdRP . PushFullScreenDebugTexture ( cmd , Uniforms . _AOBuffer , hdCamera . camera , renderContext , FullScreenDebugMode . SSAO ) ;
}
}
public void Cleanup ( )