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

Commit 0854a60

Browse files
committed
Merge remote-tracking branch 'refs/remotes/Unity-Technologies/master'
2 parents 84de82e + 6a03c91 commit 0854a60

File tree

15 files changed

+91
-88
lines changed

15 files changed

+91
-88
lines changed

PostProcessing/Editor/Models/EyeAdaptationModelEditor.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class EyeAdaptationModelEditor : PostProcessingModelEditor
1212
SerializedProperty m_HighPercent;
1313
SerializedProperty m_MinLuminance;
1414
SerializedProperty m_MaxLuminance;
15-
SerializedProperty m_ExposureCompensation;
15+
SerializedProperty m_KeyValue;
16+
SerializedProperty m_DynamicKeyValue;
1617
SerializedProperty m_AdaptationType;
1718
SerializedProperty m_SpeedUp;
1819
SerializedProperty m_SpeedDown;
@@ -25,7 +26,8 @@ public override void OnEnable()
2526
m_HighPercent = FindSetting((Settings x) => x.highPercent);
2627
m_MinLuminance = FindSetting((Settings x) => x.minLuminance);
2728
m_MaxLuminance = FindSetting((Settings x) => x.maxLuminance);
28-
m_ExposureCompensation = FindSetting((Settings x) => x.exposureCompensation);
29+
m_KeyValue = FindSetting((Settings x) => x.keyValue);
30+
m_DynamicKeyValue = FindSetting((Settings x) => x.dynamicKeyValue);
2931
m_AdaptationType = FindSetting((Settings x) => x.adaptationType);
3032
m_SpeedUp = FindSetting((Settings x) => x.speedUp);
3133
m_SpeedDown = FindSetting((Settings x) => x.speedDown);
@@ -36,27 +38,39 @@ public override void OnEnable()
3638
public override void OnInspectorGUI()
3739
{
3840
if (!GraphicsUtils.supportsDX11)
39-
{
4041
EditorGUILayout.HelpBox("This effect requires support for compute shaders. Enabling it won't do anything on unsupported platforms.", MessageType.Warning);
41-
}
4242

43-
EditorGUILayout.PropertyField(m_LogMin, EditorGUIHelper.GetContent("Histogram Log Min"));
44-
EditorGUILayout.PropertyField(m_LogMax, EditorGUIHelper.GetContent("Histogram Log Max"));
43+
EditorGUILayout.LabelField("Luminosity range", EditorStyles.boldLabel);
44+
EditorGUI.indentLevel++;
45+
EditorGUILayout.PropertyField(m_LogMin, EditorGUIHelper.GetContent("Minimum (EV)"));
46+
EditorGUILayout.PropertyField(m_LogMax, EditorGUIHelper.GetContent("Maximum (EV)"));
47+
EditorGUI.indentLevel--;
4548
EditorGUILayout.Space();
4649

50+
EditorGUILayout.LabelField("Auto exposure", EditorStyles.boldLabel);
51+
EditorGUI.indentLevel++;
4752
float low = m_LowPercent.floatValue;
4853
float high = m_HighPercent.floatValue;
4954

50-
EditorGUILayout.MinMaxSlider(EditorGUIHelper.GetContent("Filter|These values are the lower and upper percentages of the histogram that will be used to find a stable average luminance. Values outside of this range will be discarded and won't contribute to the average luminance."), ref low, ref high, 1f, 99f);
55+
EditorGUILayout.MinMaxSlider(EditorGUIHelper.GetContent("Histogram filtering|These values are the lower and upper percentages of the histogram that will be used to find a stable average luminance. Values outside of this range will be discarded and won't contribute to the average luminance."), ref low, ref high, 1f, 99f);
5156

5257
m_LowPercent.floatValue = low;
5358
m_HighPercent.floatValue = high;
5459

55-
EditorGUILayout.PropertyField(m_MinLuminance);
56-
EditorGUILayout.PropertyField(m_MaxLuminance);
57-
EditorGUILayout.PropertyField(m_ExposureCompensation);
60+
EditorGUILayout.PropertyField(m_MinLuminance, EditorGUIHelper.GetContent("Minimum (EV)"));
61+
EditorGUILayout.PropertyField(m_MaxLuminance, EditorGUIHelper.GetContent("Maximum (EV)"));
62+
EditorGUILayout.PropertyField(m_DynamicKeyValue);
5863

59-
EditorGUILayout.PropertyField(m_AdaptationType);
64+
if (!m_DynamicKeyValue.boolValue)
65+
EditorGUILayout.PropertyField(m_KeyValue);
66+
67+
EditorGUI.indentLevel--;
68+
EditorGUILayout.Space();
69+
70+
EditorGUILayout.LabelField("Adaptation", EditorStyles.boldLabel);
71+
EditorGUI.indentLevel++;
72+
73+
EditorGUILayout.PropertyField(m_AdaptationType, EditorGUIHelper.GetContent("Type"));
6074

6175
if (m_AdaptationType.intValue == (int)EyeAdaptationModel.EyeAdaptationType.Progressive)
6276
{
@@ -65,6 +79,8 @@ public override void OnInspectorGUI()
6579
EditorGUILayout.PropertyField(m_SpeedDown);
6680
EditorGUI.indentLevel--;
6781
}
82+
83+
EditorGUI.indentLevel--;
6884
}
6985
}
7086
}

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/EyeAdaptation.shader

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Shader "Hidden/Post FX/Eye Adaptation"
88
CGINCLUDE
99

1010
#pragma target 4.5
11+
#pragma multi_compile __ AUTO_KEY_VALUE
1112
#include "UnityCG.cginc"
1213
#include "Common.cginc"
1314
#include "EyeAdaptation.cginc"
@@ -86,8 +87,12 @@ Shader "Hidden/Post FX/Eye Adaptation"
8687
{
8788
avgLuminance = max(EPSILON, avgLuminance);
8889

89-
//half keyValue = 1.03 - (2.0 / (2.0 + log2(avgLuminance + 1.0)));
90+
#if AUTO_KEY_VALUE
91+
half keyValue = 1.03 - (2.0 / (2.0 + log2(avgLuminance + 1.0)));
92+
#else
9093
half keyValue = _ExposureCompensation;
94+
#endif
95+
9196
half exposure = keyValue / avgLuminance;
9297

9398
return exposure;

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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public Texture Prepare(RenderTexture source, Material uberMaterial)
8484
m_EyeCompute = Resources.Load<ComputeShader>("Shaders/EyeHistogram");
8585

8686
var material = context.materialFactory.Get("Hidden/Post FX/Eye Adaptation");
87+
material.shaderKeywords = null;
8788

8889
if (m_HistogramBuffer == null)
8990
m_HistogramBuffer = new ComputeBuffer(k_HistogramBins, sizeof(uint));
@@ -124,10 +125,13 @@ public Texture Prepare(RenderTexture source, Material uberMaterial)
124125

125126
// Compute auto exposure
126127
material.SetBuffer("_Histogram", m_HistogramBuffer); // No (int, buffer) overload for SetBuffer ?
127-
material.SetVector(Uniforms._Params, new Vector4(settings.lowPercent * 0.01f, settings.highPercent * 0.01f, settings.minLuminance, settings.maxLuminance));
128+
material.SetVector(Uniforms._Params, new Vector4(settings.lowPercent * 0.01f, settings.highPercent * 0.01f, Mathf.Exp(settings.minLuminance * 0.69314718055994530941723212145818f), Mathf.Exp(settings.maxLuminance * 0.69314718055994530941723212145818f)));
128129
material.SetVector(Uniforms._Speed, new Vector2(settings.speedDown, settings.speedUp));
129130
material.SetVector(Uniforms._ScaleOffsetRes, scaleOffsetRes);
130-
material.SetFloat(Uniforms._ExposureCompensation, settings.exposureCompensation);
131+
material.SetFloat(Uniforms._ExposureCompensation, settings.keyValue);
132+
133+
if (settings.dynamicKeyValue)
134+
material.EnableKeyword("AUTO_KEY_VALUE");
131135

132136
if (m_FirstFrame || !Application.isPlaying)
133137
{
@@ -149,10 +153,6 @@ public Texture Prepare(RenderTexture source, Material uberMaterial)
149153
m_CurrentAutoExposure = dst;
150154
}
151155

152-
// Uber setup
153-
uberMaterial.EnableKeyword("EYE_ADAPTATION");
154-
uberMaterial.SetTexture(Uniforms._AutoExposure, m_CurrentAutoExposure);
155-
156156
// Generate debug histogram
157157
if (context.profile.debugViews.IsModeActive(BuiltinDebugViewsModel.Mode.EyeAdaptation))
158158
{

PostProcessing/Runtime/Components/FogComponent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public override bool active
2222
{
2323
return model.enabled
2424
&& context.isGBufferAvailable // In forward fog is already done at shader level
25+
&& RenderSettings.fog
2526
&& !context.interrupted;
2627
}
2728
}

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
{

0 commit comments

Comments
 (0)