From ec0c9ee9fc4b2c6852e983814e5ea9694d79503e Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 30 Aug 2017 14:28:34 +0200 Subject: [PATCH] Fixed fog issues with AO --- PostProcessing/Runtime/Effects/Fog.cs | 14 +------------- PostProcessing/Runtime/Effects/MultiScaleVO.cs | 14 +------------- PostProcessing/Runtime/Effects/ScalableAO.cs | 14 +------------- .../Shaders/Builtins/MultiScaleVO.shader | 3 ++- PostProcessing/Shaders/Builtins/ScalableAO.hlsl | 2 +- PostProcessing/Shaders/Builtins/ScalableAO.shader | 10 ++++++---- 6 files changed, 12 insertions(+), 45 deletions(-) diff --git a/PostProcessing/Runtime/Effects/Fog.cs b/PostProcessing/Runtime/Effects/Fog.cs index fea2b55f..5e7c480f 100644 --- a/PostProcessing/Runtime/Effects/Fog.cs +++ b/PostProcessing/Runtime/Effects/Fog.cs @@ -28,23 +28,11 @@ internal void Render(PostProcessRenderContext context) { var sheet = context.propertySheets.Get(context.resources.shaders.deferredFog); sheet.ClearKeywords(); + var fogColor = RuntimeUtilities.isLinearColorSpace ? RenderSettings.fogColor.linear : RenderSettings.fogColor; sheet.properties.SetVector(ShaderIDs.FogColor, fogColor); sheet.properties.SetVector(ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance)); - switch (RenderSettings.fogMode) - { - case FogMode.Linear: - sheet.EnableKeyword("FOG_LINEAR"); - break; - case FogMode.Exponential: - sheet.EnableKeyword("FOG_EXP"); - break; - case FogMode.ExponentialSquared: - sheet.EnableKeyword("FOG_EXP2"); - break; - } - var cmd = context.command; cmd.BlitFullscreenTriangle(context.source, context.destination, sheet, excludeSkybox ? 1 : 0); } diff --git a/PostProcessing/Runtime/Effects/MultiScaleVO.cs b/PostProcessing/Runtime/Effects/MultiScaleVO.cs index 237191e8..a45377c2 100644 --- a/PostProcessing/Runtime/Effects/MultiScaleVO.cs +++ b/PostProcessing/Runtime/Effects/MultiScaleVO.cs @@ -531,23 +531,11 @@ public void RenderAfterOpaque(PostProcessRenderContext context) // Not needed in Deferred. if (context.camera.actualRenderingPath == RenderingPath.Forward && RenderSettings.fog) { + sheet.EnableKeyword("APPLY_FORWARD_FOG"); sheet.properties.SetVector( ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance) ); - - switch (RenderSettings.fogMode) - { - case FogMode.Linear: - sheet.EnableKeyword("FOG_LINEAR"); - break; - case FogMode.Exponential: - sheet.EnableKeyword("FOG_EXP"); - break; - case FogMode.ExponentialSquared: - sheet.EnableKeyword("FOG_EXP2"); - break; - } } RebuildCommandBuffers(context); diff --git a/PostProcessing/Runtime/Effects/ScalableAO.cs b/PostProcessing/Runtime/Effects/ScalableAO.cs index 295eeacd..75d8917a 100644 --- a/PostProcessing/Runtime/Effects/ScalableAO.cs +++ b/PostProcessing/Runtime/Effects/ScalableAO.cs @@ -114,23 +114,11 @@ void Render(PostProcessRenderContext context, CommandBuffer cmd, int occlusionSo // Not needed in Deferred. if (context.camera.actualRenderingPath == RenderingPath.Forward && RenderSettings.fog) { + sheet.EnableKeyword("APPLY_FORWARD_FOG"); sheet.properties.SetVector( ShaderIDs.FogParams, new Vector3(RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance) ); - - switch (RenderSettings.fogMode) - { - case FogMode.Linear: - sheet.EnableKeyword("FOG_LINEAR"); - break; - case FogMode.Exponential: - sheet.EnableKeyword("FOG_EXP"); - break; - case FogMode.ExponentialSquared: - sheet.EnableKeyword("FOG_EXP2"); - break; - } } // Texture setup diff --git a/PostProcessing/Shaders/Builtins/MultiScaleVO.shader b/PostProcessing/Shaders/Builtins/MultiScaleVO.shader index 95a3caa4..953a0490 100644 --- a/PostProcessing/Shaders/Builtins/MultiScaleVO.shader +++ b/PostProcessing/Shaders/Builtins/MultiScaleVO.shader @@ -80,6 +80,7 @@ Shader "Hidden/PostProcessing/MultiScaleVO" HLSLPROGRAM + #pragma multi_compile _ APPLY_FORWARD_FOG #pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2 #pragma vertex Vert #pragma fragment Frag @@ -90,7 +91,7 @@ Shader "Hidden/PostProcessing/MultiScaleVO" half ao = 1.0 - SAMPLE_TEXTURE2D(_MSVOcclusionTexture, sampler_MSVOcclusionTexture, texcoord).r; // Apply fog when enabled (forward-only) - #if (FOG_LINEAR || FOG_EXP || FOG_EXP2) + #if (APPLY_FORWARD_FOG) float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, texcoord)); d = ComputeFogDistance(d); ao *= ComputeFog(d); diff --git a/PostProcessing/Shaders/Builtins/ScalableAO.hlsl b/PostProcessing/Shaders/Builtins/ScalableAO.hlsl index d35b80eb..417a601a 100644 --- a/PostProcessing/Shaders/Builtins/ScalableAO.hlsl +++ b/PostProcessing/Shaders/Builtins/ScalableAO.hlsl @@ -247,7 +247,7 @@ float4 FragAO(VaryingsDefault i) : SV_Target ao = PositivePow(ao * INTENSITY / SAMPLE_COUNT, kContrast); // Apply fog when enabled (forward-only) -#if (FOG_LINEAR || FOG_EXP || FOG_EXP2) +#if (APPLY_FORWARD_FOG) float d = Linear01Depth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(uv))); d = ComputeFogDistance(d); ao *= ComputeFog(d); diff --git a/PostProcessing/Shaders/Builtins/ScalableAO.shader b/PostProcessing/Shaders/Builtins/ScalableAO.shader index 4bb0b583..aa193657 100644 --- a/PostProcessing/Shaders/Builtins/ScalableAO.shader +++ b/PostProcessing/Shaders/Builtins/ScalableAO.shader @@ -18,6 +18,7 @@ Shader "Hidden/PostProcessing/ScalableAO" #pragma vertex VertDefault #pragma fragment FragAO + #pragma multi_compile _ APPLY_FORWARD_FOG #pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2 #define SOURCE_DEPTH #include "ScalableAO.hlsl" @@ -32,6 +33,7 @@ Shader "Hidden/PostProcessing/ScalableAO" #pragma vertex VertDefault #pragma fragment FragAO + #pragma multi_compile _ APPLY_FORWARD_FOG #pragma multi_compile _ FOG_LINEAR FOG_EXP FOG_EXP2 #define SOURCE_GBUFFER #include "ScalableAO.hlsl" @@ -54,7 +56,7 @@ Shader "Hidden/PostProcessing/ScalableAO" ENDHLSL } - // 4 - Separable blur (horizontal pass) with G-Buffer + // 3 - Separable blur (horizontal pass) with G-Buffer Pass { HLSLPROGRAM @@ -69,7 +71,7 @@ Shader "Hidden/PostProcessing/ScalableAO" ENDHLSL } - // 5 - Separable blur (vertical pass) + // 4 - Separable blur (vertical pass) Pass { HLSLPROGRAM @@ -82,7 +84,7 @@ Shader "Hidden/PostProcessing/ScalableAO" ENDHLSL } - // 6 - Final composition + // 5 - Final composition Pass { Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha @@ -96,7 +98,7 @@ Shader "Hidden/PostProcessing/ScalableAO" ENDHLSL } - // 7 - Final composition (ambient only mode) + // 6 - Final composition (ambient only mode) Pass { Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha