@@ -664,6 +664,9 @@ private List<ShaderBlock> OptimizeBlocks(List<ShaderBlock> sourceBlocks)
664
664
var block = collapsedBlocks [ i ] ;
665
665
switch ( block . Name )
666
666
{
667
+ case "%ShaderTags" :
668
+ block . Contents = DeDuplicateByParser ( block . Contents , DeDupeType . Tags ) ;
669
+ continue ;
667
670
case "%Properties" :
668
671
collapsedBlocks [ i ] . Contents = DeDuplicateByParser ( block . Contents , DeDupeType . Properties ) ;
669
672
continue ;
@@ -691,7 +694,8 @@ private List<ShaderBlock> OptimizeBlocks(List<ShaderBlock> sourceBlocks)
691
694
692
695
private enum DeDupeType
693
696
{
694
- Properties
697
+ Properties ,
698
+ Tags ,
695
699
}
696
700
697
701
private List < string > DeDuplicateByParser ( List < string > source , DeDupeType type )
@@ -721,6 +725,40 @@ private List<string> DeDuplicateByParser(List<string> source, DeDupeType type)
721
725
}
722
726
break ;
723
727
}
728
+ case DeDupeType . Tags :
729
+ {
730
+ var dedupedTags = new Dictionary < string , string > ( ) ;
731
+ var dedupedTagsString = new StringBuilder ( ) ;
732
+ combined = $ "Tags {{{combined}}}";
733
+ var tokens = ShaderLabLexer . Lex ( combined , null , null , false , out _ ) ;
734
+ var nodes = ShaderLabParser . ParseShaderLabCommands ( tokens , ShaderAnalyzers . SLConfig , out _ ) ;
735
+ foreach ( var node in nodes )
736
+ {
737
+ if ( node is not ShaderLabCommandTagsNode tags ) continue ;
738
+ foreach ( var tag in tags . Tags )
739
+ {
740
+ tag . Deconstruct ( out var tagKey , out var tagValue ) ;
741
+ if ( keySet . Contains ( tagKey ) )
742
+ {
743
+ if ( debugBuild )
744
+ {
745
+ Debug . LogWarning ( "Found duplicate tag, updating: " + tagKey + " to " + tagValue ) ;
746
+ }
747
+ dedupedTags [ tagKey ] = tagValue ;
748
+ continue ;
749
+ }
750
+ keySet . Add ( tagKey ) ;
751
+ dedupedTags . Add ( tagKey , tagValue ) ;
752
+ }
753
+ }
754
+
755
+ foreach ( var ( key , value ) in dedupedTags )
756
+ {
757
+ dedupedTagsString . Append ( $ "\" { key } \" = \" { value } \" ") ;
758
+ }
759
+ deduped . Add ( dedupedTagsString . ToString ( ) ) ;
760
+ break ;
761
+ }
724
762
}
725
763
return deduped ;
726
764
}
0 commit comments