Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions ShaderStripperVariantCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_2018_2_OR_NEWER
#if UNITY_2018_2_OR_NEWER
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -82,6 +82,7 @@ void ReplaceOverwrittenCollections(){
bool ShaderVariantsEqual(ShaderVariantCollection.ShaderVariant a, ShaderVariantCollection.ShaderVariant b){
if (a.shader != b.shader || a.passType != b.passType) return false;
if ((a.keywords == null) != (b.keywords == null)) return false;
if (a.keywords == null && b.keywords == null) return true;
if (a.keywords.Length != b.keywords.Length) return false;
_tempCompareShaderVariants.Clear();
_tempCompareShaderVariants.AddRange(a.keywords);
Expand Down Expand Up @@ -410,22 +411,30 @@ protected override bool StripCustom(Shader shader, ShaderSnippetData passData, I

// Loop over cached variants
foreach (var collectedVariant in collectedPassVariants){

// Must match ALL keywords
_tempRequestedKeywordsToMatch.Clear();
_tempRequestedKeywordsToMatch.AddRange(_tempRequestedKeywordsToMatchCached);

// Early out (no match) if keyword counts don't match
if (_tempRequestedKeywordsToMatch.Count != collectedVariant.keywords.Length) continue;

// Early out (match) if both have no keywords
if (_tempRequestedKeywordsToMatch.Count == 0 && collectedVariant.keywords.Length == 0){
if (_tempRequestedKeywordsToMatch.Count == 0 && (collectedVariant.keywords == null || collectedVariant.keywords.Length == 0))
{
variantMatched = true;
break;
}

// No match
if (collectedVariant.keywords == null)
continue;

// Early out (no match) if keyword counts don't match
if (_tempRequestedKeywordsToMatch.Count != collectedVariant.keywords.Length)
continue;

// Check all keywords
_tempCollectedKeywordsSorted.Clear();
_tempCollectedKeywordsSorted.AddRange(collectedVariant.keywords);
if (collectedVariant.keywords != null)
_tempCollectedKeywordsSorted.AddRange(collectedVariant.keywords);
_tempCollectedKeywordsSorted.Sort((a,b)=>{return string.CompareOrdinal(a,b);});
foreach (var k in _tempCollectedKeywordsSorted){
bool keywordMatched = _tempRequestedKeywordsToMatch.Remove(k);
Expand Down Expand Up @@ -483,4 +492,4 @@ public override void OnGUI(){
#endif
}
}
#endif
#endif