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

Commit 7d3c97e

Browse files
committed
Revert "Change stripping implementation so that no files of the PostProcessing package are modified"
This reverts commit 2c04d49.
1 parent f4d165f commit 7d3c97e

12 files changed

+59
-252
lines changed
Lines changed: 23 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
using System;
22
using UnityEditor.Build;
33
using UnityEngine;
4-
using UnityEngine.SceneManagement;
54
using UnityEngine.Rendering.PostProcessing;
65

76
namespace UnityEditor.Rendering.PostProcessing
87
{
98
public sealed class PostProcessResourceStripper : ScriptableObject
109
{
11-
private PostProcessStrippingConfig stripping;
12-
private PostProcessStrippingConfig defaultConfig;
13-
10+
[SerializeField] private PostProcessResources resources;
1411
[SerializeField] private PostProcessResources unstrippedResources;
12+
[SerializeField] private PostProcessStrippingConfig stripping;
1513

1614
static PostProcessResourceStripper s_Instance;
1715

@@ -22,25 +20,19 @@ public static PostProcessResourceStripper instance
2220
if (s_Instance == null)
2321
{
2422
s_Instance = CreateInstance<PostProcessResourceStripper>();
25-
s_Instance.defaultConfig = CreateInstance<PostProcessStrippingConfig>();
23+
s_Instance.unstrippedResources.changeHandler = Update;
2624
}
2725

2826
return s_Instance;
2927
}
3028
}
3129

32-
void Awake()
33-
{
34-
SceneManager.sceneLoaded += OnSceneLoaded;
35-
36-
}
37-
3830
void OnDestroy()
3931
{
40-
SceneManager.sceneLoaded -= OnSceneLoaded;
32+
unstrippedResources.changeHandler = null;
4133
}
4234

43-
static private void StripMultiScaleAO(PostProcessResources resources)
35+
private void StripMultiScaleAO()
4436
{
4537
resources.computeShaders.multiScaleAODownsample1 = null;
4638
resources.computeShaders.multiScaleAODownsample2 = null;
@@ -49,13 +41,13 @@ static private void StripMultiScaleAO(PostProcessResources resources)
4941
resources.shaders.multiScaleAO = null;
5042
}
5143

52-
static private void StripScreenSpaceReflections(PostProcessResources resources)
44+
private void StripScreenSpaceReflections()
5345
{
5446
resources.shaders.screenSpaceReflections = null;
5547
resources.computeShaders.gaussianDownsample = null;
5648
}
5749

58-
static private void StripDebugShaders(PostProcessResources resources)
50+
private void StripDebugShaders()
5951
{
6052
resources.shaders.lightMeter = null;
6153
resources.shaders.gammaHistogram = null;
@@ -68,61 +60,15 @@ static private void StripDebugShaders(PostProcessResources resources)
6860
resources.computeShaders.vectorscope = null;
6961
}
7062

71-
private void LazyInitStrippingConfig()
72-
{
73-
if (stripping != null)
74-
return;
75-
76-
var guids = AssetDatabase.FindAssets("t:PostProcessStrippingConfig", null);
77-
if (guids.Length > 0)
78-
{
79-
stripping = (PostProcessStrippingConfig) AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[0]), typeof(PostProcessStrippingConfig));
80-
}
81-
else
82-
{
83-
// Create a new config asset
84-
AssetDatabase.CreateAsset(defaultConfig, "Assets/PostProcessStrippingConfig.asset");
85-
AssetDatabase.SaveAssets();
86-
AssetDatabase.Refresh();
87-
}
88-
89-
if (stripping == null)
90-
stripping = defaultConfig;
91-
}
92-
93-
private void SetConfig(PostProcessStrippingConfig config)
94-
{
95-
if (config == stripping)
96-
return;
97-
98-
if (defaultConfig == null)
99-
return;
100-
101-
if (config == defaultConfig)
102-
return;
103-
104-
if (config == null)
105-
{
106-
stripping = defaultConfig;
107-
return;
108-
}
109-
110-
stripping = config;
111-
}
112-
113-
private void Apply(BuildTarget target, PostProcessResources resources)
63+
private void Apply(BuildTarget target)
11464
{
115-
if (defaultConfig == null)
116-
return;
117-
118-
LazyInitStrippingConfig();
119-
if (stripping == null)
65+
if (resources == null)
12066
return;
12167

12268
if (unstrippedResources == null)
12369
return;
12470

125-
if (resources == null)
71+
if (stripping == null)
12672
return;
12773

12874
resources.computeShaders = unstrippedResources.computeShaders.Clone();
@@ -132,26 +78,26 @@ private void Apply(BuildTarget target, PostProcessResources resources)
13278
if (stripping.stripUnsupportedShaders &&
13379
(target == BuildTarget.Android || target == BuildTarget.iOS || target == BuildTarget.tvOS))
13480
{
135-
StripMultiScaleAO(resources);
81+
StripMultiScaleAO();
13682
}
13783

13884
if (stripping.stripDebugShaders)
13985
{
140-
StripDebugShaders(resources);
86+
StripDebugShaders();
14187
}
14288

14389
if (stripping.stripComputeShaders)
14490
{
14591
resources.computeShaders = new PostProcessResources.ComputeShaders();
14692
resources.shaders.autoExposure = null;
147-
StripScreenSpaceReflections(resources);
148-
StripMultiScaleAO(resources);
149-
StripDebugShaders(resources);
93+
StripScreenSpaceReflections();
94+
StripMultiScaleAO();
95+
StripDebugShaders();
15096
}
15197

15298
if (stripping.stripUnsupportedShaders && !RuntimeUtilities.supportsDeferredShading)
15399
{
154-
StripScreenSpaceReflections(resources);
100+
StripScreenSpaceReflections();
155101
resources.shaders.deferredFog = null;
156102
if (!RuntimeUtilities.supportsDepthNormals)
157103
resources.shaders.scalableAO = null;
@@ -166,35 +112,14 @@ private void Apply(BuildTarget target, PostProcessResources resources)
166112
}
167113
}
168114

169-
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
115+
public static void Update()
170116
{
171-
StripAll();
117+
Update(EditorUserBuildSettings.activeBuildTarget);
172118
}
173119

174-
public static void Strip(PostProcessResources resources)
120+
public static void Update(BuildTarget target)
175121
{
176-
instance.Apply(EditorUserBuildSettings.activeBuildTarget, resources);
177-
}
178-
179-
public static void StripAll(BuildTarget target)
180-
{
181-
var allResources = PostProcessResourcesFactory.AllResources();
182-
if (allResources == null)
183-
return;
184-
185-
foreach (var resources in allResources)
186-
instance.Apply(EditorUserBuildSettings.activeBuildTarget, resources);
187-
}
188-
189-
public static void StripAll()
190-
{
191-
StripAll(EditorUserBuildSettings.activeBuildTarget);
192-
}
193-
194-
public static void StripAll(PostProcessStrippingConfig config)
195-
{
196-
instance.SetConfig(config);
197-
StripAll(EditorUserBuildSettings.activeBuildTarget);
122+
instance.Apply(EditorUserBuildSettings.activeBuildTarget);
198123
}
199124
}
200125

@@ -204,7 +129,7 @@ sealed class UpdateStrippingOnBuildTargetChange : IActiveBuildTargetChanged
204129
public int callbackOrder { get { return 0; } }
205130
public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget)
206131
{
207-
PostProcessResourceStripper.StripAll(newTarget);
132+
PostProcessResourceStripper.Update(newTarget);
208133
}
209134
}
210135

@@ -215,23 +140,15 @@ sealed class UpdateStrippingBeforeBuild : IPreprocessBuild
215140
#if UNITY_2018_1_OR_NEWER
216141
public void OnPreprocessBuild(Build.Reporting.BuildReport report)
217142
{
218-
PostProcessResourceStripper.StripAll(report.summary.platform);
143+
PostProcessResourceStripper.Update(report.summary.platform);
219144
}
220145
#else
221146
public void OnPreprocessBuild(BuildTarget target, string path)
222147
{
223-
PostProcessResourceStripper.StripAll(target);
148+
PostProcessResourceStripper.Update(target);
224149
}
225150
#endif
226151
}
227152
#endif
228153

229-
[InitializeOnLoad]
230-
public class SetupStripping {
231-
static SetupStripping()
232-
{
233-
PostProcessResourcesFactory.Init(PostProcessResourceStripper.Strip);
234-
}
235-
}
236-
237154
}

PostProcessing/Editor/PostProcessResourceStripper.cs.meta

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using UnityEngine;
1+
using UnityEngine;
32
using UnityEditor.Rendering.PostProcessing;
4-
using UnityEngine.Rendering.PostProcessing;
53

64
namespace UnityEditor.Rendering.PostProcessing
75
{
@@ -11,39 +9,14 @@ public sealed class PostProcessStrippingConfig : ScriptableObject
119
public bool stripDebugShaders = false;
1210
public bool stripComputeShaders = false;
1311

14-
[Serializable]
15-
public sealed class Result
16-
{
17-
public PostProcessResources.Shaders shaders;
18-
public PostProcessResources.ComputeShaders computeShaders;
19-
}
20-
21-
public Result result;
22-
23-
private PostProcessResources strippedResources;
24-
2512
public void Awake()
2613
{
27-
PostProcessResourceStripper.StripAll(this);
28-
UpdateResult();
14+
PostProcessResourceStripper.Update();
2915
}
3016

3117
public void OnValidate()
3218
{
33-
PostProcessResourceStripper.StripAll(this);
34-
UpdateResult();
35-
}
36-
37-
private void UpdateResult()
38-
{
39-
if (result == null)
40-
result = new Result();
41-
42-
PostProcessResources resources = PostProcessResourcesFactory.StrippedDefaultResources();
43-
result.shaders = resources.shaders;
44-
result.computeShaders = resources.computeShaders;
45-
DestroyImmediate(resources);
19+
PostProcessResourceStripper.Update();
4620
}
4721
}
48-
4922
}
-605 Bytes
Binary file not shown.
Binary file not shown.

PostProcessing/PostProcessResourcesUnstripped.asset.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
4.11 KB
Binary file not shown.

PostProcessing/PostProcessStrippingConfig.asset.meta

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PostProcessing/Runtime/PostProcessLayer.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ void InitLegacy()
145145

146146
public void Init(PostProcessResources resources)
147147
{
148-
#if UNITY_EDITOR
149-
m_Resources = PostProcessResourcesFactory.Stripped(m_Resources);
150-
#endif
151148
if (resources != null) m_Resources = resources;
152149

153150
RuntimeUtilities.CreateIfNull(ref temporalAntialiasing);

PostProcessing/Runtime/PostProcessResources.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ public sealed class SMAALuts
7777
public Shaders shaders;
7878
public ComputeShaders computeShaders;
7979

80-
public PostProcessResources StrippableClone()
80+
#if UNITY_EDITOR
81+
public delegate void ChangeHandler();
82+
public ChangeHandler changeHandler;
83+
84+
void OnValidate()
8185
{
82-
PostProcessResources clone = CreateInstance<PostProcessResources>();
83-
clone.blueNoise64 = (Texture2D[]) blueNoise64.Clone();
84-
clone.blueNoise256 = (Texture2D[]) blueNoise256.Clone();
85-
clone.smaaLuts = smaaLuts;
86-
clone.shaders = shaders.Clone();
87-
clone.computeShaders = computeShaders.Clone();
88-
return clone;
86+
if (changeHandler != null)
87+
changeHandler();
8988
}
89+
#endif
9090
}
9191

9292
}

0 commit comments

Comments
 (0)