diff --git a/CHANGELOG.md b/CHANGELOG.md index ac2d79c..a0fa067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v3.9.2 ### Bug Fixes * Fix shader analyzer not handling `_fragment` and other per pass suffixes for `shader_feature` pragmas. +* Fix shader analyzer parsing ShaderLab case sensitive even though its not supposed to be. [(more)](https://github.com/d4rkc0d3r/d4rkAvatarOptimizer/pull/130) ## v3.9.1 ### Bug Fixes diff --git a/Editor/ShaderAnalyzer.cs b/Editor/ShaderAnalyzer.cs index e297f84..7594e8e 100644 --- a/Editor/ShaderAnalyzer.cs +++ b/Editor/ShaderAnalyzer.cs @@ -1197,7 +1197,8 @@ private void SemanticParseShader() for (int lineIndex = 0; lineIndex < lines.Count; lineIndex++) { string line = lines[lineIndex]; - if (line == "Properties") + string lowerLine = line.ToLowerInvariant(); + if (lowerLine == "properties") { foundProperties = true; if (lines[lineIndex + 1] != "{") @@ -1242,7 +1243,7 @@ private void SemanticParseShader() } } } - else if (line == "Tags") + else if (lowerLine == "tags") { if (lines[lineIndex + 1] != "{") { @@ -1304,7 +1305,7 @@ private void SemanticParseShader() output.Add(line == "CGPROGRAM" ? "ENDCG" : "ENDHLSL"); currentPass.codeBlockLineCount = output.Count - currentPass.startLineIndex - currentPass.codeBlockStartIndex; } - else if (line == "Pass") + else if (lowerLine == "pass") { if (lines[lineIndex + 1] != "{") { @@ -1315,10 +1316,10 @@ private void SemanticParseShader() currentPass.startLineIndex = output.Count; passCurlyBraceDepth = 1; lineIndex++; - output.Add($"Pass//{parsedShader.passes.Count-1}"); + output.Add($"pass//{parsedShader.passes.Count-1}"); output.Add("{"); } - else if (line.StartsWithSimple("UsePass")) + else if (lowerLine.StartsWithSimple("usepass")) { throw new ParserException("UsePass is not supported."); } @@ -1337,7 +1338,7 @@ private void SemanticParseShader() bool hasColorMask0 = false; for (int i = currentPass.startLineIndex; i < output.Count; i++) { - if (output[i].StartsWithSimple("ColorMask") && output[i].EndsWith("0")) + if (output[i].ToLowerInvariant().StartsWithSimple("colormask") && output[i].EndsWith("0")) { hasColorMask0 = true; break; @@ -1374,7 +1375,7 @@ private void SemanticParseShader() output.Add(line); } } - else if (currentPass != null && line.StartsWithSimple("Name")) + else if (currentPass != null && lowerLine.StartsWithSimple("name")) { currentPass.name = line.Substring(5).Trim('\t', ' ', '"').ToUpperInvariant(); } @@ -1392,7 +1393,7 @@ private void SemanticParseShader() string propName = match.Groups[1].Value; if (parsedShader.propertyTable.TryGetValue(propName, out var prop)) { - prop.shaderLabParams.Add(shaderLabParam); + prop.shaderLabParams.Add(shaderLabParam.ToLowerInvariant()); } } } @@ -1401,7 +1402,7 @@ private void SemanticParseShader() } if (!foundProperties) { - output.Insert(2, "Properties"); + output.Insert(2, "properties"); output.Insert(3, "{"); output.Insert(4, "}"); foreach (var pass in parsedShader.passes) @@ -3177,7 +3178,7 @@ private void Run() ParseAndEvaluateIfex(lines, ref lineIndex, output); string line = lines[lineIndex++]; output.Add(line); - if (line == "Properties") + if (line.ToLowerInvariant() == "properties") { break; } @@ -3273,9 +3274,10 @@ private void Run() { ParseAndEvaluateIfex(lines, ref lineIndex, output); string line = lines[lineIndex]; - if (line.StartsWithSimple("CustomEditor")) + string lowerLine = line.ToLowerInvariant(); + if (lowerLine.StartsWithSimple("customeditor")) continue; - if (line.StartsWithSimple("Pass//")) + if (lowerLine.StartsWithSimple("pass//")) { passID = int.Parse(line.Substring(6)); currentPass = parsedShader.passes[passID];