@@ -42,7 +42,7 @@ enum Pass
4242 readonly int [ ] m_Widths = new int [ 7 ] ;
4343 readonly int [ ] m_Heights = new int [ 7 ] ;
4444
45- readonly AmbientOcclusion m_Settings ;
45+ AmbientOcclusion m_Settings ;
4646 PropertySheet m_PropertySheet ;
4747 PostProcessResources m_Resources ;
4848
@@ -68,7 +68,7 @@ public DepthTextureMode GetCameraFlags()
6868
6969 // Special case for AO [because SRPs], please don't do this in other effects, it's bad
7070 // practice in this framework
71- internal void SetResources ( PostProcessResources resources )
71+ public void SetResources ( PostProcessResources resources )
7272 {
7373 m_Resources = resources ;
7474 }
@@ -141,7 +141,7 @@ Vector3 GetSizeArray(MipLevel mip)
141141 return new Vector3 ( m_Widths [ ( int ) mip ] , m_Heights [ ( int ) mip ] , 16 ) ;
142142 }
143143
144- void GenerateAOMap ( CommandBuffer cmd , Camera camera , RenderTargetIdentifier destination , RenderTargetIdentifier ? depthMap )
144+ public void GenerateAOMap ( CommandBuffer cmd , Camera camera , RenderTargetIdentifier destination , RenderTargetIdentifier ? depthMap , bool invert )
145145 {
146146 // Base size
147147 m_Widths [ 0 ] = camera . pixelWidth * ( RuntimeUtilities . isSinglePassStereoEnabled ? 2 : 1 ) ;
@@ -170,7 +170,7 @@ void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifier dest
170170 PushUpsampleCommands ( cmd , ShaderIDs . LowDepth4 , ShaderIDs . Occlusion4 , ShaderIDs . LowDepth3 , ShaderIDs . Occlusion3 , ShaderIDs . Combined3 , GetSize ( MipLevel . L4 ) , GetSize ( MipLevel . L3 ) ) ;
171171 PushUpsampleCommands ( cmd , ShaderIDs . LowDepth3 , ShaderIDs . Combined3 , ShaderIDs . LowDepth2 , ShaderIDs . Occlusion2 , ShaderIDs . Combined2 , GetSize ( MipLevel . L3 ) , GetSize ( MipLevel . L2 ) ) ;
172172 PushUpsampleCommands ( cmd , ShaderIDs . LowDepth2 , ShaderIDs . Combined2 , ShaderIDs . LowDepth1 , ShaderIDs . Occlusion1 , ShaderIDs . Combined1 , GetSize ( MipLevel . L2 ) , GetSize ( MipLevel . L1 ) ) ;
173- PushUpsampleCommands ( cmd , ShaderIDs . LowDepth1 , ShaderIDs . Combined1 , ShaderIDs . LinearDepth , null , destination , GetSize ( MipLevel . L1 ) , GetSize ( MipLevel . Original ) ) ;
173+ PushUpsampleCommands ( cmd , ShaderIDs . LowDepth1 , ShaderIDs . Combined1 , ShaderIDs . LinearDepth , null , destination , GetSize ( MipLevel . L1 ) , GetSize ( MipLevel . Original ) , invert ) ;
174174
175175 // Cleanup
176176 PushReleaseCommands ( cmd ) ;
@@ -189,12 +189,12 @@ void PushAllocCommands(CommandBuffer cmd)
189189 AllocArray ( cmd , ShaderIDs . TiledDepth2 , MipLevel . L4 , RenderTextureFormat . RHalf , true ) ;
190190 AllocArray ( cmd , ShaderIDs . TiledDepth3 , MipLevel . L5 , RenderTextureFormat . RHalf , true ) ;
191191 AllocArray ( cmd , ShaderIDs . TiledDepth4 , MipLevel . L6 , RenderTextureFormat . RHalf , true ) ;
192-
192+
193193 Alloc ( cmd , ShaderIDs . Occlusion1 , MipLevel . L1 , RenderTextureFormat . R8 , true ) ;
194194 Alloc ( cmd , ShaderIDs . Occlusion2 , MipLevel . L2 , RenderTextureFormat . R8 , true ) ;
195195 Alloc ( cmd , ShaderIDs . Occlusion3 , MipLevel . L3 , RenderTextureFormat . R8 , true ) ;
196196 Alloc ( cmd , ShaderIDs . Occlusion4 , MipLevel . L4 , RenderTextureFormat . R8 , true ) ;
197-
197+
198198 Alloc ( cmd , ShaderIDs . Combined1 , MipLevel . L1 , RenderTextureFormat . R8 , true ) ;
199199 Alloc ( cmd , ShaderIDs . Combined2 , MipLevel . L2 , RenderTextureFormat . R8 , true ) ;
200200 Alloc ( cmd , ShaderIDs . Combined3 , MipLevel . L3 , RenderTextureFormat . R8 , true ) ;
@@ -345,10 +345,14 @@ void PushRenderCommands(CommandBuffer cmd, int source, int destination, Vector3
345345 ) ;
346346 }
347347
348- void PushUpsampleCommands ( CommandBuffer cmd , int lowResDepth , int interleavedAO , int highResDepth , int ? highResAO , RenderTargetIdentifier dest , Vector3 lowResDepthSize , Vector2 highResDepthSize )
348+ void PushUpsampleCommands ( CommandBuffer cmd , int lowResDepth , int interleavedAO , int highResDepth , int ? highResAO , RenderTargetIdentifier dest , Vector3 lowResDepthSize , Vector2 highResDepthSize , bool invert = false )
349349 {
350350 var cs = m_Resources . computeShaders . multiScaleAOUpsample ;
351- int kernel = cs . FindKernel ( highResAO == null ? "main" : "main_blendout" ) ;
351+ int kernel = cs . FindKernel ( highResAO == null
352+ ? invert
353+ ? "main_invert"
354+ : "main"
355+ : "main_blendout" ) ;
352356
353357 float stepSize = 1920f / lowResDepthSize . x ;
354358 float bTolerance = 1f - Mathf . Pow ( 10f , m_Settings . blurTolerance . value ) * stepSize ;
@@ -377,22 +381,22 @@ void PushUpsampleCommands(CommandBuffer cmd, int lowResDepth, int interleavedAO,
377381 void PushReleaseCommands ( CommandBuffer cmd )
378382 {
379383 Release ( cmd , ShaderIDs . LinearDepth ) ;
380-
384+
381385 Release ( cmd , ShaderIDs . LowDepth1 ) ;
382386 Release ( cmd , ShaderIDs . LowDepth1 ) ;
383387 Release ( cmd , ShaderIDs . LowDepth1 ) ;
384388 Release ( cmd , ShaderIDs . LowDepth1 ) ;
385-
389+
386390 Release ( cmd , ShaderIDs . TiledDepth1 ) ;
387391 Release ( cmd , ShaderIDs . TiledDepth2 ) ;
388392 Release ( cmd , ShaderIDs . TiledDepth3 ) ;
389393 Release ( cmd , ShaderIDs . TiledDepth4 ) ;
390-
394+
391395 Release ( cmd , ShaderIDs . Occlusion1 ) ;
392396 Release ( cmd , ShaderIDs . Occlusion2 ) ;
393397 Release ( cmd , ShaderIDs . Occlusion3 ) ;
394398 Release ( cmd , ShaderIDs . Occlusion4 ) ;
395-
399+
396400 Release ( cmd , ShaderIDs . Combined1 ) ;
397401 Release ( cmd , ShaderIDs . Combined2 ) ;
398402 Release ( cmd , ShaderIDs . Combined3 ) ;
@@ -432,6 +436,7 @@ public void RenderAfterOpaque(PostProcessRenderContext context)
432436 {
433437 var cmd = context . command ;
434438 cmd . BeginSample ( "Ambient Occlusion" ) ;
439+ SetResources ( context . resources ) ;
435440 PreparePropertySheet ( context ) ;
436441 CheckAOTexture ( context ) ;
437442
@@ -446,7 +451,7 @@ public void RenderAfterOpaque(PostProcessRenderContext context)
446451 ) ;
447452 }
448453
449- GenerateAOMap ( cmd , context . camera , m_AmbientOnlyAO , null ) ;
454+ GenerateAOMap ( cmd , context . camera , m_AmbientOnlyAO , null , false ) ;
450455 PushDebug ( context ) ;
451456 cmd . SetGlobalTexture ( ShaderIDs . MSVOcclusionTexture , m_AmbientOnlyAO ) ;
452457 cmd . BlitFullscreenTriangle ( BuiltinRenderTextureType . None , BuiltinRenderTextureType . CameraTarget , m_PropertySheet , ( int ) Pass . CompositionForward ) ;
@@ -457,9 +462,10 @@ public void RenderAmbientOnly(PostProcessRenderContext context)
457462 {
458463 var cmd = context . command ;
459464 cmd . BeginSample ( "Ambient Occlusion Render" ) ;
465+ SetResources ( context . resources ) ;
460466 PreparePropertySheet ( context ) ;
461467 CheckAOTexture ( context ) ;
462- GenerateAOMap ( cmd , context . camera , m_AmbientOnlyAO , null ) ;
468+ GenerateAOMap ( cmd , context . camera , m_AmbientOnlyAO , null , false ) ;
463469 PushDebug ( context ) ;
464470 cmd . EndSample ( "Ambient Occlusion Render" ) ;
465471 }
@@ -496,6 +502,10 @@ public DepthTextureMode GetCameraFlags()
496502 return DepthTextureMode . None ;
497503 }
498504
505+ public void GenerateAOMap ( CommandBuffer cmd , Camera camera , RenderTargetIdentifier destination , RenderTargetIdentifier ? depthMap , bool invert )
506+ {
507+ }
508+
499509 public void RenderAfterOpaque ( PostProcessRenderContext context )
500510 {
501511 }
0 commit comments