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

Commit ec0c9ee

Browse files
committed
Fixed fog issues with AO
1 parent d9de0d9 commit ec0c9ee

File tree

6 files changed

+12
-45
lines changed

6 files changed

+12
-45
lines changed

PostProcessing/Runtime/Effects/Fog.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,11 @@ internal void Render(PostProcessRenderContext context)
2828
{
2929
var sheet = context.propertySheets.Get(context.resources.shaders.deferredFog);
3030
sheet.ClearKeywords();
31+
3132
var fogColor = RuntimeUtilities.isLinearColorSpace ? RenderSettings.fogColor.linear : RenderSettings.fogColor;
3233
sheet.properties.SetVector(ShaderIDs.FogColor, fogColor);
3334
sheet.properties.SetVector(ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance));
3435

35-
switch (RenderSettings.fogMode)
36-
{
37-
case FogMode.Linear:
38-
sheet.EnableKeyword("FOG_LINEAR");
39-
break;
40-
case FogMode.Exponential:
41-
sheet.EnableKeyword("FOG_EXP");
42-
break;
43-
case FogMode.ExponentialSquared:
44-
sheet.EnableKeyword("FOG_EXP2");
45-
break;
46-
}
47-
4836
var cmd = context.command;
4937
cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, excludeSkybox ? 1 : 0);
5038
}

PostProcessing/Runtime/Effects/MultiScaleVO.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,23 +531,11 @@ public void RenderAfterOpaque(PostProcessRenderContext context)
531531
// Not needed in Deferred.
532532
if (context.camera.actualRenderingPath == RenderingPath.Forward && RenderSettings.fog)
533533
{
534+
sheet.EnableKeyword("APPLY_FORWARD_FOG");
534535
sheet.properties.SetVector(
535536
ShaderIDs.FogParams,
536537
new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance)
537538
);
538-
539-
switch (RenderSettings.fogMode)
540-
{
541-
case FogMode.Linear:
542-
sheet.EnableKeyword("FOG_LINEAR");
543-
break;
544-
case FogMode.Exponential:
545-
sheet.EnableKeyword("FOG_EXP");
546-
break;
547-
case FogMode.ExponentialSquared:
548-
sheet.EnableKeyword("FOG_EXP2");
549-
break;
550-
}
551539
}
552540

553541
RebuildCommandBuffers(context);

PostProcessing/Runtime/Effects/ScalableAO.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,11 @@ void Render(PostProcessRenderContext context, CommandBuffer cmd, int occlusionSo
114114
// Not needed in Deferred.
115115
if (context.camera.actualRenderingPath == RenderingPath.Forward && RenderSettings.fog)
116116
{
117+
sheet.EnableKeyword("APPLY_FORWARD_FOG");
117118
sheet.properties.SetVector(
118119
ShaderIDs.FogParams,
119120
new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance)
120121
);
121-
122-
switch (RenderSettings.fogMode)
123-
{
124-
case FogMode.Linear:
125-
sheet.EnableKeyword("FOG_LINEAR");
126-
break;
127-
case FogMode.Exponential:
128-
sheet.EnableKeyword("FOG_EXP");
129-
break;
130-
case FogMode.ExponentialSquared:
131-
sheet.EnableKeyword("FOG_EXP2");
132-
break;
133-
}
134122
}
135123

136124
// Texture setup

PostProcessing/Shaders/Builtins/MultiScaleVO.shader

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
8080

8181
HLSLPROGRAM
8282

83+
#pragma multi_compile _ APPLY_FORWARD_FOG
8384
#pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2
8485
#pragma vertex Vert
8586
#pragma fragment Frag
@@ -90,7 +91,7 @@ Shader "Hidden/PostProcessing/MultiScaleVO"
9091
half ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, texcoord).r;
9192

9293
// Apply fog when enabled (forward-only)
93-
#if (FOG_LINEAR || FOG_EXP || FOG_EXP2)
94+
#if (APPLY_FORWARD_FOG)
9495
float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, texcoord));
9596
d = ComputeFogDistance(d);
9697
ao *= ComputeFog(d);

PostProcessing/Shaders/Builtins/ScalableAO.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ float4 FragAO(VaryingsDefault i) : SV_Target
247247
ao = PositivePow(ao * INTENSITY / SAMPLE_COUNT, kContrast);
248248

249249
// Apply fog when enabled (forward-only)
250-
#if (FOG_LINEAR || FOG_EXP || FOG_EXP2)
250+
#if (APPLY_FORWARD_FOG)
251251
float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(uv)));
252252
d = ComputeFogDistance(d);
253253
ao *= ComputeFog(d);

PostProcessing/Shaders/Builtins/ScalableAO.shader

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
1818

1919
#pragma vertex VertDefault
2020
#pragma fragment FragAO
21+
#pragma multi_compile _ APPLY_FORWARD_FOG
2122
#pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2
2223
#define SOURCE_DEPTH
2324
#include "ScalableAO.hlsl"
@@ -32,6 +33,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
3233

3334
#pragma vertex VertDefault
3435
#pragma fragment FragAO
36+
#pragma multi_compile _ APPLY_FORWARD_FOG
3537
#pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2
3638
#define SOURCE_GBUFFER
3739
#include "ScalableAO.hlsl"
@@ -54,7 +56,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
5456
ENDHLSL
5557
}
5658

57-
// 4 - Separable blur (horizontal pass) with G-Buffer
59+
// 3 - Separable blur (horizontal pass) with G-Buffer
5860
Pass
5961
{
6062
HLSLPROGRAM
@@ -69,7 +71,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
6971
ENDHLSL
7072
}
7173

72-
// 5 - Separable blur (vertical pass)
74+
// 4 - Separable blur (vertical pass)
7375
Pass
7476
{
7577
HLSLPROGRAM
@@ -82,7 +84,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
8284
ENDHLSL
8385
}
8486

85-
// 6 - Final composition
87+
// 5 - Final composition
8688
Pass
8789
{
8890
Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha
@@ -96,7 +98,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
9698
ENDHLSL
9799
}
98100

99-
// 7 - Final composition (ambient only mode)
101+
// 6 - Final composition (ambient only mode)
100102
Pass
101103
{
102104
Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha

0 commit comments

Comments
 (0)