Skip to content

Commit

Permalink
Fix shader analyzer parsing ShaderLab case sensitive even though its …
Browse files Browse the repository at this point in the history
…not supposed to be. #130
  • Loading branch information
d4rkc0d3r committed Oct 20, 2024
1 parent c089a20 commit 4aadc42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 14 additions & 12 deletions Editor/ShaderAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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] != "{")
Expand Down Expand Up @@ -1242,7 +1243,7 @@ private void SemanticParseShader()
}
}
}
else if (line == "Tags")
else if (lowerLine == "tags")
{
if (lines[lineIndex + 1] != "{")
{
Expand Down Expand Up @@ -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] != "{")
{
Expand All @@ -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.");
}
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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());
}
}
}
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 4aadc42

Please sign in to comment.