Skip to content

Commit d570e10

Browse files
eh-unityEvergreen
authored andcommitted
PostProcess pass consistency improvements.
1 parent 122ef3d commit d570e10

18 files changed

+402
-419
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/BloomPostProcessPass.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ internal sealed class BloomPostProcessPass : PostProcessPass
2020

2121
public BloomMipPyramid mipPyramid => m_MipPyramid;
2222

23+
const string k_PassNameKawase = "Blit Bloom Mipmaps (Kawase)";
24+
const string k_PassNameDual = "Blit Bloom Mipmaps (Dual)";
25+
ProfilingSampler m_ProfilingSamplerKawase;
26+
ProfilingSampler m_ProfilingSamplerDual;
27+
2328
public BloomPostProcessPass(Shader shader)
2429
{
2530
this.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing - 1;
26-
this.profilingSampler = null;
31+
this.profilingSampler = new ProfilingSampler("Blit Bloom Mipmaps");
32+
m_ProfilingSamplerKawase = new ProfilingSampler(k_PassNameKawase);
33+
m_ProfilingSamplerDual = new ProfilingSampler(k_PassNameDual);
2734

2835
m_Material = PostProcessUtils.LoadShader(shader, passName);
2936

@@ -63,14 +70,16 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
6370
if (!m_IsValid)
6471
return;
6572

73+
var bloom = volumeStack.GetComponent<Bloom>();
74+
if (!bloom.IsActive())
75+
return;
76+
6677
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
6778
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
6879

6980
var sourceTexture = resourceData.cameraColor;
7081
var sourceDesc = sourceTexture.GetDescriptor(renderGraph);
7182

72-
var bloom = volumeStack.GetComponent<Bloom>();
73-
7483
// Setup
7584
// Materials are set up beforehand.
7685
// We rely on the fact that they're private and separate for each blit.
@@ -183,7 +192,7 @@ static public int CalcBloomMipCount(Bloom bloom, in Vector2Int bloomResolution)
183192

184193
TextureHandle BloomGaussian(RenderGraph renderGraph, in TextureHandle source)
185194
{
186-
using (var builder = renderGraph.AddUnsafePass<BloomPassData>("Blit Bloom Mipmaps", out var passData, ProfilingSampler.Get(URPProfileId.Bloom)))
195+
using (var builder = renderGraph.AddUnsafePass<BloomPassData>(passName, out var passData, profilingSampler))
187196
{
188197
passData.sourceTexture = source;
189198
passData.material = m_Material;
@@ -267,7 +276,7 @@ TextureHandle BloomGaussian(RenderGraph renderGraph, in TextureHandle source)
267276

268277
TextureHandle BloomKawase(RenderGraph renderGraph, in TextureHandle source)
269278
{
270-
using (var builder = renderGraph.AddUnsafePass<BloomPassData>("Blit Bloom Mipmaps (Kawase)", out var passData, ProfilingSampler.Get(URPProfileId.Bloom)))
279+
using (var builder = renderGraph.AddUnsafePass<BloomPassData>(k_PassNameKawase, out var passData, m_ProfilingSamplerKawase))
271280
{
272281
passData.sourceTexture = source;
273282
passData.material = m_Material;
@@ -321,7 +330,7 @@ TextureHandle BloomKawase(RenderGraph renderGraph, in TextureHandle source)
321330
// Dual Filter, Bandwidth-Efficient Rendering, siggraph2015
322331
TextureHandle BloomDual(RenderGraph renderGraph, in TextureHandle source)
323332
{
324-
using (var builder = renderGraph.AddUnsafePass<BloomPassData>("Blit Bloom Mipmaps (Dual)", out var passData, ProfilingSampler.Get(URPProfileId.Bloom)))
333+
using (var builder = renderGraph.AddUnsafePass<BloomPassData>(k_PassNameDual, out var passData, m_ProfilingSamplerDual))
325334
{
326335
passData.sourceTexture = source;
327336
passData.material = m_Material;
@@ -412,7 +421,7 @@ public TextureHandle GetResultMip(int index)
412421
if (mipCount == 1)
413422
return mipDownTextures[0]; // Prefilter only.
414423

415-
int i = Mathf.Clamp(index, 0, mipCount - 1);
424+
int i = Mathf.Max(Mathf.Min(index, mipCount - 1), 0);
416425
return mipUpTextures[i]; // Upsampled results.
417426
}
418427

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/DepthOfFieldBokehProcessPass.cs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace UnityEngine.Rendering.Universal
66
{
77
internal sealed class DepthOfFieldBokehPostProcessPass : PostProcessPass
88
{
9-
public const string k_TargetName = "_DoFTarget";
9+
public const string k_TargetName = "CameraColorDepthOfFieldBokeh";
1010
const int k_DownSample = 2;
1111

1212
Material m_Material;
@@ -19,12 +19,10 @@ internal sealed class DepthOfFieldBokehPostProcessPass : PostProcessPass
1919
float m_BokehMaxRadius;
2020
float m_BokehRcpAspect;
2121

22-
bool m_UseFastSRGBLinearConversion;
23-
2422
public DepthOfFieldBokehPostProcessPass(Shader shader)
2523
{
2624
this.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing - 1;
27-
this.profilingSampler = null;
25+
this.profilingSampler = new ProfilingSampler("Blit Depth of Field (Bokeh)");
2826

2927
m_Material = PostProcessUtils.LoadShader(shader, passName);
3028
m_IsValid = m_Material != null;
@@ -36,23 +34,10 @@ public override void Dispose()
3634
m_IsValid = false;
3735
}
3836

39-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
40-
public void Setup(bool useFastSRGBLinearConversion)
41-
{
42-
m_UseFastSRGBLinearConversion = useFastSRGBLinearConversion;
43-
}
44-
4537
private class DoFBokehPassData
4638
{
4739
internal Material material;
4840

49-
// Setup
50-
internal Vector4[] bokehKernel;
51-
internal int downSample;
52-
internal float uvMargin;
53-
internal Vector4 cocParams;
54-
internal bool useFastSRGBLinearConversion;
55-
internal bool enableAlphaOutput;
5641
// Inputs
5742
internal TextureHandle sourceTexture;
5843
internal TextureHandle depthTexture;
@@ -63,17 +48,30 @@ private class DoFBokehPassData
6348
internal TextureHandle pongTexture;
6449
// Output texture
6550
internal TextureHandle destinationTexture;
51+
// Setup
52+
internal Vector4[] bokehKernel;
53+
internal Vector4 cocParams;
54+
internal int downSample;
55+
internal float uvMargin;
56+
internal bool useFastSRGBLinearConversion;
57+
internal bool enableAlphaOutput;
6658
};
6759

6860
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
6961
{
7062
if (!m_IsValid)
7163
return;
7264

73-
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
74-
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
75-
7665
var depthOfField = volumeStack.GetComponent<DepthOfField>();
66+
if (!depthOfField.IsActive() || depthOfField.mode.value != DepthOfFieldMode.Bokeh)
67+
return;
68+
69+
var cameraData = frameData.Get<UniversalCameraData>();
70+
if (cameraData.isSceneViewCamera)
71+
return;
72+
73+
var postProcessingData = frameData.Get<UniversalPostProcessingData>();
74+
var resourceData = frameData.Get<UniversalResourceData>();
7775

7876
var sourceTexture = resourceData.cameraColor;
7977
var destinationTexture = PostProcessUtils.CreateCompatibleTexture(renderGraph, sourceTexture, k_TargetName, true, FilterMode.Bilinear);
@@ -90,7 +88,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
9088
var pongTextureDesc = PostProcessUtils.GetCompatibleDescriptor(srcDesc, wh, hh, Experimental.Rendering.GraphicsFormat.R16G16B16A16_SFloat);
9189
var pongTexture = PostProcessUtils.CreateCompatibleTexture(renderGraph, pongTextureDesc, "_PongTexture", true, FilterMode.Bilinear);
9290

93-
using (var builder = renderGraph.AddUnsafePass<DoFBokehPassData>("Depth of Field - Bokeh", out var passData))
91+
using (var builder = renderGraph.AddUnsafePass<DoFBokehPassData>(passName, out var passData, profilingSampler))
9492
{
9593
// Setup
9694
// "A Lens and Aperture Camera Model for Synthetic Image Generation" [Potmesil81]
@@ -120,7 +118,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
120118
passData.downSample = k_DownSample;
121119
passData.uvMargin = uvMargin;
122120
passData.cocParams = new Vector4(P, maxCoC, maxRadius, rcpAspect);
123-
passData.useFastSRGBLinearConversion = m_UseFastSRGBLinearConversion;
121+
passData.useFastSRGBLinearConversion = postProcessingData.useFastSRGBLinearConversion;
124122
passData.enableAlphaOutput = cameraData.isAlphaOutputEnabled;
125123

126124
// Inputs

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/DepthOfFieldGaussianPostProcessPass.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace UnityEngine.Rendering.Universal
77
{
88
internal sealed class DepthOfFieldGaussianPostProcessPass : PostProcessPass
99
{
10-
public const string k_TargetName = "_DoFTarget";
10+
public const string k_TargetName = "CameraColorDepthOfFieldGaussian";
1111
const int k_DownSample = 2;
1212

1313
Material m_Material;
@@ -19,7 +19,7 @@ internal sealed class DepthOfFieldGaussianPostProcessPass : PostProcessPass
1919
public DepthOfFieldGaussianPostProcessPass(Shader shader)
2020
{
2121
this.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing - 1;
22-
this.profilingSampler = null;
22+
this.profilingSampler = new ProfilingSampler("Blit Depth of Field (Gaussian)");
2323

2424
m_Material = PostProcessUtils.LoadShader(shader, passName);
2525
m_MaterialCoc = PostProcessUtils.LoadShader(shader, passName);
@@ -47,16 +47,11 @@ public override void Dispose()
4747

4848
private class DoFGaussianPassData
4949
{
50-
// Setup
51-
internal int downsample;
52-
internal Vector3 cocParams;
53-
internal bool highQualitySamplingValue;
54-
internal bool enableAlphaOutput;
5550
// Inputs
56-
internal TextureHandle sourceTexture;
57-
internal TextureHandle depthTexture;
5851
internal Material material;
5952
internal Material materialCoC;
53+
internal TextureHandle sourceTexture;
54+
internal TextureHandle depthTexture;
6055
// Pass textures
6156
internal TextureHandle halfCoCTexture;
6257
internal TextureHandle fullCoCTexture;
@@ -65,16 +60,26 @@ private class DoFGaussianPassData
6560
internal RenderTargetIdentifier[] multipleRenderTargets = new RenderTargetIdentifier[2];
6661
// Output textures
6762
internal TextureHandle destination;
63+
// Setup
64+
internal Vector3 cocParams;
65+
internal int downsample;
66+
internal bool highQualitySamplingValue;
67+
internal bool enableAlphaOutput;
6868
};
6969
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
7070
{
7171
if (!m_IsValid)
7272
return;
7373

74+
var depthOfField = volumeStack.GetComponent<DepthOfField>();
75+
if (!depthOfField.IsActive() || depthOfField.mode.value != DepthOfFieldMode.Gaussian)
76+
return;
77+
7478
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
75-
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
79+
if (cameraData.isSceneViewCamera)
80+
return;
7681

77-
var depthOfField = volumeStack.GetComponent<DepthOfField>();
82+
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
7883

7984
var sourceTexture = resourceData.cameraColor;
8085
var destinationTexture = PostProcessUtils.CreateCompatibleTexture(renderGraph, sourceTexture, k_TargetName, true, FilterMode.Bilinear);
@@ -95,7 +100,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
95100
var pongTextureDesc = PostProcessUtils.GetCompatibleDescriptor(srcDesc, wh, hh, colorFormat);
96101
var pongTexture = PostProcessUtils.CreateCompatibleTexture(renderGraph, pongTextureDesc, "_PongTexture", true, FilterMode.Bilinear);
97102

98-
using (var builder = renderGraph.AddUnsafePass<DoFGaussianPassData>("Depth of Field - Gaussian", out var passData))
103+
using (var builder = renderGraph.AddUnsafePass<DoFGaussianPassData>(passName, out var passData, profilingSampler))
99104
{
100105
// Setup
101106
float farStart = depthOfField.gaussianStart.value;

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/FinalPostProcessPass.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ public FinalPostProcessPass(Shader shader, Texture2D[] filmGrainTextures)
3333
m_Material = PostProcessUtils.LoadShader(shader, passName);
3434
m_IsValid = m_Material != null;
3535
m_FilmGrainTextures = filmGrainTextures;
36+
37+
// Defaults
38+
m_FilteringOperation = FilteringOperation.Linear; // Common case.
39+
m_HdrOperations = HDROutputUtils.Operation.None; // HDR disabled by default.
40+
m_ApplySrgbEncoding = false; // sRGB conversion is typically automatic based on format.
41+
m_ApplyFxaa = true; // Upscale disabled by default. Apply FXAA in final pass.
42+
m_RenderOverlayUI = false; // HDR disabled by default. HDR only.
3643
}
3744

3845
public override void Dispose()

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/Fsr1UpscalePostProcessPass.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public Fsr1UpscalePostProcessPass(Shader shader)
2020

2121
m_Material = PostProcessUtils.LoadShader(shader, passName);
2222
m_IsValid = m_Material != null;
23+
24+
// Default
25+
PostProcessUtils.MakeCompatible(ref m_UpscaledDesc);
26+
m_UpscaledDesc.width = 1; // Unknown at pipe/pass construction time. Safe default. Avoid division by zero.
27+
m_UpscaledDesc.height = 1;
28+
m_UpscaledDesc.format = Experimental.Rendering.GraphicsFormat.B10G11R11_UFloatPack32; // URP default.
2329
}
2430

2531
public override void Dispose()

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/LensFlareDataDrivenPostProcessPass.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ internal sealed class LensFlareDataDrivenPostProcessPass : PostProcessPass
99
Material m_Material;
1010
bool m_IsValid;
1111

12+
const string k_passNameOcclusion = "Blit Lens Flare Occlusion";
13+
ProfilingSampler m_ProfilingSamplerOcclusion;
14+
1215
public LensFlareDataDrivenPostProcessPass(Shader shader)
1316
{
1417
this.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing - 1;
15-
this.profilingSampler = null;
18+
this.profilingSampler = new ProfilingSampler("Blit Lens Flares (Data Driven)");
19+
m_ProfilingSamplerOcclusion = new ProfilingSampler(k_passNameOcclusion);
1620

1721
m_Material = PostProcessUtils.LoadShader(shader, passName);
1822
m_IsValid = m_Material != null;
@@ -42,6 +46,10 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
4246
if (!m_IsValid)
4347
return;
4448

49+
var postProcessingData = frameData.Get<UniversalPostProcessingData>();
50+
if (LensFlareCommonSRP.Instance.IsEmpty() || !postProcessingData.supportDataDrivenLensFlare)
51+
return;
52+
4553
var cameraData = frameData.Get<UniversalCameraData>();
4654
var resourceData = frameData.Get<UniversalResourceData>();
4755

@@ -63,7 +71,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
6371

6472
void LensFlareDataDrivenComputeOcclusion(RenderGraph renderGraph, UniversalResourceData resourceData, UniversalCameraData cameraData, in TextureDesc dstDesc, PaniniProjection paniniProjection)
6573
{
66-
using (var builder = renderGraph.AddUnsafePass<LensFlarePassData>("Lens Flare Compute Occlusion", out var passData, ProfilingSampler.Get(URPProfileId.LensFlareDataDrivenComputeOcclusion)))
74+
using (var builder = renderGraph.AddUnsafePass<LensFlarePassData>(k_passNameOcclusion, out var passData, m_ProfilingSamplerOcclusion))
6775
{
6876
TextureHandle occlusionHandle = renderGraph.ImportTexture(LensFlareCommonSRP.occlusionRT);
6977
passData.destinationTexture = occlusionHandle;
@@ -158,7 +166,7 @@ void LensFlareDataDrivenComputeOcclusion(RenderGraph renderGraph, UniversalResou
158166

159167
void RenderLensFlareDataDriven(RenderGraph renderGraph, UniversalResourceData resourceData, UniversalCameraData cameraData, in TextureHandle destination, in TextureDesc srcDesc, PaniniProjection paniniProjection)
160168
{
161-
using (var builder = renderGraph.AddUnsafePass<LensFlarePassData>("Lens Flare Data Driven Pass", out var passData, ProfilingSampler.Get(URPProfileId.LensFlareDataDriven)))
169+
using (var builder = renderGraph.AddUnsafePass<LensFlarePassData>(passName, out var passData, profilingSampler))
162170
{
163171
// Use WriteTexture here because DoLensFlareDataDrivenCommon will call SetRenderTarget internally.
164172
// TODO RENDERGRAPH: convert SRP core lens flare to be rendergraph friendly

Packages/com.unity.render-pipelines.universal/Runtime/Passes/PostProcess/LensFlareScreenSpacePostProcessPass.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ internal sealed class LensFlareScreenSpacePostProcessPass : PostProcessPass
1717
public LensFlareScreenSpacePostProcessPass(Shader shader)
1818
{
1919
this.renderPassEvent = RenderPassEvent.AfterRenderingPostProcessing - 1;
20-
this.profilingSampler = null;
20+
this.profilingSampler = new ProfilingSampler("Blit Lens Flares (Screen Space)");
2121

2222
m_Material = PostProcessUtils.LoadShader(shader, passName);
2323
m_IsValid = m_Material != null;
24+
25+
// Default values
26+
m_ColorBufferWidth = 1; // Unknown at pipe/pass construction time. Safe default. Avoid division by zero.
27+
m_ColorBufferHeight = 1;
28+
m_FlareSourceBloomMipIndex = 0; // Safe. Mip pyramid might not exist.
2429
}
2530

2631
public override void Dispose()
@@ -57,6 +62,9 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
5762
if (!m_IsValid)
5863
return;
5964

65+
if (!IsActive(volumeStack, frameData))
66+
return;
67+
6068
var lensFlareScreenSpace = volumeStack.GetComponent<ScreenSpaceLensFlare>();
6169
var bloom = volumeStack.GetComponent<Bloom>();
6270

@@ -87,7 +95,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
8795
// NOTE: Result texture is the result of the flares/streaks only. Not the final output which is "bloom + flares".
8896
var resultTmpTexture = PostProcessUtils.CreateCompatibleTexture(renderGraph, streakTextureDesc, "_LensFlareScreenSpace", true, FilterMode.Bilinear);
8997

90-
using (var builder = renderGraph.AddUnsafePass<LensFlareScreenSpacePassData>("Blit Lens Flare Screen Space", out var passData, ProfilingSampler.Get(URPProfileId.LensFlareScreenSpace)))
98+
using (var builder = renderGraph.AddUnsafePass<LensFlareScreenSpacePassData>(passName, out var passData, profilingSampler))
9199
{
92100
// Use WriteTexture here because DoLensFlareScreenSpaceCommon will call SetRenderTarget internally.
93101
// TODO RENDERGRAPH: convert SRP core lensflare to be rendergraph friendly
@@ -158,5 +166,15 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
158166
});
159167
}
160168
}
169+
170+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
171+
static internal bool IsActive(VolumeStack volumeStack, ContextContainer frameData)
172+
{
173+
var lensFlareScreenSpace = volumeStack.GetComponent<ScreenSpaceLensFlare>();
174+
if (!lensFlareScreenSpace.IsActive())
175+
return false;
176+
177+
return frameData.Get<UniversalPostProcessingData>().supportScreenSpaceLensFlare;
178+
}
161179
}
162180
}

0 commit comments

Comments
 (0)