Created
April 11, 2026 14:34
-
-
Save CharlieHess/04f68a91303b99d8e5fe37ac62a644fb to your computer and use it in GitHub Desktop.
ProPixelizerVariantStripper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using System.Linq; | |
| using UnityEditor; | |
| using UnityEditor.Build; | |
| using UnityEditor.Rendering; | |
| using UnityEngine; | |
| internal sealed class ProPixelizerVariantStripper : IPreprocessShaders | |
| { | |
| private static readonly HashSet<string> StrippedKeywords = new HashSet<string> | |
| { | |
| "_ADDITIONAL_LIGHTS", | |
| "_ADDITIONAL_LIGHTS_VERTEX", | |
| "_ADDITIONAL_LIGHT_SHADOWS", | |
| "_DBUFFER_MRT1", | |
| "_DBUFFER_MRT2", | |
| "_DBUFFER_MRT3", | |
| "_FORWARD_PLUS", | |
| "_GBUFFER_NORMALS_OCT", | |
| "_LIGHT_COOKIES", | |
| "_LIGHT_LAYERS", | |
| "_MIXED_LIGHTING_SUBTRACTIVE", | |
| "_REFLECTION_PROBE_BLENDING", | |
| "_REFLECTION_PROBE_BOX_PROJECTION", | |
| "_RENDER_PASS_ENABLED", | |
| "_SCREEN_SPACE_OCCLUSION", | |
| "_SHADOWS_SOFT", | |
| "_SHADOWS_SOFT_HIGH", | |
| "_SHADOWS_SOFT_LOW", | |
| "_SHADOWS_SOFT_MEDIUM", | |
| "EVALUATE_SH_MIXED", | |
| "EVALUATE_SH_VERTEX" | |
| }; | |
| public int callbackOrder => 0; | |
| public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data) | |
| { | |
| if (!BuildPipeline.isBuildingPlayer) | |
| { | |
| return; | |
| } | |
| if (!shader.name.StartsWith("ProPixelizer/")) | |
| { | |
| return; | |
| } | |
| int initialCount = data.Count; | |
| for (int i = data.Count - 1; i >= 0; i--) | |
| { | |
| if (ShouldStripVariant(data[i])) | |
| { | |
| data.RemoveAt(i); | |
| } | |
| } | |
| int strippedCount = initialCount - data.Count; | |
| if (strippedCount > 0) | |
| { | |
| Debug.Log( | |
| $"ProPixelizerVariantStripper: stripped {strippedCount} variants from {shader.name} ({snippet.passName})."); | |
| } | |
| } | |
| private static bool ShouldStripVariant(ShaderCompilerData compilerData) | |
| { | |
| IEnumerable<string> keywordNames = compilerData.shaderKeywordSet | |
| .GetShaderKeywords() | |
| .Select(keyword => keyword.name); | |
| foreach (string keywordName in keywordNames) | |
| { | |
| if (StrippedKeywords.Contains(keywordName)) | |
| { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment