summaryrefslogtreecommitdiff
path: root/UnityEngine.PostProcessing/FogComponent.cs
diff options
context:
space:
mode:
Diffstat (limited to 'UnityEngine.PostProcessing/FogComponent.cs')
-rw-r--r--UnityEngine.PostProcessing/FogComponent.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/UnityEngine.PostProcessing/FogComponent.cs b/UnityEngine.PostProcessing/FogComponent.cs
new file mode 100644
index 0000000..387ec64
--- /dev/null
+++ b/UnityEngine.PostProcessing/FogComponent.cs
@@ -0,0 +1,67 @@
+using UnityEngine.Rendering;
+
+namespace UnityEngine.PostProcessing;
+
+public sealed class FogComponent : PostProcessingComponentCommandBuffer<FogModel>
+{
+ private static class Uniforms
+ {
+ internal static readonly int _FogColor = Shader.PropertyToID("_FogColor");
+
+ internal static readonly int _Density = Shader.PropertyToID("_Density");
+
+ internal static readonly int _Start = Shader.PropertyToID("_Start");
+
+ internal static readonly int _End = Shader.PropertyToID("_End");
+
+ internal static readonly int _TempRT = Shader.PropertyToID("_TempRT");
+ }
+
+ private const string k_ShaderString = "Hidden/Post FX/Fog";
+
+ public override bool active => base.model.enabled && context.isGBufferAvailable && RenderSettings.fog && !context.interrupted;
+
+ public override string GetName()
+ {
+ return "Fog";
+ }
+
+ public override DepthTextureMode GetCameraFlags()
+ {
+ return DepthTextureMode.Depth;
+ }
+
+ public override CameraEvent GetCameraEvent()
+ {
+ return CameraEvent.AfterImageEffectsOpaque;
+ }
+
+ public override void PopulateCommandBuffer(CommandBuffer cb)
+ {
+ FogModel.Settings settings = base.model.settings;
+ Material material = context.materialFactory.Get("Hidden/Post FX/Fog");
+ material.shaderKeywords = null;
+ Color value = ((!GraphicsUtils.isLinearColorSpace) ? RenderSettings.fogColor : RenderSettings.fogColor.linear);
+ material.SetColor(Uniforms._FogColor, value);
+ material.SetFloat(Uniforms._Density, RenderSettings.fogDensity);
+ material.SetFloat(Uniforms._Start, RenderSettings.fogStartDistance);
+ material.SetFloat(Uniforms._End, RenderSettings.fogEndDistance);
+ switch (RenderSettings.fogMode)
+ {
+ case FogMode.Linear:
+ material.EnableKeyword("FOG_LINEAR");
+ break;
+ case FogMode.Exponential:
+ material.EnableKeyword("FOG_EXP");
+ break;
+ case FogMode.ExponentialSquared:
+ material.EnableKeyword("FOG_EXP2");
+ break;
+ }
+ RenderTextureFormat format = ((!context.isHdr) ? RenderTextureFormat.Default : RenderTextureFormat.DefaultHDR);
+ cb.GetTemporaryRT(Uniforms._TempRT, context.width, context.height, 24, FilterMode.Bilinear, format);
+ cb.Blit(BuiltinRenderTextureType.CameraTarget, Uniforms._TempRT);
+ cb.Blit(Uniforms._TempRT, BuiltinRenderTextureType.CameraTarget, material, settings.excludeSkybox ? 1 : 0);
+ cb.ReleaseTemporaryRT(Uniforms._TempRT);
+ }
+}