Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.

Commit c33e713

Browse files
committed
More work on MSVO for SRP
1 parent 23dfcb6 commit c33e713

4 files changed

Lines changed: 60 additions & 29 deletions

File tree

PostProcessing/Runtime/Effects/AmbientOcclusion.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ public bool IsAmbientOnly(PostProcessRenderContext context)
118118
&& camera.allowHDR;
119119
}
120120

121-
// This is a special case we need for SRP support on MSVO as we won't be able to rely on
122-
// the context object passed around (it won't be defined by the time AO is rendered)
123-
internal void SetResources(PostProcessResources resources)
124-
{
125-
((MultiScaleVO)m_Methods[1]).SetResources(resources);
126-
}
127-
128121
public IAmbientOcclusionMethod Get()
129122
{
130123
return m_Methods[(int)settings.mode.value];
@@ -141,6 +134,16 @@ public override void Release()
141134
m.Release();
142135
}
143136

137+
public ScalableAO GetScalableAO()
138+
{
139+
return (ScalableAO)m_Methods[(int)AmbientOcclusionMode.ScalableAmbientObscurance];
140+
}
141+
142+
public MultiScaleVO GetMultiScaleVO()
143+
{
144+
return (MultiScaleVO)m_Methods[(int)AmbientOcclusionMode.MultiScaleVolumetricObscurance];
145+
}
146+
144147
// Unused
145148
public override void Render(PostProcessRenderContext context)
146149
{

PostProcessing/Runtime/Effects/MultiScaleVO.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,6 @@ void OnEnable()
119119

120120
debugLayer.OnEnable();
121121

122-
// Special case to enable AO usage in SRPs
123-
GetBundle<AmbientOcclusion>()
124-
.CastRenderer<AmbientOcclusionRenderer>()
125-
.SetResources(m_Resources);
126-
127122
// Scriptable render pipelines handle their own command buffers
128123
if (RuntimeUtilities.scriptableRenderPipelineActive)
129124
return;
@@ -347,7 +342,7 @@ void BuildCommandBuffers()
347342
context.command = m_LegacyCmdBufferOpaque;
348343
aoRenderer.Get().RenderAfterOpaque(context);
349344
}
350-
345+
351346
bool isFogActive = fog.IsEnabledAndSupported(context);
352347
bool hasCustomOpaqueOnlyEffects = HasOpaqueOnlyEffects(context);
353348
int opaqueOnlyEffects = 0;
@@ -440,18 +435,32 @@ void OnPostRender()
440435
}
441436
}
442437

443-
PostProcessBundle GetBundle<T>()
438+
public PostProcessBundle GetBundle<T>()
444439
where T : PostProcessEffectSettings
445440
{
446441
return GetBundle(typeof(T));
447442
}
448443

449-
PostProcessBundle GetBundle(Type settingsType)
444+
public PostProcessBundle GetBundle(Type settingsType)
450445
{
451446
Assert.IsTrue(m_Bundles.ContainsKey(settingsType), "Invalid type");
452447
return m_Bundles[settingsType];
453448
}
454449

450+
public T GetSettings<T>()
451+
where T : PostProcessEffectSettings
452+
{
453+
return GetBundle<T>().CastSettings<T>();
454+
}
455+
456+
public void BakeMSVOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifier destination, RenderTargetIdentifier? depthMap, bool invert)
457+
{
458+
var bundle = GetBundle<AmbientOcclusion>();
459+
var renderer = bundle.CastRenderer<AmbientOcclusionRenderer>().GetMultiScaleVO();
460+
renderer.SetResources(m_Resources);
461+
renderer.GenerateAOMap(cmd, camera, destination, depthMap, invert);
462+
}
463+
455464
internal void OverrideSettings(List<PostProcessEffectSettings> baseSettings, float interpFactor)
456465
{
457466
// Go through all settings & overriden parameters for the given volume and lerp values

PostProcessing/Shaders/Builtins/MultiScaleVOUpsample.compute

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//
2121

2222
#pragma kernel main MAIN=main
23+
#pragma kernel main_invert MAIN=main_invert INVERT
2324
#pragma kernel main_premin MAIN=main_premin COMBINE_LOWER_RESOLUTIONS
2425
#pragma kernel main_blendout MAIN=main_blendout BLEND_WITH_HIGHER_RESOLUTION
2526
#pragma kernel main_premin_blendout MAIN=main_premin_blendout COMBINE_LOWER_RESOLUTIONS BLEND_WITH_HIGHER_RESOLUTION
@@ -228,8 +229,16 @@ void MAIN(uint3 Gid : SV_GroupID, uint GI : SV_GroupIndex, uint3 GTid : SV_Group
228229
float4 HiDepths = HiResDB.Gather(samplerHiResDB, UV1);
229230

230231
int2 OutST = DTid.xy << 1;
232+
233+
#ifdef INVERT
234+
AoResult[OutST + int2(-1, 0)] = 1.0 - BilateralUpsample(HiDepths.x, HiSSAOs.x, LoDepths.xyzw, LoSSAOs.xyzw);
235+
AoResult[OutST + int2( 0, 0)] = 1.0 - BilateralUpsample(HiDepths.y, HiSSAOs.y, LoDepths.yzwx, LoSSAOs.yzwx);
236+
AoResult[OutST + int2( 0, -1)] = 1.0 - BilateralUpsample(HiDepths.z, HiSSAOs.z, LoDepths.zwxy, LoSSAOs.zwxy);
237+
AoResult[OutST + int2(-1, -1)] = 1.0 - BilateralUpsample(HiDepths.w, HiSSAOs.w, LoDepths.wxyz, LoSSAOs.wxyz);
238+
#else
231239
AoResult[OutST + int2(-1, 0)] = BilateralUpsample(HiDepths.x, HiSSAOs.x, LoDepths.xyzw, LoSSAOs.xyzw);
232240
AoResult[OutST + int2( 0, 0)] = BilateralUpsample(HiDepths.y, HiSSAOs.y, LoDepths.yzwx, LoSSAOs.yzwx);
233241
AoResult[OutST + int2( 0, -1)] = BilateralUpsample(HiDepths.z, HiSSAOs.z, LoDepths.zwxy, LoSSAOs.zwxy);
234242
AoResult[OutST + int2(-1, -1)] = BilateralUpsample(HiDepths.w, HiSSAOs.w, LoDepths.wxyz, LoSSAOs.wxyz);
243+
#endif
235244
}

0 commit comments

Comments
 (0)