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

Commit 7e01dcd

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into better-eye-adapt
2 parents ee44b89 + 35d0b5d commit 7e01dcd

14 files changed

+46
-129
lines changed

PostProcessing/Editor/Models/FogModelEditor.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,23 @@
1-
using UnityEngine;
21
using UnityEngine.PostProcessing;
32

43
namespace UnityEditor.PostProcessing
54
{
65
using Settings = FogModel.Settings;
76

8-
[PostProcessingModelEditor(typeof(FogModel))]
7+
[PostProcessingModelEditor(typeof(FogModel), alwaysEnabled: true)]
98
public class FogModelEditor : PostProcessingModelEditor
109
{
11-
SerializedProperty m_Color;
12-
SerializedProperty m_Mode;
13-
SerializedProperty m_Density;
14-
SerializedProperty m_Start;
15-
SerializedProperty m_End;
1610
SerializedProperty m_ExcludeSkybox;
1711

1812
public override void OnEnable()
1913
{
20-
m_Color = FindSetting((Settings x) => x.color);
21-
m_Mode = FindSetting((Settings x) => x.mode);
22-
m_Density = FindSetting((Settings x) => x.density);
23-
m_Start = FindSetting((Settings x) => x.start);
24-
m_End = FindSetting((Settings x) => x.end);
2514
m_ExcludeSkybox = FindSetting((Settings x) => x.excludeSkybox);
2615
}
2716

2817
public override void OnInspectorGUI()
2918
{
30-
EditorGUILayout.PropertyField(m_Color);
31-
EditorGUILayout.PropertyField(m_ExcludeSkybox);
32-
EditorGUILayout.PropertyField(m_Mode);
33-
34-
EditorGUI.indentLevel++;
35-
if (m_Mode.intValue == (int)FogMode.Linear)
36-
{
37-
EditorGUILayout.PropertyField(m_Start);
38-
EditorGUILayout.PropertyField(m_End);
39-
}
40-
else
41-
{
42-
EditorGUILayout.PropertyField(m_Density);
43-
}
19+
EditorGUILayout.HelpBox("This effect adds fog compatibility to the deferred rendering path; actual fog settings should be set in the Lighting panel.", MessageType.Info);
20+
EditorGUILayout.PropertyField(m_ExcludeSkybox, EditorGUIHelper.GetContent("Exclude Skybox (deferred only)"));
4421
EditorGUI.indentLevel--;
4522
}
4623
}

PostProcessing/Editor/Models/VignetteModelEditor.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class VignetteModelEditor : PostProcessingModelEditor
1717
SerializedProperty m_Roundness;
1818
SerializedProperty m_Mask;
1919
SerializedProperty m_Opacity;
20+
SerializedProperty m_Rounded;
2021

2122
public override void OnEnable()
2223
{
@@ -28,21 +29,21 @@ public override void OnEnable()
2829
m_Roundness = FindSetting((Settings x) => x.roundness);
2930
m_Mask = FindSetting((Settings x) => x.mask);
3031
m_Opacity = FindSetting((Settings x) => x.opacity);
32+
m_Rounded = FindSetting((Settings x) => x.rounded);
3133
}
3234

3335
public override void OnInspectorGUI()
3436
{
3537
EditorGUILayout.PropertyField(m_Mode);
3638
EditorGUILayout.PropertyField(m_Color);
3739

38-
if (m_Mode.intValue <= (int)VignetteMode.Round)
40+
if (m_Mode.intValue < (int)VignetteMode.Masked)
3941
{
4042
EditorGUILayout.PropertyField(m_Center);
4143
EditorGUILayout.PropertyField(m_Intensity);
4244
EditorGUILayout.PropertyField(m_Smoothness);
43-
44-
if (m_Mode.intValue == (int)VignetteMode.Classic)
45-
EditorGUILayout.PropertyField(m_Roundness);
45+
EditorGUILayout.PropertyField(m_Roundness);
46+
EditorGUILayout.PropertyField(m_Rounded);
4647
}
4748
else
4849
{

PostProcessing/Resources/Shaders/Bloom.shader

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ Shader "Hidden/Post FX/Bloom"
7979
{
8080
float autoExposure = 1.0;
8181
uv = UnityStereoScreenSpaceUVAdjust(uv, _MainTex_ST);
82-
83-
#if EYE_ADAPTATION
8482
autoExposure = tex2D(_AutoExposure, uv).r;
85-
#endif
86-
8783
return tex2D(tex, uv) * autoExposure;
8884
}
8985

@@ -151,7 +147,6 @@ Shader "Hidden/Post FX/Bloom"
151147
Pass
152148
{
153149
CGPROGRAM
154-
#pragma multi_compile __ EYE_ADAPTATION
155150
#pragma multi_compile __ ANTI_FLICKER
156151
#pragma multi_compile __ UNITY_COLORSPACE_GAMMA
157152
#pragma vertex VertDefault

PostProcessing/Resources/Shaders/TAA.cginc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// -----------------------------------------------------------------------------
1111
// Solver
1212

13-
#define TAA_USE_GATHER4_FOR_DEPTH_SAMPLE (SHADER_TARGET >= 41)
14-
1513
#define TAA_USE_STABLE_BUT_GHOSTY_VARIANT 0
1614

1715
#if !defined(TAA_DILATE_MOTION_VECTOR_SAMPLE)
@@ -39,13 +37,7 @@ struct OutputSolver
3937
sampler2D _HistoryTex;
4038

4139
sampler2D _CameraMotionVectorsTexture;
42-
43-
#if TAA_USE_GATHER4_FOR_DEPTH_SAMPLE
44-
Texture2D _CameraDepthTexture;
45-
SamplerState sampler_CameraDepthTexture;
46-
#else
4740
sampler2D _CameraDepthTexture;
48-
#endif
4941

5042
float4 _HistoryTex_TexelSize;
5143
float4 _CameraDepthTexture_TexelSize;
@@ -74,20 +66,14 @@ VaryingsSolver VertSolver(AttributesDefault input)
7466
float2 GetClosestFragment(float2 uv)
7567
{
7668
const float2 k = _CameraDepthTexture_TexelSize.xy;
77-
78-
#if TAA_USE_GATHER4_FOR_DEPTH_SAMPLE
79-
const float4 neighborhood = _CameraDepthTexture.Gather(sampler_CameraDepthTexture, uv, int2(1, 1));
80-
float3 result = float3(0.0, 0.0, _CameraDepthTexture.Sample(sampler_CameraDepthTexture, uv).r);
81-
#else
8269
const float4 neighborhood = float4(
8370
SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv - k),
8471
SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv + float2(k.x, -k.y)),
8572
SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv + float2(-k.x, k.y)),
8673
SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv + k)
8774
);
88-
float3 result = float3(0.0, 0.0, SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv));
89-
#endif
9075

76+
float3 result = float3(0.0, 0.0, SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv));
9177
result = lerp(result, float3(-1.0, -1.0, neighborhood.x), step(neighborhood.x, result.z));
9278
result = lerp(result, float3( 1.0, -1.0, neighborhood.y), step(neighborhood.y, result.z));
9379
result = lerp(result, float3(-1.0, 1.0, neighborhood.z), step(neighborhood.z, result.z));

PostProcessing/Resources/Shaders/Uber.shader

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ Shader "Hidden/Post FX/Uber Shader"
1919
#pragma target 3.0
2020

2121
#pragma multi_compile __ UNITY_COLORSPACE_GAMMA
22-
#pragma multi_compile __ EYE_ADAPTATION
2322
#pragma multi_compile __ CHROMATIC_ABERRATION
2423
#pragma multi_compile __ DEPTH_OF_FIELD DEPTH_OF_FIELD_COC_VIEW
2524
#pragma multi_compile __ BLOOM BLOOM_LENS_DIRT
2625
#pragma multi_compile __ COLOR_GRADING COLOR_GRADING_LOG_VIEW
2726
#pragma multi_compile __ USER_LUT
2827
#pragma multi_compile __ GRAIN
29-
#pragma multi_compile __ VIGNETTE_CLASSIC VIGNETTE_ROUND VIGNETTE_MASKED
28+
#pragma multi_compile __ VIGNETTE_CLASSIC VIGNETTE_MASKED
3029
#pragma multi_compile __ DITHERING
3130

3231
#include "UnityCG.cginc"
@@ -67,7 +66,7 @@ Shader "Hidden/Post FX/Uber Shader"
6766
// Vignette
6867
half3 _Vignette_Color;
6968
half2 _Vignette_Center; // UV space
70-
half3 _Vignette_Settings; // x: intensity, y: smoothness, z: roundness
69+
half4 _Vignette_Settings; // x: intensity, y: smoothness, z: roundness, w: rounded
7170
sampler2D _Vignette_Mask;
7271
half _Vignette_Opacity; // [0;1]
7372

@@ -101,14 +100,7 @@ Shader "Hidden/Post FX/Uber Shader"
101100
half4 FragUber(VaryingsFlipped i) : SV_Target
102101
{
103102
float2 uv = i.uv;
104-
half autoExposure = 1.0;
105-
106-
// Store the auto exposure value for later
107-
#if EYE_ADAPTATION
108-
{
109-
autoExposure = tex2D(_AutoExposure, uv).r;
110-
}
111-
#endif
103+
half autoExposure = tex2D(_AutoExposure, uv).r;
112104

113105
half3 color = (0.0).xxx;
114106
#if DEPTH_OF_FIELD && CHROMATIC_ABERRATION
@@ -235,20 +227,12 @@ Shader "Hidden/Post FX/Uber Shader"
235227
#if VIGNETTE_CLASSIC
236228
{
237229
half2 d = abs(uv - _Vignette_Center) * _Vignette_Settings.x;
230+
d.x *= lerp(1.0, _ScreenParams.x / _ScreenParams.y, _Vignette_Settings.w);
238231
d = pow(d, _Vignette_Settings.z); // Roundness
239232
half vfactor = pow(saturate(1.0 - dot(d, d)), _Vignette_Settings.y);
240233
color *= lerp(_Vignette_Color, (1.0).xxx, vfactor);
241234
}
242235

243-
// Perfectly round vignette
244-
#elif VIGNETTE_ROUND
245-
{
246-
half2 d = abs(uv - _Vignette_Center) * _Vignette_Settings.x;
247-
d.x *= _ScreenParams.x / _ScreenParams.y;
248-
half vfactor = pow(saturate(1.0 - dot(d, d)), _Vignette_Settings.y);
249-
color *= lerp(_Vignette_Color, (1.0).xxx, vfactor);
250-
}
251-
252236
// Masked vignette
253237
#elif VIGNETTE_MASKED
254238
{

PostProcessing/Runtime/Components/BloomComponent.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ public void Prepare(RenderTexture source, Material uberMaterial, Texture autoExp
3737
var material = context.materialFactory.Get("Hidden/Post FX/Bloom");
3838
material.shaderKeywords = null;
3939

40-
// Apply auto exposure before the prefiltering pass if needed
41-
if (autoExposure != null)
42-
{
43-
material.EnableKeyword("EYE_ADAPTATION");
44-
material.SetTexture(Uniforms._AutoExposure, autoExposure);
45-
}
40+
// Apply auto exposure before the prefiltering pass
41+
material.SetTexture(Uniforms._AutoExposure, autoExposure);
4642

4743
// Do bloom on a half-res buffer, full-res doesn't bring much and kills performances on
4844
// fillrate limited platforms

PostProcessing/Runtime/Components/EyeAdaptationComponent.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ public Texture Prepare(RenderTexture source, Material uberMaterial)
153153
m_CurrentAutoExposure = dst;
154154
}
155155

156-
// Uber setup
157-
uberMaterial.EnableKeyword("EYE_ADAPTATION");
158-
uberMaterial.SetTexture(Uniforms._AutoExposure, m_CurrentAutoExposure);
159-
160156
// Generate debug histogram
161157
if (context.profile.debugViews.IsModeActive(BuiltinDebugViewsModel.Mode.EyeAdaptation))
162158
{

PostProcessing/Runtime/Components/FogComponent.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,18 @@ public override CameraEvent GetCameraEvent()
4141
return CameraEvent.BeforeImageEffectsOpaque;
4242
}
4343

44-
public override void Init(PostProcessingContext pcontext, FogModel pmodel)
45-
{
46-
base.Init(pcontext, pmodel);
47-
48-
var settings = model.settings;
49-
RenderSettings.fog = model.enabled;
50-
RenderSettings.fogColor = settings.color;
51-
RenderSettings.fogMode = settings.mode;
52-
RenderSettings.fogDensity = settings.density;
53-
RenderSettings.fogStartDistance = settings.start;
54-
RenderSettings.fogEndDistance = settings.end;
55-
}
56-
5744
public override void PopulateCommandBuffer(CommandBuffer cb)
5845
{
5946
var settings = model.settings;
6047

6148
var material = context.materialFactory.Get(k_ShaderString);
6249
material.shaderKeywords = null;
63-
material.SetColor(Uniforms._FogColor, settings.color);
64-
material.SetFloat(Uniforms._Density, settings.density);
65-
material.SetFloat(Uniforms._Start, settings.start);
66-
material.SetFloat(Uniforms._End, settings.end);
50+
material.SetColor(Uniforms._FogColor, RenderSettings.fogColor);
51+
material.SetFloat(Uniforms._Density, RenderSettings.fogDensity);
52+
material.SetFloat(Uniforms._Start, RenderSettings.fogStartDistance);
53+
material.SetFloat(Uniforms._End, RenderSettings.fogEndDistance);
6754

68-
switch (settings.mode)
55+
switch (RenderSettings.fogMode)
6956
{
7057
case FogMode.Linear:
7158
material.EnableKeyword("FOG_LINEAR");

PostProcessing/Runtime/Components/VignetteComponent.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ public override void Prepare(Material uberMaterial)
3030
uberMaterial.SetVector(Uniforms._Vignette_Center, settings.center);
3131
uberMaterial.EnableKeyword("VIGNETTE_CLASSIC");
3232
float roundness = (1f - settings.roundness) * 6f + settings.roundness;
33-
uberMaterial.SetVector(Uniforms._Vignette_Settings, new Vector3(settings.intensity * 3f, settings.smoothness * 5f, roundness));
34-
}
35-
else if (settings.mode == VignetteModel.Mode.Round)
36-
{
37-
uberMaterial.SetVector(Uniforms._Vignette_Center, settings.center);
38-
uberMaterial.EnableKeyword("VIGNETTE_ROUND");
39-
uberMaterial.SetVector(Uniforms._Vignette_Settings, new Vector3(settings.intensity * 3f, settings.smoothness * 5f, 1f));
33+
uberMaterial.SetVector(Uniforms._Vignette_Settings, new Vector4(settings.intensity * 3f, settings.smoothness * 5f, roundness, settings.rounded ? 1f : 0f));
4034
}
4135
else if (settings.mode == VignetteModel.Mode.Masked)
4236
{

PostProcessing/Runtime/Models/FogModel.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ public class FogModel : PostProcessingModel
88
[Serializable]
99
public struct Settings
1010
{
11-
[Tooltip("Controls the color of that fog drawn in the scene.")]
12-
public Color color;
13-
14-
[Tooltip("Controls the mathematical function determining the way fog accumulates with distance from the camera. Options are Linear, Exponential and Exponential Squared.")]
15-
public FogMode mode;
16-
17-
[Tooltip("Controls the density of the fog effect in the Scene when using Exponential or Exponential Squared modes.")]
18-
public float density;
19-
20-
[Tooltip("Controls the distance from the camera where the fog will start in the scene.")]
21-
public float start;
22-
23-
[Tooltip("Controls the distance from the camera where the fog will completely obscure objects in the Scene.")]
24-
public float end;
25-
2611
[Tooltip("Should the fog affect the skybox?")]
2712
public bool excludeSkybox;
2813

@@ -32,11 +17,6 @@ public static Settings defaultSettings
3217
{
3318
return new Settings
3419
{
35-
color = new Color32(102, 108, 113, 154),
36-
mode = FogMode.Exponential,
37-
density = 0.001f,
38-
start = 0f,
39-
end = 600f,
4020
excludeSkybox = true
4121
};
4222
}

PostProcessing/Runtime/Models/VignetteModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ public class VignetteModel : PostProcessingModel
88
public enum Mode
99
{
1010
Classic,
11-
Round,
1211
Masked
1312
}
1413

@@ -40,6 +39,9 @@ public struct Settings
4039
[Range(0f, 1f), Tooltip("Mask opacity.")]
4140
public float opacity;
4241

42+
[Tooltip("Should the vignette be perfectly round or be dependent on the current aspect ratio?")]
43+
public bool rounded;
44+
4345
public static Settings defaultSettings
4446
{
4547
get
@@ -53,7 +55,8 @@ public static Settings defaultSettings
5355
smoothness = 0.2f,
5456
roundness = 1f,
5557
mask = null,
56-
opacity = 1f
58+
opacity = 1f,
59+
rounded = false
5760
};
5861
}
5962
}

PostProcessing/Runtime/PostProcessingBehaviour.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,15 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
220220
dst = m_RenderTextureFactory.Get(src);
221221
#endif
222222

223-
Texture autoExposure = null;
223+
Texture autoExposure = GraphicsUtils.whiteTexture;
224224
if (m_EyeAdaptation.active)
225225
{
226226
uberActive = true;
227227
autoExposure = m_EyeAdaptation.Prepare(src, uberMaterial);
228228
}
229229

230+
uberMaterial.SetTexture("_AutoExposure", autoExposure);
231+
230232
if (dofActive)
231233
{
232234
uberActive = true;

PostProcessing/Runtime/PostProcessingProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ public class PostProcessingProfile : ScriptableObject
77
#pragma warning disable 0169 // "field x is never used"
88

99
public BuiltinDebugViewsModel debugViews = new BuiltinDebugViewsModel();
10+
public FogModel fog = new FogModel();
1011
public AntialiasingModel antialiasing = new AntialiasingModel();
1112
public AmbientOcclusionModel ambientOcclusion = new AmbientOcclusionModel();
1213
public ScreenSpaceReflectionModel screenSpaceReflection = new ScreenSpaceReflectionModel();
13-
public FogModel fog = new FogModel();
1414
public DepthOfFieldModel depthOfField = new DepthOfFieldModel();
1515
public MotionBlurModel motionBlur = new MotionBlurModel();
1616
public EyeAdaptationModel eyeAdaptation = new EyeAdaptationModel();

0 commit comments

Comments
 (0)