using UnityEngine ;
using UnityEngine.Rendering ;
using UnityEngine.Experimental.PostProcessing ;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
internal static readonly int _Radius = Shader . PropertyToID ( "_Radius" ) ;
internal static readonly int _Downsample = Shader . PropertyToID ( "_Downsample" ) ;
internal static readonly int _SampleCount = Shader . PropertyToID ( "_SampleCount" ) ;
internal static readonly int _MainTex = Shader . PropertyToID ( "_MainTex" ) ;
internal static readonly int _AOBuffer = Shader . PropertyToID ( "_AmbientOcclusionTexture" ) ;
internal static readonly int _TempTex1 = Shader . PropertyToID ( "_TempTex1" ) ;
internal static readonly int _TempTex2 = Shader . PropertyToID ( "_TempTex2" ) ;
PropertySheet m_Sheet ;
Material m_Material ;
readonly RenderTargetIdentifier m_AmbientOcclusionRT ;
public void Build ( RenderPipelineResources renderPipelinesResources )
{
var material = Utilities . CreateEngineMaterial ( "Hidden/HDPipeline/ScreenSpace/AmbientOcclusion" ) ;
// TODO: Don't we need to also free the material ?
m_Sheet = new PropertySheet ( material ) ;
m_Material = Utilities . CreateEngineMaterial ( "Hidden/HDPipeline/ScreenSpace/AmbientOcclusion" ) ;
m_Material . hideFlags = HideFlags . DontSave ;
public void Render ( ScreenSpaceAmbientOcclusionSettings . Settings settings , Camera camera , ScriptableRenderContext renderContext , RenderTargetIdentifier depthID , bool isForward )
public void Render ( ScreenSpaceAmbientOcclusionSettings . Settings settings , HDCamera hdCamera , ScriptableRenderContext renderContext , RenderTargetIdentifier depthID , bool isForward )
{
const RenderTextureFormat kFormat = RenderTextureFormat . ARGB32 ;
const RenderTextureReadWrite kRWMode = RenderTextureReadWrite . Linear ;
return ;
}
var width = camera . pixelWidth ;
var height = camera . pixelHeight ;
var width = hdCamera . camera . pixelWidth ;
var height = hdCamera . camera . pixelHeight ;
m_Sheet . properties . SetFloat ( Uniforms . _Intensity , settings . intensity ) ;
m_Sheet . properties . SetFloat ( Uniforms . _Radius , settings . radius ) ;
m_Sheet . properties . SetFloat ( Uniforms . _Downsample , 1.0f / downsize ) ;
m_Sheet . properties . SetFloat ( Uniforms . _SampleCount , settings . sampleCount ) ;
m_Material . SetFloat ( Uniforms . _Intensity , settings . intensity ) ;
m_Material . SetFloat ( Uniforms . _Radius , settings . radius ) ;
m_Material . SetFloat ( Uniforms . _Downsample , 1.0f / downsize ) ;
m_Material . SetFloat ( Uniforms . _SampleCount , settings . sampleCount ) ;
// Start building a command buffer.
var cmd = new CommandBuffer { name = "Ambient Occlusion" } ;
// AO estimation.
cmd . GetTemporaryRT ( Uniforms . _TempTex1 , width / downsize , height / downsize , 0 , kFilter , kFormat , kRWMode ) ;
cmd . BlitFullscreenTriangle ( depthID , Uniforms . _TempTex1 , m_Sheet , 0 ) ;
cmd . SetGlobalTexture ( Uniforms . _MainTex , depthID ) ;
Utilities . DrawFullScreen ( cmd , m_Material , hdCamera , Uniforms . _TempTex1 , null , 0 ) ;
cmd . BlitFullscreenTriangle ( Uniforms . _TempTex1 , Uniforms . _TempTex2 , m_Sheet , 1 ) ;
cmd . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex1 ) ;
Utilities . DrawFullScreen ( cmd , m_Material , hdCamera , Uniforms . _TempTex2 , null , 1 ) ;
cmd . BlitFullscreenTriangle ( Uniforms . _TempTex2 , Uniforms . _TempTex1 , m_Sheet , 2 ) ;
cmd . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex2 ) ;
Utilities . DrawFullScreen ( cmd , m_Material , hdCamera , Uniforms . _TempTex1 , null , 2 ) ;
cmd . BlitFullscreenTriangle ( Uniforms . _TempTex1 , Uniforms . _AOBuffer , depthID , m_Sheet , 3 ) ;
cmd . SetGlobalTexture ( Uniforms . _MainTex , Uniforms . _TempTex1 ) ;
Utilities . DrawFullScreen ( cmd , m_Material , hdCamera , Uniforms . _AOBuffer , null , 3 ) ;
cmd . ReleaseTemporaryRT ( Uniforms . _TempTex1 ) ;
// Setup texture for lighting pass (automagic of unity)
public void Cleanup ( )
{
if ( m_Sheet ! = null )
m_Sheet . Release ( ) ;
if ( m_Material ! = null )
{
if ( Application . isPlaying )
Object . Destroy ( m_Material ) ;
else
Object . DestroyImmediate ( m_Material ) ;
}
}
}
}