@@ -42,6 +42,9 @@ enum Pass
42
42
43
43
readonly int [ ] m_Widths = new int [ 7 ] ;
44
44
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 ] ;
45
48
46
49
AmbientOcclusion m_Settings ;
47
50
PropertySheet m_PropertySheet ;
@@ -79,8 +82,8 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format,
79
82
int sizeId = ( int ) size ;
80
83
cmd . GetTemporaryRT ( id , new RenderTextureDescriptor
81
84
{
82
- width = m_Widths [ sizeId ] ,
83
- height = m_Heights [ sizeId ] ,
85
+ width = m_ScaledWidths [ sizeId ] ,
86
+ height = m_ScaledHeights [ sizeId ] ,
84
87
colorFormat = format ,
85
88
depthBufferBits = 0 ,
86
89
volumeDepth = 1 ,
@@ -97,8 +100,8 @@ void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat fo
97
100
int sizeId = ( int ) size ;
98
101
cmd . GetTemporaryRT ( id , new RenderTextureDescriptor
99
102
{
100
- width = m_Widths [ sizeId ] ,
101
- height = m_Heights [ sizeId ] ,
103
+ width = m_ScaledWidths [ sizeId ] ,
104
+ height = m_ScaledHeights [ sizeId ] ,
102
105
colorFormat = format ,
103
106
depthBufferBits = 0 ,
104
107
volumeDepth = 16 ,
@@ -135,26 +138,30 @@ float CalculateTanHalfFovHeight(Camera camera)
135
138
136
139
Vector2 GetSize ( MipLevel mip )
137
140
{
138
- return new Vector2 ( m_Widths [ ( int ) mip ] , m_Heights [ ( int ) mip ] ) ;
141
+ return new Vector2 ( m_ScaledWidths [ ( int ) mip ] , m_ScaledHeights [ ( int ) mip ] ) ;
139
142
}
140
143
141
144
Vector3 GetSizeArray ( MipLevel mip )
142
145
{
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 ) ;
144
147
}
145
148
146
149
public void GenerateAOMap ( CommandBuffer cmd , Camera camera , RenderTargetIdentifier destination , RenderTargetIdentifier ? depthMap , bool invert , bool isMSAA )
147
150
{
148
- // Base size
151
+ // Base size
149
152
m_Widths [ 0 ] = camera . pixelWidth * ( RuntimeUtilities . isSinglePassStereoEnabled ? 2 : 1 ) ;
150
153
m_Heights [ 0 ] = camera . pixelHeight ;
151
-
154
+ m_ScaledWidths [ 0 ] = camera . scaledPixelWidth * ( RuntimeUtilities . isSinglePassStereoEnabled ? 2 : 1 ) ;
155
+ m_ScaledHeights [ 0 ] = camera . scaledPixelHeight ;
156
+
152
157
// L1 -> L6 sizes
153
158
for ( int i = 1 ; i < 7 ; i ++ )
154
159
{
155
160
int div = 1 << i ;
156
161
m_Widths [ i ] = ( m_Widths [ 0 ] + ( div - 1 ) ) / div ;
157
162
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 ;
158
165
}
159
166
160
167
// Allocate temporary textures
@@ -179,7 +186,7 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi
179
186
}
180
187
181
188
void PushAllocCommands ( CommandBuffer cmd , bool isMSAA )
182
- {
189
+ {
183
190
if ( isMSAA )
184
191
{
185
192
Alloc ( cmd , ShaderIDs . LinearDepth , MipLevel . Original , RenderTextureFormat . RGHalf , true ) ;
@@ -266,7 +273,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
266
273
cmd . SetComputeVectorParam ( cs , "ZBufferParams" , CalculateZBufferParams ( camera ) ) ;
267
274
cmd . SetComputeTextureParam ( cs , kernel , "Depth" , depthMapId ) ;
268
275
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 ) ;
270
277
271
278
if ( needDepthMapRelease )
272
279
Release ( cmd , ShaderIDs . DepthCopy ) ;
@@ -281,7 +288,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
281
288
cmd . SetComputeTextureParam ( cs , kernel , "DS8xAtlas" , ShaderIDs . TiledDepth3 ) ;
282
289
cmd . SetComputeTextureParam ( cs , kernel , "DS16xAtlas" , ShaderIDs . TiledDepth4 ) ;
283
290
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 ) ;
285
292
}
286
293
287
294
void PushRenderCommands ( CommandBuffer cmd , int source , int destination , Vector3 sourceSize , float tanHalfFovH , bool isMSAA )
@@ -451,15 +458,17 @@ void PreparePropertySheet(PostProcessRenderContext context)
451
458
452
459
void CheckAOTexture ( PostProcessRenderContext context )
453
460
{
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 )
455
463
{
456
464
RuntimeUtilities . Destroy ( m_AmbientOnlyAO ) ;
457
465
458
466
m_AmbientOnlyAO = new RenderTexture ( context . width , context . height , 0 , RenderTextureFormat . R8 , RenderTextureReadWrite . Linear )
459
467
{
460
468
hideFlags = HideFlags . DontSave ,
461
469
filterMode = FilterMode . Point ,
462
- enableRandomWrite = true
470
+ enableRandomWrite = true ,
471
+ useDynamicScale = context . camera . allowDynamicResolution
463
472
} ;
464
473
m_AmbientOnlyAO . Create ( ) ;
465
474
}
0 commit comments