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

Commit 12198a2

Browse files
committed
Added an "exclude skybox" option to fog
1 parent b153d2d commit 12198a2

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

PostProcessing/Editor/Models/FogModelEditor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class FogModelEditor : PostProcessingModelEditor
1313
SerializedProperty m_Density;
1414
SerializedProperty m_Start;
1515
SerializedProperty m_End;
16+
SerializedProperty m_ExcludeSkybox;
1617

1718
public override void OnEnable()
1819
{
@@ -21,11 +22,13 @@ public override void OnEnable()
2122
m_Density = FindSetting((Settings x) => x.density);
2223
m_Start = FindSetting((Settings x) => x.start);
2324
m_End = FindSetting((Settings x) => x.end);
25+
m_ExcludeSkybox = FindSetting((Settings x) => x.excludeSkybox);
2426
}
2527

2628
public override void OnInspectorGUI()
2729
{
2830
EditorGUILayout.PropertyField(m_Color);
31+
EditorGUILayout.PropertyField(m_ExcludeSkybox);
2932
EditorGUILayout.PropertyField(m_Mode);
3033

3134
EditorGUI.indentLevel++;

PostProcessing/Resources/Shaders/Fog.shader

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ Shader "Hidden/Post FX/Fog"
5959
{
6060
half4 color = tex2D(_MainTex, i.uv);
6161

62+
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv);
63+
depth = Linear01Depth(depth);
64+
float dist = ComputeDistance(depth) - _Start;
65+
half fog = 1.0 - ComputeFog(dist);
66+
67+
return lerp(color, _FogColor, fog);
68+
}
69+
70+
half4 FragFogExcludeSkybox(Varyings i) : SV_Target
71+
{
72+
half4 color = tex2D(_MainTex, i.uv);
73+
6274
float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv);
6375
depth = Linear01Depth(depth);
6476
float skybox = depth < SKYBOX_THREASHOLD_VALUE;
@@ -83,5 +95,15 @@ Shader "Hidden/Post FX/Fog"
8395

8496
ENDCG
8597
}
98+
99+
Pass
100+
{
101+
CGPROGRAM
102+
103+
#pragma vertex VertFog
104+
#pragma fragment FragFogExcludeSkybox
105+
106+
ENDCG
107+
}
86108
}
87109
}

PostProcessing/Runtime/Components/FogComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public override void PopulateCommandBuffer(CommandBuffer cb)
8484

8585
cb.GetTemporaryRT(Uniforms._TempRT, context.width, context.height, 24, FilterMode.Bilinear, fbFormat);
8686
cb.Blit(BuiltinRenderTextureType.CameraTarget, Uniforms._TempRT);
87-
cb.Blit(Uniforms._TempRT, BuiltinRenderTextureType.CameraTarget, material);
87+
cb.Blit(Uniforms._TempRT, BuiltinRenderTextureType.CameraTarget, material, settings.excludeSkybox ? 1 : 0);
8888
cb.ReleaseTemporaryRT(Uniforms._TempRT);
8989
}
9090
}

PostProcessing/Runtime/Models/FogModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public struct Settings
2323
[Tooltip("Controls the distance from the camera where the fog will completely obscure objects in the Scene.")]
2424
public float end;
2525

26+
[Tooltip("Should the fog affect the skybox?")]
27+
public bool excludeSkybox;
28+
2629
public static Settings defaultSettings
2730
{
2831
get
@@ -33,7 +36,8 @@ public static Settings defaultSettings
3336
mode = FogMode.Exponential,
3437
density = 0.001f,
3538
start = 0f,
36-
end = 600f
39+
end = 600f,
40+
excludeSkybox = true
3741
};
3842
}
3943
}

0 commit comments

Comments
 (0)