Skip to content

Commit db5215b

Browse files
Refactor: Simplify shader property extraction logic
Co-authored-by: sindharta.tanuwijaya <sindharta.tanuwijaya@unity3d.com>
1 parent 6b22ce1 commit db5215b

File tree

7 files changed

+531
-555
lines changed

7 files changed

+531
-555
lines changed

com.unity.toon-graphics-test/Editor/README_ShaderGenerator.md

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ This tool helps maintain consistency between `UnityToon.shader` and `UnityToonTe
44

55
## Files
66

7-
- **CommonPropertiesPart.shader**: Hidden shader asset that contains the shared `Properties` block for both shaders, with original comments preserved
8-
- **TessellationPropertiesPart.shader**: Hidden shader asset that contains tessellation-specific properties only present in the tessellation shader
7+
- **CommonPropertiesPart.shader**: Plain text list of shared property definitions (no Shader wrapper) with original comments preserved
8+
- **TessellationPropertiesPart.shader**: Plain text list of tessellation-only property definitions (no Shader wrapper)
99
- **ShaderGenerator.cs**: Unity Editor script (now located in the graphics test package) that generates the shader files from the property assets
1010

1111
## How to Use
@@ -27,28 +27,16 @@ This tool helps maintain consistency between `UnityToon.shader` and `UnityToonTe
2727

2828
## Property File Format
2929

30-
The property files are valid ShaderLab assets that wrap the shared definitions in a minimal hidden shader. The generator extracts only the body of the `Properties` block.
30+
Each property file is plain text containing only property declarations, e.g.
3131

3232
```
33-
Shader "Hidden/UnityToon/CommonPropertiesPart"
34-
{
35-
Properties
36-
{
37-
// Comments are preserved
38-
[HideInInspector] _simpleUI ("SimpleUI", Int ) = 0
39-
[Enum(OFF, 0, ON, 1)] _isUnityToonshader("Material is touched by Unity Toon Shader", Int) = 1
40-
_BaseColor ("BaseColor", Color) = (1,1,1,1)
41-
}
42-
43-
SubShader
44-
{
45-
Tags { "RenderType"="Opaque" }
46-
Pass { }
47-
}
48-
}
33+
// Comments are preserved
34+
[HideInInspector] _simpleUI ("SimpleUI", Int ) = 0
35+
[Enum(OFF, 0, ON, 1)] _isUnityToonshader("Material is touched by Unity Toon Shader", Int) = 1
36+
_BaseColor ("BaseColor", Color) = (1,1,1,1)
4937
```
5038

51-
Inside the `Properties` block you can use the same syntax as in any ShaderLab shader. Comments and blank lines are preserved.
39+
You can use the usual ShaderLab property syntax, including comments and blank lines. The generator indents/layers them into the target shaders automatically.
5240

5341
## Benefits
5442

@@ -86,8 +74,8 @@ com.unity.toon-graphics-test/
8674
└── README_ShaderGenerator.md # This file
8775
8876
com.unity.toonshader/Runtime/Integrated/Shaders/
89-
├── CommonPropertiesPart.shader # Shared properties with comments (hidden shader asset)
90-
├── TessellationPropertiesPart.shader # Tessellation-specific properties (hidden shader asset)
77+
├── CommonPropertiesPart.shader # Shared properties (plain text)
78+
├── TessellationPropertiesPart.shader # Tessellation-specific properties (plain text)
9179
├── UnityToon.shader # Generated shader (regular)
9280
└── UnityToonTessellation.shader # Generated shader (tessellation)
9381

com.unity.toon-graphics-test/Editor/ShaderGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ private string ExtractPropertiesBlockContent(string shaderContent)
275275
Match startMatch = Regex.Match(shaderContent, propertiesPattern);
276276
if (!startMatch.Success)
277277
{
278-
return null;
278+
return shaderContent.Trim();
279279
}
280280

281281
int openBraceIndex = shaderContent.IndexOf('{', startMatch.Index);
282282
if (openBraceIndex == -1)
283283
{
284-
return null;
284+
return shaderContent.Trim();
285285
}
286286

287287
int braceCount = 1;
@@ -307,7 +307,7 @@ private string ExtractPropertiesBlockContent(string shaderContent)
307307

308308
if (closeBraceIndex == -1)
309309
{
310-
return null;
310+
return shaderContent.Trim();
311311
}
312312

313313
string block = shaderContent.Substring(openBraceIndex + 1, closeBraceIndex - openBraceIndex - 1);

0 commit comments

Comments
 (0)