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

Commit 49af5e0

Browse files
committed
Initial support across most effects.
+ SMAA not tested. + TAA uses dynamically sized buffers but doesn't work correctly. + Any pass that uses texel size in the shader is incorrect (texel size calculation is wrong in native side) + Need to double check MotionBlur
1 parent 4e01e2e commit 49af5e0

File tree

5 files changed

+59
-31
lines changed

5 files changed

+59
-31
lines changed

PostProcessing/Runtime/Effects/MotionBlur.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,33 @@ public override void Render(PostProcessRenderContext context)
9292
sheet.properties.SetFloat(ShaderIDs.RcpMaxBlurRadius, 1f / maxBlurPixels);
9393

9494
int vbuffer = ShaderIDs.VelocityTex;
95-
cmd.GetTemporaryRT(vbuffer, context.width, context.height, 0, FilterMode.Point,
96-
packedRTFormat, RenderTextureReadWrite.Linear);
95+
var rtDesc = context.GetDescriptor(0, packedRTFormat, RenderTextureReadWrite.Linear);
96+
cmd.GetTemporaryRT(vbuffer, rtDesc, FilterMode.Point);
9797
cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, vbuffer, sheet, (int)Pass.VelocitySetup);
9898

9999
// Pass 2 - First TileMax filter (1/2 downsize)
100100
int tile2 = ShaderIDs.Tile2RT;
101-
cmd.GetTemporaryRT(tile2, context.width / 2, context.height / 2, 0, FilterMode.Point,
102-
vectorRTFormat, RenderTextureReadWrite.Linear);
101+
rtDesc = context.GetDescriptor(0, vectorRTFormat, RenderTextureReadWrite.Linear);
102+
rtDesc.width = context.width / 2;
103+
rtDesc.height = context.height / 2;
104+
cmd.GetTemporaryRT(tile2, rtDesc, FilterMode.Point);
103105
cmd.BlitFullscreenTriangle(vbuffer, tile2, sheet, (int)Pass.TileMax1);
104106

105107
// Pass 3 - Second TileMax filter (1/2 downsize)
106108
int tile4 = ShaderIDs.Tile4RT;
107-
cmd.GetTemporaryRT(tile4, context.width / 4, context.height / 4, 0, FilterMode.Point,
108-
vectorRTFormat, RenderTextureReadWrite.Linear);
109+
rtDesc = context.GetDescriptor(0, vectorRTFormat, RenderTextureReadWrite.Linear);
110+
rtDesc.width = context.width / 4;
111+
rtDesc.height = context.height / 4;
112+
cmd.GetTemporaryRT(tile4, rtDesc, FilterMode.Point);
109113
cmd.BlitFullscreenTriangle(tile2, tile4, sheet, (int)Pass.TileMax2);
110114
cmd.ReleaseTemporaryRT(tile2);
111115

112116
// Pass 4 - Third TileMax filter (1/2 downsize)
113117
int tile8 = ShaderIDs.Tile8RT;
114-
cmd.GetTemporaryRT(tile8, context.width / 8, context.height / 8, 0, FilterMode.Point,
115-
vectorRTFormat, RenderTextureReadWrite.Linear);
118+
rtDesc = context.GetDescriptor(0, vectorRTFormat, RenderTextureReadWrite.Linear);
119+
rtDesc.width = context.width / 8;
120+
rtDesc.height = context.height / 8;
121+
cmd.GetTemporaryRT(tile8, rtDesc, FilterMode.Point);
116122
cmd.BlitFullscreenTriangle(tile4, tile8, sheet, (int)Pass.TileMax2);
117123
cmd.ReleaseTemporaryRT(tile4);
118124

@@ -122,17 +128,21 @@ public override void Render(PostProcessRenderContext context)
122128
sheet.properties.SetFloat(ShaderIDs.TileMaxLoop, (int)(tileSize / 8f));
123129

124130
int tile = ShaderIDs.TileVRT;
125-
cmd.GetTemporaryRT(tile, context.width / tileSize, context.height / tileSize, 0,
126-
FilterMode.Point, vectorRTFormat, RenderTextureReadWrite.Linear);
131+
rtDesc = context.GetDescriptor(0, vectorRTFormat, RenderTextureReadWrite.Linear);
132+
rtDesc.width = context.width / tileSize;
133+
rtDesc.height = context.height / tileSize;
134+
cmd.GetTemporaryRT(tile, rtDesc, FilterMode.Point);
127135
cmd.BlitFullscreenTriangle(tile8, tile, sheet, (int)Pass.TileMaxV);
128136
cmd.ReleaseTemporaryRT(tile8);
129137

130138
// Pass 6 - NeighborMax filter
139+
rtDesc = context.GetDescriptor(0, vectorRTFormat, RenderTextureReadWrite.Linear);
131140
int neighborMax = ShaderIDs.NeighborMaxTex;
132141
int neighborMaxWidth = context.width / tileSize;
133142
int neighborMaxHeight = context.height / tileSize;
134-
cmd.GetTemporaryRT(neighborMax, neighborMaxWidth, neighborMaxHeight, 0,
135-
FilterMode.Point, vectorRTFormat, RenderTextureReadWrite.Linear);
143+
rtDesc.width = neighborMaxWidth;
144+
rtDesc.height = neighborMaxHeight;
145+
cmd.GetTemporaryRT(neighborMax, rtDesc, FilterMode.Point);
136146
cmd.BlitFullscreenTriangle(tile, neighborMax, sheet, (int)Pass.NeighborMax);
137147
cmd.ReleaseTemporaryRT(tile);
138148

PostProcessing/Runtime/Effects/MultiScaleVO.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ enum Pass
4242

4343
readonly int[] m_Widths = new int[7];
4444
readonly int[] m_Heights = new int[7];
45+
// Scaled dimensions used with dynamic resolution
46+
readonly int[] m_ScaledWidths = new int[7];
47+
readonly int[] m_ScaledHeights = new int[7];
4548

4649
AmbientOcclusion m_Settings;
4750
PropertySheet m_PropertySheet;
@@ -79,8 +82,8 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format,
7982
int sizeId = (int)size;
8083
cmd.GetTemporaryRT(id, new RenderTextureDescriptor
8184
{
82-
width = m_Widths[sizeId],
83-
height = m_Heights[sizeId],
85+
width = m_ScaledWidths[sizeId],
86+
height = m_ScaledHeights[sizeId],
8487
colorFormat = format,
8588
depthBufferBits = 0,
8689
volumeDepth = 1,
@@ -97,8 +100,8 @@ void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat fo
97100
int sizeId = (int)size;
98101
cmd.GetTemporaryRT(id, new RenderTextureDescriptor
99102
{
100-
width = m_Widths[sizeId],
101-
height = m_Heights[sizeId],
103+
width = m_ScaledWidths[sizeId],
104+
height = m_ScaledHeights[sizeId],
102105
colorFormat = format,
103106
depthBufferBits = 0,
104107
volumeDepth = 16,
@@ -135,26 +138,30 @@ float CalculateTanHalfFovHeight(Camera camera)
135138

136139
Vector2 GetSize(MipLevel mip)
137140
{
138-
return new Vector2(m_Widths[(int)mip], m_Heights[(int)mip]);
141+
return new Vector2(m_ScaledWidths[(int)mip], m_ScaledHeights[(int)mip]);
139142
}
140143

141144
Vector3 GetSizeArray(MipLevel mip)
142145
{
143-
return new Vector3(m_Widths[(int)mip], m_Heights[(int)mip], 16);
146+
return new Vector3(m_ScaledWidths[(int)mip], m_ScaledHeights[(int)mip], 16);
144147
}
145148

146149
public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifier destination, RenderTargetIdentifier? depthMap, bool invert, bool isMSAA)
147150
{
148-
// Base size
151+
// Base size
149152
m_Widths[0] = camera.pixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1);
150153
m_Heights[0] = camera.pixelHeight;
151-
154+
m_ScaledWidths[0] = camera.scaledPixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1);
155+
m_ScaledHeights[0] = camera.scaledPixelHeight;
156+
152157
// L1 -> L6 sizes
153158
for (int i = 1; i < 7; i++)
154159
{
155160
int div = 1 << i;
156161
m_Widths[i] = (m_Widths[0] + (div - 1)) / div;
157162
m_Heights[i] = (m_Heights[0] + (div - 1)) / div;
163+
m_ScaledWidths[i] = (m_ScaledWidths[0] + (div - 1)) / div;
164+
m_ScaledHeights[i] = (m_ScaledHeights[0] + (div - 1)) / div;
158165
}
159166

160167
// Allocate temporary textures
@@ -179,7 +186,7 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi
179186
}
180187

181188
void PushAllocCommands(CommandBuffer cmd, bool isMSAA)
182-
{
189+
{
183190
if(isMSAA)
184191
{
185192
Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RGHalf, true);
@@ -266,7 +273,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
266273
cmd.SetComputeVectorParam(cs, "ZBufferParams", CalculateZBufferParams(camera));
267274
cmd.SetComputeTextureParam(cs, kernel, "Depth", depthMapId);
268275

269-
cmd.DispatchCompute(cs, kernel, m_Widths[(int)MipLevel.L4], m_Heights[(int)MipLevel.L4], 1);
276+
cmd.DispatchCompute(cs, kernel, m_ScaledWidths[(int)MipLevel.L4], m_ScaledHeights[(int)MipLevel.L4], 1);
270277

271278
if (needDepthMapRelease)
272279
Release(cmd, ShaderIDs.DepthCopy);
@@ -281,7 +288,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
281288
cmd.SetComputeTextureParam(cs, kernel, "DS8xAtlas", ShaderIDs.TiledDepth3);
282289
cmd.SetComputeTextureParam(cs, kernel, "DS16xAtlas", ShaderIDs.TiledDepth4);
283290

284-
cmd.DispatchCompute(cs, kernel, m_Widths[(int)MipLevel.L6], m_Heights[(int)MipLevel.L6], 1);
291+
cmd.DispatchCompute(cs, kernel, m_ScaledWidths[(int)MipLevel.L6], m_ScaledHeights[(int)MipLevel.L6], 1);
285292
}
286293

287294
void PushRenderCommands(CommandBuffer cmd, int source, int destination, Vector3 sourceSize, float tanHalfFovH, bool isMSAA)
@@ -451,15 +458,17 @@ void PreparePropertySheet(PostProcessRenderContext context)
451458

452459
void CheckAOTexture(PostProcessRenderContext context)
453460
{
454-
if (m_AmbientOnlyAO == null || !m_AmbientOnlyAO.IsCreated() || m_AmbientOnlyAO.width != context.width || m_AmbientOnlyAO.height != context.height)
461+
if (m_AmbientOnlyAO == null || !m_AmbientOnlyAO.IsCreated() || m_AmbientOnlyAO.width != context.width || m_AmbientOnlyAO.height != context.height ||
462+
m_AmbientOnlyAO.useDynamicScale != context.camera.allowDynamicResolution)
455463
{
456464
RuntimeUtilities.Destroy(m_AmbientOnlyAO);
457465

458466
m_AmbientOnlyAO = new RenderTexture(context.width, context.height, 0, RenderTextureFormat.R8, RenderTextureReadWrite.Linear)
459467
{
460468
hideFlags = HideFlags.DontSave,
461469
filterMode = FilterMode.Point,
462-
enableRandomWrite = true
470+
enableRandomWrite = true,
471+
useDynamicScale = context.camera.allowDynamicResolution
463472
};
464473
m_AmbientOnlyAO.Create();
465474
}

PostProcessing/Runtime/Effects/SubpixelMorphologicalAntialiasing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ internal void Render(PostProcessRenderContext context)
6363
var cmd = context.command;
6464
cmd.BeginSample("SubpixelMorphologicalAntialiasing");
6565

66-
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flip, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear);
67-
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flop, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear);
66+
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flip, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, context.camera.allowDynamicResolution);
67+
cmd.GetTemporaryRT(ShaderIDs.SMAA_Flop, context.width, context.height, 0, FilterMode.Bilinear, context.sourceFormat, RenderTextureReadWrite.Linear, 1, false, RenderTextureMemoryless.None, context.camera.allowDynamicResolution);
6868

6969
cmd.BlitFullscreenTriangle(context.source, ShaderIDs.SMAA_Flip, sheet, (int)Pass.EdgeDetection + (int)quality, true);
7070
cmd.BlitFullscreenTriangle(ShaderIDs.SMAA_Flip, ShaderIDs.SMAA_Flop, sheet, (int)Pass.BlendWeights + (int)quality);

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void InitLegacy()
244244
[ImageEffectUsesCommandBuffer]
245245
void OnRenderImage(RenderTexture src, RenderTexture dst)
246246
{
247-
if (finalBlitToCameraTarget)
247+
if (finalBlitToCameraTarget && (m_Camera.allowDynamicResolution && ScalableBufferManager.heightScaleFactor == 1.0 && ScalableBufferManager.widthScaleFactor == 1.0))
248248
RenderTexture.active = dst; // silence warning
249249
else
250250
Graphics.Blit(src, dst);
@@ -607,7 +607,7 @@ void BuildCommandBuffers()
607607
context.destination = cameraTarget;
608608

609609
#if UNITY_2019_1_OR_NEWER
610-
if (finalBlitToCameraTarget && !RuntimeUtilities.scriptableRenderPipelineActive)
610+
if (finalBlitToCameraTarget && !RuntimeUtilities.scriptableRenderPipelineActive && (!m_Camera.allowDynamicResolution || (ScalableBufferManager.heightScaleFactor == 1.0 && ScalableBufferManager.widthScaleFactor == 1.0)))
611611
{
612612
if (m_Camera.targetTexture)
613613
{

PostProcessing/Runtime/PostProcessRenderContext.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public void PushDebugOverlay(CommandBuffer cmd, RenderTargetIdentifier source, P
322322
// size usages explicit
323323
#if UNITY_2017_2_OR_NEWER
324324
RenderTextureDescriptor m_sourceDescriptor;
325-
RenderTextureDescriptor GetDescriptor(int depthBufferBits = 0, RenderTextureFormat colorFormat = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default)
325+
public RenderTextureDescriptor GetDescriptor(int depthBufferBits = 0, RenderTextureFormat colorFormat = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default)
326326
{
327327
var modifiedDesc = new RenderTextureDescriptor(m_sourceDescriptor.width, m_sourceDescriptor.height,
328328
m_sourceDescriptor.colorFormat, depthBufferBits);
@@ -337,6 +337,11 @@ RenderTextureDescriptor GetDescriptor(int depthBufferBits = 0, RenderTextureForm
337337
modifiedDesc.enableRandomWrite = m_sourceDescriptor.enableRandomWrite;
338338
modifiedDesc.shadowSamplingMode = m_sourceDescriptor.shadowSamplingMode;
339339

340+
#if UNITY_2019_1_OR_NEWER
341+
if (m_Camera.allowDynamicResolution)
342+
modifiedDesc.useDynamicScale = true;
343+
#endif
344+
340345
if (colorFormat != RenderTextureFormat.Default)
341346
modifiedDesc.colorFormat = colorFormat;
342347

@@ -380,8 +385,12 @@ public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID,
380385
//intermediates in VR are unchanged
381386
if (stereoActive && desc.dimension == Rendering.TextureDimension.Tex2DArray)
382387
desc.dimension = Rendering.TextureDimension.Tex2D;
383-
388+
389+
#if UNITY_2019_1_OR_NEWER
384390
cmd.GetTemporaryRT(nameID, desc, filter);
391+
#else
392+
cmd.GetTemporaryRT(nameID, desc.width, desc.height, desc.depthBufferBits, filter, desc.colorFormat, readWrite, desc.msaaSamples, desc.enableRandomWrite, desc.memoryless, m_Camera.allowDynamicResolution);
393+
#endif
385394
#else
386395
int actualWidth = width;
387396
int actualHeight = height;

0 commit comments

Comments
 (0)