Skip to content

Commit 87329d5

Browse files
committed
(PR #3) (Separate) Adds a hook to allow non SRP code to add additional shader stripping.
1 parent 15b5de3 commit 87329d5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

com.unity.render-pipelines.universal/Editor/ShaderPreprocessor.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum ShaderFeatures
2222
TerrainHoles = (1 << 7)
2323
}
2424

25-
internal class ShaderPreprocessor : IPreprocessShaders
25+
public class ShaderPreprocessor : IPreprocessShaders
2626
{
2727
ShaderKeyword m_MainLightShadows = new ShaderKeyword(ShaderKeywordStrings.MainLightShadows);
2828
ShaderKeyword m_AdditionalLightsVertex = new ShaderKeyword(ShaderKeywordStrings.AdditionalLightsVertex);
@@ -47,6 +47,19 @@ internal class ShaderPreprocessor : IPreprocessShaders
4747
// The first one executed is the one where callbackOrder is returning the smallest number.
4848
public int callbackOrder { get { return 0; } }
4949

50+
/// <summary> A function returning true if the shader should be stripped. </summary>
51+
public static Func<Shader, ShaderCompilerData, ShaderSnippetData, bool> CustomStrippingFunction;
52+
53+
bool StripCustom(Shader shader, ShaderCompilerData compilerData, ShaderSnippetData snippetData)
54+
{
55+
if (CustomStrippingFunction != null)
56+
{
57+
return CustomStrippingFunction(shader, compilerData, snippetData);
58+
}
59+
60+
return false;
61+
}
62+
5063
bool StripUnusedShader(ShaderFeatures features, Shader shader, ShaderCompilerData compilerData)
5164
{
5265
if (!CoreUtils.HasFlag(features, ShaderFeatures.MainLightShadows) &&
@@ -186,6 +199,9 @@ bool StripUnused(ShaderFeatures features, Shader shader, ShaderSnippetData snipp
186199
if (StripDeprecated(compilerData))
187200
return true;
188201

202+
if (StripCustom(shader, compilerData, snippetData))
203+
return true;
204+
189205
return false;
190206
}
191207

0 commit comments

Comments
 (0)