@@ -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 }
0 commit comments