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

Commit

Permalink
Fixed fog issues with AO
Browse files Browse the repository at this point in the history
  • Loading branch information
Chman committed Aug 30, 2017
1 parent d9de0d9 commit ec0c9ee
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 45 deletions.
14 changes: 1 addition & 13 deletions PostProcessing/Runtime/Effects/Fog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 1 addition & 13 deletions PostProcessing/Runtime/Effects/MultiScaleVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 1 addition & 13 deletions PostProcessing/Runtime/Effects/ScalableAO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion PostProcessing/Shaders/Builtins/MultiScaleVO.shader
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion PostProcessing/Shaders/Builtins/ScalableAO.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions PostProcessing/Shaders/Builtins/ScalableAO.shader
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -69,7 +71,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
ENDHLSL
}

// 5 - Separable blur (vertical pass)
// 4 - Separable blur (vertical pass)
Pass
{
HLSLPROGRAM
Expand All @@ -82,7 +84,7 @@ Shader "Hidden/PostProcessing/ScalableAO"
ENDHLSL
}

// 6 - Final composition
// 5 - Final composition
Pass
{
Blend Zero OneMinusSrcColor, Zero OneMinusSrcAlpha
Expand All @@ -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
Expand Down

0 comments on commit ec0c9ee

Please sign in to comment.