Skip to content

Commit 92fc17e

Browse files
feat: Implement shader generation for toon shader
Co-authored-by: sindharta.tanuwijaya <sindharta.tanuwijaya@unity3d.com>
1 parent 3c2110f commit 92fc17e

14 files changed

+4713
-93
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Unity Toon Shader Generator
2+
3+
This tool helps maintain consistency between `UnityToon.shader` and `UnityToonTessellation.shader` by using a single source of truth for shared properties.
4+
5+
## Files
6+
7+
- **CommonPropertiesPart.shader**: Plain text list of shared property definitions (no Shader wrapper) with original comments preserved (`Packages/com.unity.toonshader/Runtime/Shaders/Common/Parts/`)
8+
- **TessellationPropertiesPart.shader**: Plain text list of tessellation-only property definitions (no Shader wrapper) (`Packages/com.unity.toonshader/Runtime/Shaders/Common/Parts/`)
9+
- **ShaderGenerator.cs**: Unity Editor script (now located in the graphics test package) that generates the shader files from the property assets
10+
11+
## How to Use
12+
13+
1. **Edit Properties**:
14+
- Modify the plain-text part files under `Packages/com.unity.toonshader/Runtime/Shaders/Common/Parts/`
15+
- The files contain only property declarations, so standard ShaderLab property syntax applies
16+
17+
2. **Generate Shader Files**:
18+
- In Unity, choose `Toon Shader > Generate Shader Files`
19+
- The tool will automatically:
20+
- Replace the Properties blocks in both shader files
21+
- Preserve all other shader content (HLSLINCLUDE, SubShaders, etc.)
22+
23+
## Property File Format
24+
25+
Each property file is plain text containing only property declarations, e.g.
26+
27+
```
28+
// Comments are preserved
29+
[HideInInspector] _simpleUI ("SimpleUI", Int ) = 0
30+
[Enum(OFF, 0, ON, 1)] _isUnityToonshader("Material is touched by Unity Toon Shader", Int) = 1
31+
_BaseColor ("BaseColor", Color) = (1,1,1,1)
32+
```
33+
34+
You can use the usual ShaderLab property syntax, including comments and blank lines. The generator indents/layers them into the target shaders automatically.
35+
36+
## Benefits
37+
38+
- **Single Source of Truth**: All shared properties are defined in one place
39+
- **Consistency**: Ensures both shader files have identical shared properties
40+
- **Maintainability**: Easy to add, remove, or modify properties across both shaders
41+
- **Preservation**: All non-Properties content and comments are preserved during generation
42+
- **Comment Preservation**: All original comments from the Properties blocks are maintained
43+
- **Traceability**: Each generated shader receives an `//Auto-generated on ...` timestamp banner at the top
44+
45+
## Manual Generation (Alternative)
46+
47+
If you prefer to generate shaders manually, you can run the Python helper from the repository root:
48+
49+
```bash
50+
cd /workspace
51+
python3 generate_UnityToon.py
52+
```
53+
54+
Convenience launchers are provided as `generate_UnityToon.sh` and `generate_UnityToon.bat`.
55+
56+
## Troubleshooting
57+
58+
- **Properties block not found**: Ensure the shader files have a valid `Properties { }` block
59+
- **File not found errors**: Check that the property files exist in the correct paths
60+
- **Generation fails**: Check the Unity Console for detailed error messages
61+
62+
## File Structure
63+
64+
```
65+
com.unity.toon-graphics-test/
66+
└── Editor/
67+
├── ShaderGenerator.cs # Unity Editor script
68+
├── ShaderGeneratorTest.cs # Editor test harness
69+
└── README_ShaderGenerator.md # This file
70+
71+
com.unity.toonshader/Runtime/Shaders/Common/Parts/
72+
├── CommonPropertiesPart.shader # Shared properties (plain text)
73+
└── TessellationPropertiesPart.shader # Tessellation-specific properties (plain text)
74+
75+
com.unity.toonshader/Runtime/Integrated/Shaders/
76+
├── UnityToon.shader # Generated shader (regular)
77+
└── UnityToonTessellation.shader # Generated shader (tessellation)
78+
79+
generate_UnityToon.py # Python generator (root)
80+
test_generate_UnityToon.py # Python smoke test (root)
81+
test_shader_generation.cs # .NET console smoke test (root)
82+
generate_UnityToon.sh / .bat # Platform launchers for the Python generator
83+
```

0 commit comments

Comments
 (0)