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

Commit 35d0b5d

Browse files
authored
Merge pull request #108 from Unity-Technologies/variant-reduction
Reduced the amount of variants
2 parents fe21cac + dbbc916 commit 35d0b5d

File tree

9 files changed

+36
-49
lines changed

9 files changed

+36
-49
lines changed

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/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
@@ -149,10 +149,6 @@ public Texture Prepare(RenderTexture source, Material uberMaterial)
149149
m_CurrentAutoExposure = dst;
150150
}
151151

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

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/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/Utils/GraphicsUtils.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ public static bool supportsDX11
1818
#endif
1919
}
2020

21+
static Texture2D s_WhiteTexture;
22+
public static Texture2D whiteTexture
23+
{
24+
get
25+
{
26+
if (s_WhiteTexture != null)
27+
return s_WhiteTexture;
28+
29+
s_WhiteTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
30+
s_WhiteTexture.SetPixel(0, 0, new Color(1f, 1f, 1f, 1f));
31+
s_WhiteTexture.Apply();
32+
33+
return s_WhiteTexture;
34+
}
35+
}
36+
2137
static Mesh s_Quad;
2238
public static Mesh quad
2339
{

0 commit comments

Comments
 (0)