@@ -39,6 +39,8 @@ enum Pass
39
39
readonly float [ ] m_InvThicknessTable = new float [ 12 ] ;
40
40
readonly float [ ] m_SampleWeightTable = new float [ 12 ] ;
41
41
42
+ readonly int [ ] m_Widths = new int [ 7 ] ;
43
+ readonly int [ ] m_Heights = new int [ 7 ] ;
42
44
// Scaled dimensions used with dynamic resolution
43
45
readonly int [ ] m_ScaledWidths = new int [ 7 ] ;
44
46
readonly int [ ] m_ScaledHeights = new int [ 7 ] ;
@@ -74,41 +76,57 @@ public void SetResources(PostProcessResources resources)
74
76
m_Resources = resources ;
75
77
}
76
78
77
- void Alloc ( CommandBuffer cmd , int id , MipLevel size , RenderTextureFormat format , bool uav )
79
+ void Alloc ( CommandBuffer cmd , int id , MipLevel size , RenderTextureFormat format , bool uav , bool dynamicScale )
78
80
{
79
81
int sizeId = ( int ) size ;
80
82
cmd . GetTemporaryRT ( id , new RenderTextureDescriptor
81
83
{
84
+ #if UNITY_2019_4_OR_NEWER
85
+ width = m_Widths [ sizeId ] ,
86
+ height = m_Heights [ sizeId ] ,
87
+ #else
82
88
width = m_ScaledWidths [ sizeId ] ,
83
89
height = m_ScaledHeights [ sizeId ] ,
90
+ #endif
84
91
colorFormat = format ,
85
92
depthBufferBits = 0 ,
86
93
volumeDepth = 1 ,
87
94
autoGenerateMips = false ,
88
95
msaaSamples = 1 ,
89
96
#if UNITY_2019_2_OR_NEWER
90
97
mipCount = 1 ,
98
+ #endif
99
+ #if UNITY_2019_4_OR_NEWER
100
+ useDynamicScale = dynamicScale ,
91
101
#endif
92
102
enableRandomWrite = uav ,
93
103
dimension = TextureDimension . Tex2D ,
94
104
sRGB = false
95
105
} , FilterMode . Point ) ;
96
106
}
97
107
98
- void AllocArray ( CommandBuffer cmd , int id , MipLevel size , RenderTextureFormat format , bool uav )
108
+ void AllocArray ( CommandBuffer cmd , int id , MipLevel size , RenderTextureFormat format , bool uav , bool dynamicScale )
99
109
{
100
110
int sizeId = ( int ) size ;
101
111
cmd . GetTemporaryRT ( id , new RenderTextureDescriptor
102
112
{
113
+ #if UNITY_2019_4_OR_NEWER
114
+ width = m_Widths [ sizeId ] ,
115
+ height = m_Heights [ sizeId ] ,
116
+ #else
103
117
width = m_ScaledWidths [ sizeId ] ,
104
118
height = m_ScaledHeights [ sizeId ] ,
119
+ #endif
105
120
colorFormat = format ,
106
121
depthBufferBits = 0 ,
107
122
volumeDepth = 16 ,
108
123
autoGenerateMips = false ,
109
124
msaaSamples = 1 ,
110
125
#if UNITY_2019_2_OR_NEWER
111
126
mipCount = 1 ,
127
+ #endif
128
+ #if UNITY_2019_4_OR_NEWER
129
+ useDynamicScale = dynamicScale ,
112
130
#endif
113
131
enableRandomWrite = uav ,
114
132
dimension = TextureDimension . Tex2DArray ,
@@ -152,24 +170,26 @@ Vector3 GetSizeArray(MipLevel mip)
152
170
public void GenerateAOMap ( CommandBuffer cmd , Camera camera , RenderTargetIdentifier destination , RenderTargetIdentifier ? depthMap , bool invert , bool isMSAA )
153
171
{
154
172
// Base size
173
+ m_Widths [ 0 ] = m_ScaledWidths [ 0 ] = camera . pixelWidth * ( RuntimeUtilities . isSinglePassStereoEnabled ? 2 : 1 ) ;
174
+ m_Heights [ 0 ] = m_ScaledHeights [ 0 ] = camera . pixelHeight ;
155
175
#if UNITY_2017_3_OR_NEWER
156
176
m_ScaledWidths [ 0 ] = camera . scaledPixelWidth * ( RuntimeUtilities . isSinglePassStereoEnabled ? 2 : 1 ) ;
157
177
m_ScaledHeights [ 0 ] = camera . scaledPixelHeight ;
158
- #else
159
- m_ScaledWidths [ 0 ] = camera . pixelWidth * ( RuntimeUtilities . isSinglePassStereoEnabled ? 2 : 1 ) ;
160
- m_ScaledHeights [ 0 ] = camera . pixelHeight ;
161
178
#endif
162
-
179
+ float widthScalingFactor = ScalableBufferManager . widthScaleFactor ;
180
+ float heightScalingFactor = ScalableBufferManager . heightScaleFactor ;
163
181
// L1 -> L6 sizes
164
182
for ( int i = 1 ; i < 7 ; i ++ )
165
183
{
166
184
int div = 1 << i ;
167
- m_ScaledWidths [ i ] = ( m_ScaledWidths [ 0 ] + ( div - 1 ) ) / div ;
168
- m_ScaledHeights [ i ] = ( m_ScaledHeights [ 0 ] + ( div - 1 ) ) / div ;
185
+ m_Widths [ i ] = ( m_Widths [ 0 ] + ( div - 1 ) ) / div ;
186
+ m_Heights [ i ] = ( m_Heights [ 0 ] + ( div - 1 ) ) / div ;
187
+ m_ScaledWidths [ i ] = Mathf . CeilToInt ( m_Widths [ i ] * widthScalingFactor ) ;
188
+ m_ScaledHeights [ i ] = Mathf . CeilToInt ( m_Heights [ i ] * heightScalingFactor ) ;
169
189
}
170
190
171
191
// Allocate temporary textures
172
- PushAllocCommands ( cmd , isMSAA ) ;
192
+ PushAllocCommands ( cmd , isMSAA , camera ) ;
173
193
174
194
// Render logic
175
195
PushDownsampleCommands ( cmd , camera , depthMap , isMSAA ) ;
@@ -189,53 +209,53 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi
189
209
PushReleaseCommands ( cmd ) ;
190
210
}
191
211
192
- void PushAllocCommands ( CommandBuffer cmd , bool isMSAA )
212
+ void PushAllocCommands ( CommandBuffer cmd , bool isMSAA , Camera camera )
193
213
{
194
214
if ( isMSAA )
195
215
{
196
- Alloc ( cmd , ShaderIDs . LinearDepth , MipLevel . Original , RenderTextureFormat . RGHalf , true ) ;
197
-
198
- Alloc ( cmd , ShaderIDs . LowDepth1 , MipLevel . L1 , RenderTextureFormat . RGFloat , true ) ;
199
- Alloc ( cmd , ShaderIDs . LowDepth2 , MipLevel . L2 , RenderTextureFormat . RGFloat , true ) ;
200
- Alloc ( cmd , ShaderIDs . LowDepth3 , MipLevel . L3 , RenderTextureFormat . RGFloat , true ) ;
201
- Alloc ( cmd , ShaderIDs . LowDepth4 , MipLevel . L4 , RenderTextureFormat . RGFloat , true ) ;
202
-
203
- AllocArray ( cmd , ShaderIDs . TiledDepth1 , MipLevel . L3 , RenderTextureFormat . RGHalf , true ) ;
204
- AllocArray ( cmd , ShaderIDs . TiledDepth2 , MipLevel . L4 , RenderTextureFormat . RGHalf , true ) ;
205
- AllocArray ( cmd , ShaderIDs . TiledDepth3 , MipLevel . L5 , RenderTextureFormat . RGHalf , true ) ;
206
- AllocArray ( cmd , ShaderIDs . TiledDepth4 , MipLevel . L6 , RenderTextureFormat . RGHalf , true ) ;
207
-
208
- Alloc ( cmd , ShaderIDs . Occlusion1 , MipLevel . L1 , RenderTextureFormat . RG16 , true ) ;
209
- Alloc ( cmd , ShaderIDs . Occlusion2 , MipLevel . L2 , RenderTextureFormat . RG16 , true ) ;
210
- Alloc ( cmd , ShaderIDs . Occlusion3 , MipLevel . L3 , RenderTextureFormat . RG16 , true ) ;
211
- Alloc ( cmd , ShaderIDs . Occlusion4 , MipLevel . L4 , RenderTextureFormat . RG16 , true ) ;
212
-
213
- Alloc ( cmd , ShaderIDs . Combined1 , MipLevel . L1 , RenderTextureFormat . RG16 , true ) ;
214
- Alloc ( cmd , ShaderIDs . Combined2 , MipLevel . L2 , RenderTextureFormat . RG16 , true ) ;
215
- Alloc ( cmd , ShaderIDs . Combined3 , MipLevel . L3 , RenderTextureFormat . RG16 , true ) ;
216
+ Alloc ( cmd , ShaderIDs . LinearDepth , MipLevel . Original , RenderTextureFormat . RGHalf , true , camera . allowDynamicResolution ) ;
217
+
218
+ Alloc ( cmd , ShaderIDs . LowDepth1 , MipLevel . L1 , RenderTextureFormat . RGFloat , true , camera . allowDynamicResolution ) ;
219
+ Alloc ( cmd , ShaderIDs . LowDepth2 , MipLevel . L2 , RenderTextureFormat . RGFloat , true , camera . allowDynamicResolution ) ;
220
+ Alloc ( cmd , ShaderIDs . LowDepth3 , MipLevel . L3 , RenderTextureFormat . RGFloat , true , camera . allowDynamicResolution ) ;
221
+ Alloc ( cmd , ShaderIDs . LowDepth4 , MipLevel . L4 , RenderTextureFormat . RGFloat , true , camera . allowDynamicResolution ) ;
222
+
223
+ AllocArray ( cmd , ShaderIDs . TiledDepth1 , MipLevel . L3 , RenderTextureFormat . RGHalf , true , camera . allowDynamicResolution ) ;
224
+ AllocArray ( cmd , ShaderIDs . TiledDepth2 , MipLevel . L4 , RenderTextureFormat . RGHalf , true , camera . allowDynamicResolution ) ;
225
+ AllocArray ( cmd , ShaderIDs . TiledDepth3 , MipLevel . L5 , RenderTextureFormat . RGHalf , true , camera . allowDynamicResolution ) ;
226
+ AllocArray ( cmd , ShaderIDs . TiledDepth4 , MipLevel . L6 , RenderTextureFormat . RGHalf , true , camera . allowDynamicResolution ) ;
227
+
228
+ Alloc ( cmd , ShaderIDs . Occlusion1 , MipLevel . L1 , RenderTextureFormat . RG16 , true , camera . allowDynamicResolution ) ;
229
+ Alloc ( cmd , ShaderIDs . Occlusion2 , MipLevel . L2 , RenderTextureFormat . RG16 , true , camera . allowDynamicResolution ) ;
230
+ Alloc ( cmd , ShaderIDs . Occlusion3 , MipLevel . L3 , RenderTextureFormat . RG16 , true , camera . allowDynamicResolution ) ;
231
+ Alloc ( cmd , ShaderIDs . Occlusion4 , MipLevel . L4 , RenderTextureFormat . RG16 , true , camera . allowDynamicResolution ) ;
232
+
233
+ Alloc ( cmd , ShaderIDs . Combined1 , MipLevel . L1 , RenderTextureFormat . RG16 , true , camera . allowDynamicResolution ) ;
234
+ Alloc ( cmd , ShaderIDs . Combined2 , MipLevel . L2 , RenderTextureFormat . RG16 , true , camera . allowDynamicResolution ) ;
235
+ Alloc ( cmd , ShaderIDs . Combined3 , MipLevel . L3 , RenderTextureFormat . RG16 , true , camera . allowDynamicResolution ) ;
216
236
}
217
237
else
218
238
{
219
- Alloc ( cmd , ShaderIDs . LinearDepth , MipLevel . Original , RenderTextureFormat . RHalf , true ) ;
220
-
221
- Alloc ( cmd , ShaderIDs . LowDepth1 , MipLevel . L1 , RenderTextureFormat . RFloat , true ) ;
222
- Alloc ( cmd , ShaderIDs . LowDepth2 , MipLevel . L2 , RenderTextureFormat . RFloat , true ) ;
223
- Alloc ( cmd , ShaderIDs . LowDepth3 , MipLevel . L3 , RenderTextureFormat . RFloat , true ) ;
224
- Alloc ( cmd , ShaderIDs . LowDepth4 , MipLevel . L4 , RenderTextureFormat . RFloat , true ) ;
225
-
226
- AllocArray ( cmd , ShaderIDs . TiledDepth1 , MipLevel . L3 , RenderTextureFormat . RHalf , true ) ;
227
- AllocArray ( cmd , ShaderIDs . TiledDepth2 , MipLevel . L4 , RenderTextureFormat . RHalf , true ) ;
228
- AllocArray ( cmd , ShaderIDs . TiledDepth3 , MipLevel . L5 , RenderTextureFormat . RHalf , true ) ;
229
- AllocArray ( cmd , ShaderIDs . TiledDepth4 , MipLevel . L6 , RenderTextureFormat . RHalf , true ) ;
230
-
231
- Alloc ( cmd , ShaderIDs . Occlusion1 , MipLevel . L1 , RenderTextureFormat . R8 , true ) ;
232
- Alloc ( cmd , ShaderIDs . Occlusion2 , MipLevel . L2 , RenderTextureFormat . R8 , true ) ;
233
- Alloc ( cmd , ShaderIDs . Occlusion3 , MipLevel . L3 , RenderTextureFormat . R8 , true ) ;
234
- Alloc ( cmd , ShaderIDs . Occlusion4 , MipLevel . L4 , RenderTextureFormat . R8 , true ) ;
235
-
236
- Alloc ( cmd , ShaderIDs . Combined1 , MipLevel . L1 , RenderTextureFormat . R8 , true ) ;
237
- Alloc ( cmd , ShaderIDs . Combined2 , MipLevel . L2 , RenderTextureFormat . R8 , true ) ;
238
- Alloc ( cmd , ShaderIDs . Combined3 , MipLevel . L3 , RenderTextureFormat . R8 , true ) ;
239
+ Alloc ( cmd , ShaderIDs . LinearDepth , MipLevel . Original , RenderTextureFormat . RHalf , true , camera . allowDynamicResolution ) ;
240
+
241
+ Alloc ( cmd , ShaderIDs . LowDepth1 , MipLevel . L1 , RenderTextureFormat . RFloat , true , camera . allowDynamicResolution ) ;
242
+ Alloc ( cmd , ShaderIDs . LowDepth2 , MipLevel . L2 , RenderTextureFormat . RFloat , true , camera . allowDynamicResolution ) ;
243
+ Alloc ( cmd , ShaderIDs . LowDepth3 , MipLevel . L3 , RenderTextureFormat . RFloat , true , camera . allowDynamicResolution ) ;
244
+ Alloc ( cmd , ShaderIDs . LowDepth4 , MipLevel . L4 , RenderTextureFormat . RFloat , true , camera . allowDynamicResolution ) ;
245
+
246
+ AllocArray ( cmd , ShaderIDs . TiledDepth1 , MipLevel . L3 , RenderTextureFormat . RHalf , true , camera . allowDynamicResolution ) ;
247
+ AllocArray ( cmd , ShaderIDs . TiledDepth2 , MipLevel . L4 , RenderTextureFormat . RHalf , true , camera . allowDynamicResolution ) ;
248
+ AllocArray ( cmd , ShaderIDs . TiledDepth3 , MipLevel . L5 , RenderTextureFormat . RHalf , true , camera . allowDynamicResolution ) ;
249
+ AllocArray ( cmd , ShaderIDs . TiledDepth4 , MipLevel . L6 , RenderTextureFormat . RHalf , true , camera . allowDynamicResolution ) ;
250
+
251
+ Alloc ( cmd , ShaderIDs . Occlusion1 , MipLevel . L1 , RenderTextureFormat . R8 , true , camera . allowDynamicResolution ) ;
252
+ Alloc ( cmd , ShaderIDs . Occlusion2 , MipLevel . L2 , RenderTextureFormat . R8 , true , camera . allowDynamicResolution ) ;
253
+ Alloc ( cmd , ShaderIDs . Occlusion3 , MipLevel . L3 , RenderTextureFormat . R8 , true , camera . allowDynamicResolution ) ;
254
+ Alloc ( cmd , ShaderIDs . Occlusion4 , MipLevel . L4 , RenderTextureFormat . R8 , true , camera . allowDynamicResolution ) ;
255
+
256
+ Alloc ( cmd , ShaderIDs . Combined1 , MipLevel . L1 , RenderTextureFormat . R8 , true , camera . allowDynamicResolution ) ;
257
+ Alloc ( cmd , ShaderIDs . Combined2 , MipLevel . L2 , RenderTextureFormat . R8 , true , camera . allowDynamicResolution ) ;
258
+ Alloc ( cmd , ShaderIDs . Combined3 , MipLevel . L3 , RenderTextureFormat . R8 , true , camera . allowDynamicResolution ) ;
239
259
}
240
260
}
241
261
@@ -254,7 +274,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti
254
274
// buffer (it's only available in some specific situations).
255
275
if ( ! RuntimeUtilities . IsResolvedDepthAvailable ( camera ) )
256
276
{
257
- Alloc ( cmd , ShaderIDs . DepthCopy , MipLevel . Original , RenderTextureFormat . RFloat , false ) ;
277
+ Alloc ( cmd , ShaderIDs . DepthCopy , MipLevel . Original , RenderTextureFormat . RFloat , false , camera . allowDynamicResolution ) ;
258
278
depthMapId = new RenderTargetIdentifier ( ShaderIDs . DepthCopy ) ;
259
279
cmd . BlitFullscreenTriangle ( BuiltinRenderTextureType . None , depthMapId , m_PropertySheet , ( int ) Pass . DepthCopy ) ;
260
280
needDepthMapRelease = true ;
0 commit comments