@@ -281,6 +281,7 @@ void RebuildCommandBuffers(PostProcessRenderContext context)
281281 context . height
282282 ) ;
283283
284+ m_PropertySheet . ClearKeywords ( ) ;
284285 m_PropertySheet . properties . SetVector ( ShaderIDs . AOColor , Color . white - color ) ;
285286
286287#if ! UNITY_2017_1_OR_NEWER
@@ -526,9 +527,36 @@ public void RenderAfterOpaque(PostProcessRenderContext context)
526527 var cmd = context . command ;
527528 cmd . BeginSample ( "Ambient Occlusion" ) ;
528529 DoLazyInitialization ( context ) ;
530+
531+ var sheet = m_PropertySheet ;
532+
533+ // In forward fog is applied at the object level in the grometry pass so we need to
534+ // apply it to AO as well or it'll drawn on top of the fog effect.
535+ // Not needed in Deferred.
536+ if ( context . camera . actualRenderingPath == RenderingPath . Forward && RenderSettings . fog )
537+ {
538+ sheet . properties . SetVector (
539+ ShaderIDs . FogParams ,
540+ new Vector3 ( RenderSettings . fogDensity , RenderSettings . fogStartDistance , RenderSettings . fogEndDistance )
541+ ) ;
542+
543+ switch ( RenderSettings . fogMode )
544+ {
545+ case FogMode . Linear :
546+ sheet . EnableKeyword ( "FOG_LINEAR" ) ;
547+ break ;
548+ case FogMode . Exponential :
549+ sheet . EnableKeyword ( "FOG_EXP" ) ;
550+ break ;
551+ case FogMode . ExponentialSquared :
552+ sheet . EnableKeyword ( "FOG_EXP2" ) ;
553+ break ;
554+ }
555+ }
556+
529557 RebuildCommandBuffers ( context ) ;
530558 cmd . SetGlobalTexture ( ShaderIDs . MSVOcclusionTexture , m_Result . id ) ;
531- cmd . BlitFullscreenTriangle ( context . source , context . destination , m_PropertySheet , ( int ) Pass . CompositeForward ) ;
559+ cmd . BlitFullscreenTriangle ( context . source , context . destination , sheet , ( int ) Pass . CompositeForward ) ;
532560 cmd . EndSample ( "Ambient Occlusion" ) ;
533561 }
534562
0 commit comments