11using System ;
22using System . Collections . Generic ;
3+ using System . Data . Common ;
34using System . IO ;
45using System . Linq ;
56using System . Runtime . InteropServices ;
@@ -144,6 +145,8 @@ public override void OnInspectorGUI()
144145 "Search folders recursively" ) ;
145146 EditorGUI . EndDisabledGroup ( ) ;
146147
148+ ToggleUI ( ref script . DetailedLogging ,
149+ "Enable Detailed Logging" ) ;
147150 ToggleUI ( ref script . VerboseLogging ,
148151 "Enable Verbose Logging" ) ;
149152
@@ -246,7 +249,10 @@ public override void OnInspectorGUI()
246249
247250 ToggleUI ( ref script . StripInstancing ,
248251 "Strip Instancing variants" ,
249- "Should be safe to strip if you know that no material will use geometry instancing." ) ;
252+ "Should be safe to strip if you know that no material will ever use geometry instancing." ) ;
253+ ToggleUI ( ref script . StripNonInstancing ,
254+ "Strip Non-Instancing variants" ,
255+ "Should be safe to strip if you know that materials will always use geometry instancing." ) ;
250256
251257 GUILayout . Space ( 8 ) ;
252258
@@ -263,6 +269,25 @@ public override void OnInspectorGUI()
263269 ToggleUI ( ref script . StripLightmapSubtractive ,
264270 "Strip Baked Subtractive Lightmap variants" ) ;
265271
272+ GUILayout . Space ( 8 ) ;
273+
274+ ToggleUI ( ref script . StripLightForDeferred ,
275+ "Strip Deferred vs Shadow Light Probe" ) ;
276+
277+ EditorGUI . BeginDisabledGroup (
278+ script . StripLightForDeferred ) ;
279+ ToggleUI ( ref script . StripLightprobeOn ,
280+ "Strip Light Probe On variants" ) ;
281+ ToggleUI ( ref script . StripLightprobeOff ,
282+ "Strip Light Probe Off variants" ) ;
283+ EditorGUI . EndDisabledGroup ( ) ;
284+
285+ GUILayout . Space ( 8 ) ;
286+
287+ ToggleUI ( ref script . StripUnityHdrOn ,
288+ "Strip Unity HDR On variants" ) ;
289+ ToggleUI ( ref script . StripUnityHdrOff ,
290+ "Strip Unity HDR Off variants" ) ;
266291 }
267292
268293 GUILayout . Space ( 12 ) ;
@@ -326,7 +351,7 @@ public override void OnInspectorGUI()
326351 foreach ( var obj in script . Objects )
327352 CollectAssets ( obj , ref assets ,
328353 script . SearchFoldersRecursively ) ;
329- if ( script . VerboseLogging )
354+ if ( script . DetailedLogging )
330355 foreach ( var asset in assets )
331356 Debug . LogFormat (
332357 " found {0}\n of type {1}\n " ,
@@ -462,7 +487,8 @@ private void ExportAssetBundle(UnityEngine.Object[] exports,
462487 var oldFogKeepLinear = gfxCfg . FindProperty ( "m_FogKeepLinear" ) . boolValue ;
463488 var oldFogKeepExp = gfxCfg . FindProperty ( "m_FogKeepExp" ) . boolValue ;
464489 var oldFogKeepExp2 = gfxCfg . FindProperty ( "m_FogKeepExp2" ) . boolValue ;
465- var oldFogStripInstancing = gfxCfg . FindProperty ( "m_InstancingStripping" ) . intValue ;
490+ var oldStripInstancing = gfxCfg . FindProperty ( "m_InstancingStripping" ) . intValue ;
491+ // var oldStripNonInstancing = gfxCfg.FindProperty("m_NonInstancingStripping").intValue;
466492 var oldLightmapStripping = gfxCfg . FindProperty ( "m_LightmapStripping" ) . boolValue ;
467493 var oldLightmapKeepPlain = gfxCfg . FindProperty ( "m_LightmapKeepPlain" ) . boolValue ;
468494 var oldLightmapKeepDirCombined = gfxCfg . FindProperty ( "m_LightmapKeepDirCombined" ) . boolValue ;
@@ -472,11 +498,12 @@ private void ExportAssetBundle(UnityEngine.Object[] exports,
472498 var oldLightmapKeepSubtractive = gfxCfg . FindProperty ( "m_LightmapKeepSubtractive" ) . boolValue ;
473499 // Always enable shader variant stripping for best results
474500 // Otherwise we are depending on the actual project setting
475- GraphicsSettings . logWhenShaderIsCompiled = script . VerboseLogging ;
501+ GraphicsSettings . logWhenShaderIsCompiled = script . DetailedLogging ;
476502 gfxCfg . FindProperty ( "m_FogStripping" ) . boolValue = true ;
477503 gfxCfg . FindProperty ( "m_LightmapStripping" ) . boolValue = true ;
478504 // Either fully strip instancing or keep it (not sure if "unused" makes much sense)
479505 gfxCfg . FindProperty ( "m_InstancingStripping" ) . intValue = script . StripInstancing ? 1 : 2 ;
506+ // gfxCfg.FindProperty("m_NonInstancingStripping").intValue = script.StripNonInstancing ? 1 : 2;
480507 gfxCfg . FindProperty ( "m_FogKeepLinear" ) . boolValue = ! script . StripFogLinear ;
481508 gfxCfg . FindProperty ( "m_FogKeepExp" ) . boolValue = ! script . StripFogExp ;
482509 gfxCfg . FindProperty ( "m_FogKeepExp2" ) . boolValue = ! script . StripFogExp2 ;
@@ -494,7 +521,7 @@ private void ExportAssetBundle(UnityEngine.Object[] exports,
494521 try
495522 {
496523 // Give verbose log message to report use APIs
497- if ( script . VerboseLogging ) Debug . LogFormat (
524+ if ( script . DetailedLogging ) Debug . LogFormat (
498525 "Create {0} with graphics API: {1}" , Path . GetFileName ( path ) ,
499526 string . Join ( ", " , Array . ConvertAll ( apis , x => x . ToString ( ) ) ) ) ;
500527 // Call the actual exporting functionality
@@ -516,8 +543,9 @@ private void ExportAssetBundle(UnityEngine.Object[] exports,
516543 gfxCfg . FindProperty ( "m_FogKeepLinear" ) . boolValue = oldFogKeepLinear ;
517544 gfxCfg . FindProperty ( "m_FogKeepExp" ) . boolValue = oldFogKeepExp ;
518545 gfxCfg . FindProperty ( "m_FogKeepExp2" ) . boolValue = oldFogKeepExp2 ;
519- gfxCfg . FindProperty ( "m_InstancingStripping" ) . intValue = oldFogStripInstancing ;
520546 gfxCfg . FindProperty ( "m_LightmapStripping" ) . boolValue = oldLightmapStripping ;
547+ gfxCfg . FindProperty ( "m_InstancingStripping" ) . intValue = oldStripInstancing ;
548+ // gfxCfg.FindProperty("m_NonInstancingStripping").intValue = oldStripNonInstancing;
521549 gfxCfg . FindProperty ( "m_LightmapKeepPlain" ) . boolValue = oldLightmapKeepPlain ;
522550 gfxCfg . FindProperty ( "m_LightmapKeepDirCombined" ) . boolValue = oldLightmapKeepDirCombined ;
523551 gfxCfg . FindProperty ( "m_LightmapKeepDynamicPlain" ) . boolValue = oldLightmapKeepDynamicPlain ;
@@ -644,6 +672,9 @@ class StripShaderVariants : IPreprocessShaders
644672 static ShaderKeyword FOG_EXP = new ShaderKeyword ( "FOG_EXP" ) ;
645673 static ShaderKeyword FOG_EXP2 = new ShaderKeyword ( "FOG_EXP2" ) ;
646674 static ShaderKeyword FOG_LINEAR = new ShaderKeyword ( "FOG_LINEAR" ) ;
675+ static ShaderKeyword INSTANCING = new ShaderKeyword ( "INSTANCING_ON" ) ;
676+ static ShaderKeyword UNITY_HDR_ON = new ShaderKeyword ( "UNITY_HDR_ON" ) ;
677+ static ShaderKeyword LIGHTPROBE_SH = new ShaderKeyword ( "LIGHTPROBE_SH" ) ;
647678
648679 // Do the processing of shaders to potentially alter the shader variants to be compiled
649680 public void OnProcessShader ( Shader shader , ShaderSnippetData snippet , IList < ShaderCompilerData > data )
@@ -656,30 +687,58 @@ public void OnProcessShader(Shader shader, ShaderSnippetData snippet, IList<Shad
656687 StripShaderVariantCounter . ShadersBefore = data . Count ;
657688 // Strip certain pass variants in case render path is known to be unused
658689 if ( Cfg . StripMetaPass && snippet . passType == PassType . Meta ) data . Clear ( ) ;
659- else if ( Cfg . StripDeferredPass && snippet . passType == PassType . Deferred ) data . Clear ( ) ;
660- else if ( Cfg . StripForwardBasePass && snippet . passType == PassType . ForwardBase ) data . Clear ( ) ;
661- else if ( Cfg . StripForwardAddPass && snippet . passType == PassType . ForwardAdd ) data . Clear ( ) ;
662- else if ( Cfg . StripShadowCasterPass && snippet . passType == PassType . ShadowCaster ) data . Clear ( ) ;
690+ if ( Cfg . StripDeferredPass && snippet . passType == PassType . Deferred ) data . Clear ( ) ;
691+ if ( Cfg . StripForwardBasePass && snippet . passType == PassType . ForwardBase ) data . Clear ( ) ;
692+ if ( Cfg . StripForwardAddPass && snippet . passType == PassType . ForwardAdd ) data . Clear ( ) ;
693+ if ( Cfg . StripShadowCasterPass && snippet . passType == PassType . ShadowCaster ) data . Clear ( ) ;
663694 // Process the variants array from behind
664695 for ( int i = data . Count - 1 ; i != - 1 ; -- i )
665696 {
666697 bool remove = false ;
667698 bool isFogExp = data [ i ] . shaderKeywordSet . IsEnabled ( FOG_EXP ) ;
668699 bool isFogExp2 = data [ i ] . shaderKeywordSet . IsEnabled ( FOG_EXP2 ) ;
669700 bool isFogLinear = data [ i ] . shaderKeywordSet . IsEnabled ( FOG_LINEAR ) ;
701+ bool isInstanced = data [ i ] . shaderKeywordSet . IsEnabled ( INSTANCING ) ;
702+ bool isUnityHdrOn = data [ i ] . shaderKeywordSet . IsEnabled ( UNITY_HDR_ON ) ;
703+ bool isLightprobeSH = data [ i ] . shaderKeywordSet . IsEnabled ( LIGHTPROBE_SH ) ;
670704 // Debug.Log(shader.name + " Keywords " + string.Join(", ",
671705 // data[i].shaderKeywordSet.GetShaderKeywords()));
672706 bool isFog = isFogExp | isFogExp2 | isFogLinear ;
673707 if ( Cfg . StripFogNone && ! isFog ) remove = true ;
674- else if ( Cfg . StripFogExp && isFogExp ) remove = true ;
675- else if ( Cfg . StripFogExp2 && isFogExp2 ) remove = true ;
676- else if ( Cfg . StripFogLinear && isFogLinear ) remove = true ;
708+ if ( Cfg . StripFogExp && isFogExp ) remove = true ;
709+ if ( Cfg . StripFogExp2 && isFogExp2 ) remove = true ;
710+ if ( Cfg . StripFogLinear && isFogLinear ) remove = true ;
711+ if ( Cfg . StripUnityHdrOn && isUnityHdrOn ) remove = true ;
712+ if ( Cfg . StripUnityHdrOff && ! isUnityHdrOn ) remove = true ;
713+ if ( Cfg . StripInstancing && isInstanced ) remove = true ;
714+ if ( Cfg . StripNonInstancing && ! isInstanced ) remove = true ;
715+ // Do light stripping according to shader stage
716+ // Deferred needs light, shadow caster does not
717+ if ( Cfg . StripLightForDeferred == false ) {
718+ if ( Cfg . StripLightprobeOn && isLightprobeSH ) remove = true ;
719+ if ( Cfg . StripLightprobeOff && ! isLightprobeSH ) remove = true ;
720+ }
721+ else {
722+ if ( snippet . passType == PassType . Deferred )
723+ remove |= ! isLightprobeSH ;
724+ if ( snippet . passType == PassType . ShadowCaster )
725+ remove |= isLightprobeSH ;
726+ }
727+
677728 if ( remove ) data . RemoveAt ( i ) ;
678729 }
679730 // Print a log if verbose logging is enabled
680- if ( Cfg . VerboseLogging ) Debug . Log ( string . Format (
681- "{0}: {1} variants stripped: {3}, compiling: {2}" ,
682- shader . name , snippet . passName , data . Count ,
731+ for ( int i = 0 ; i < data . Count ; i ++ )
732+ {
733+ if ( Cfg . VerboseLogging ) Debug . Log ( string . Format (
734+ "{0}: {1} {2} Shader for {3} on {4} [{5}]" ,
735+ i , snippet . passType , snippet . shaderType ,
736+ data [ i ] . shaderCompilerPlatform , data [ i ] . buildTarget ,
737+ string . Join ( ", " , data [ i ] . shaderKeywordSet . GetShaderKeywords ( ) ) ) ) ;
738+ }
739+ if ( Cfg . DetailedLogging ) Debug . Log ( string . Format (
740+ "{0}: {1} {2} variants stripped: {4}, compiling: {3}" ,
741+ shader . name , snippet . passType , snippet . shaderType , data . Count ,
683742 StripShaderVariantCounter . ShadersBefore - data . Count ) ) ;
684743 }
685744 }
0 commit comments