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

Commit c2601d2

Browse files
committed
Reduced the amount of variants; saved 2 shader keywords; merged vignette "classic" and "round"
1 parent d810da5 commit c2601d2

File tree

9 files changed

+25
-43
lines changed

9 files changed

+25
-43
lines changed

PostProcessing/Editor/Models/VignetteModelEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override void OnInspectorGUI()
3535
EditorGUILayout.PropertyField(m_Mode);
3636
EditorGUILayout.PropertyField(m_Color);
3737

38-
if (m_Mode.intValue <= (int)VignetteMode.Round)
38+
if (m_Mode.intValue < (int)VignetteMode.Masked)
3939
{
4040
EditorGUILayout.PropertyField(m_Center);
4141
EditorGUILayout.PropertyField(m_Intensity);

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: 3 additions & 19 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"
@@ -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
@@ -233,18 +225,10 @@ Shader "Hidden/Post FX/Uber Shader"
233225

234226
// Procedural vignette
235227
#if VIGNETTE_CLASSIC
236-
{
237-
half2 d = abs(uv - _Vignette_Center) * _Vignette_Settings.x;
238-
d = pow(d, _Vignette_Settings.z); // Roundness
239-
half vfactor = pow(saturate(1.0 - dot(d, d)), _Vignette_Settings.y);
240-
color *= lerp(_Vignette_Color, (1.0).xxx, vfactor);
241-
}
242-
243-
// Perfectly round vignette
244-
#elif VIGNETTE_ROUND
245228
{
246229
half2 d = abs(uv - _Vignette_Center) * _Vignette_Settings.x;
247230
d.x *= _ScreenParams.x / _ScreenParams.y;
231+
d = pow(d, _Vignette_Settings.z); // Roundness
248232
half vfactor = pow(saturate(1.0 - dot(d, d)), _Vignette_Settings.y);
249233
color *= lerp(_Vignette_Color, (1.0).xxx, vfactor);
250234
}

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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ public override void Prepare(Material uberMaterial)
3232
float roundness = (1f - settings.roundness) * 6f + settings.roundness;
3333
uberMaterial.SetVector(Uniforms._Vignette_Settings, new Vector3(settings.intensity * 3f, settings.smoothness * 5f, roundness));
3434
}
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));
40-
}
4135
else if (settings.mode == VignetteModel.Mode.Masked)
4236
{
4337
if (settings.mask != null && settings.opacity > 0f)

PostProcessing/Runtime/Models/VignetteModel.cs

Lines changed: 0 additions & 1 deletion
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

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)