Skip to content

Commit c6711f0

Browse files
Refactor: Move shader properties to common folder
This commit reorganizes shader property files into a common directory and removes BOM characters. Co-authored-by: sindharta.tanuwijaya <sindharta.tanuwijaya@unity3d.com>
1 parent db5215b commit c6711f0

File tree

8 files changed

+17
-14
lines changed

8 files changed

+17
-14
lines changed
9.59 KB
Binary file not shown.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace UnityEditor.Rendering.Toon
1717
public class ShaderGenerator : EditorWindow
1818
{
1919
private static readonly Regex PropertyNameRegex = new Regex(@"(?:\]\s*|^)([A-Za-z_][A-Za-z0-9_]*)\s*\(", RegexOptions.Compiled);
20-
private const string COMMON_PROPERTIES_PATH = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders/CommonPropertiesPart.shader";
21-
private const string TESSELATION_PROPERTIES_PATH = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders/TessellationPropertiesPart.shader";
20+
private const string COMMON_PROPERTIES_PATH = "Packages/common.unity.toonshader/Runtime/Shaders/Common/Parts~/CommonPropertiesPart.shader";
21+
private const string TESSELATION_PROPERTIES_PATH = "Packages/common.unity.toonshader/Runtime/Shaders/Common/Parts~/TessellationPropertiesPart.shader";
2222
private const string UNITY_TOON_SHADER_PATH = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders/UnityToon.shader";
2323
private const string UNITY_TOON_TESSELATION_SHADER_PATH = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders/UnityToonTessellation.shader";
2424

@@ -376,7 +376,7 @@ private string ReadFile(string path)
376376
{
377377
if (File.Exists(path))
378378
{
379-
return File.ReadAllText(path);
379+
return File.ReadAllText(path).TrimStart('\uFEFF');
380380
}
381381
return null;
382382
}
@@ -390,7 +390,7 @@ private void WriteFile(string path, string content)
390390
Directory.CreateDirectory(directory);
391391
}
392392

393-
File.WriteAllText(path, content);
393+
File.WriteAllText(path, content.TrimStart('\uFEFF'));
394394
}
395395

396396
private string ApplyAutoGeneratedComment(string content, string commentLine)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void TestShaderGeneration()
1818
try
1919
{
2020
// Test reading the common properties file
21-
string commonPropertiesPath = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders/CommonPropertiesPart.shader";
21+
string commonPropertiesPath = "Packages/common.unity.toonshader/Runtime/Shaders/Common/Parts~/CommonPropertiesPart.shader";
2222
string commonPropertiesShader = File.ReadAllText(commonPropertiesPath);
2323

2424
if (string.IsNullOrEmpty(commonPropertiesShader))
@@ -36,7 +36,7 @@ public static void TestShaderGeneration()
3636
Debug.Log($"Successfully extracted common properties. Length: {commonProperties.Length} characters");
3737

3838
// Test reading the tessellation properties file
39-
string tessellationPropertiesPath = "Packages/com.unity.toonshader/Runtime/Integrated/Shaders/TessellationPropertiesPart.shader";
39+
string tessellationPropertiesPath = "Packages/common.unity.toonshader/Runtime/Shaders/Common/Parts~/TessellationPropertiesPart.shader";
4040
string tessellationPropertiesShader = File.ReadAllText(tessellationPropertiesPath);
4141

4242
if (string.IsNullOrEmpty(tessellationPropertiesShader))

generate_UnityToon.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ def get_property_name(line: str):
5656

5757

5858
def load_properties_from_shader(shader_path, descriptor):
59-
with open(shader_path, 'r') as f:
59+
with open(shader_path, 'r', encoding='utf-8') as f:
6060
shader_content = f.read()
6161

6262
if not shader_content:
6363
print(f"ERROR: {descriptor} shader file is empty or could not be read")
6464
return None
6565

66+
shader_content = shader_content.lstrip('\ufeff')
67+
6668
properties = extract_properties_from_shader_content(shader_content)
6769
if not properties:
6870
print(f"ERROR: Could not extract {descriptor} properties from {shader_path}")
@@ -75,13 +77,13 @@ def load_properties_from_shader(shader_path, descriptor):
7577
def generate_shader_files():
7678
try:
7779
# Read the common properties shader
78-
common_properties_path = "com.unity.toonshader/Runtime/Integrated/Shaders/CommonPropertiesPart.shader"
80+
common_properties_path = "common.unity.toonshader/Runtime/Shaders/Common/Parts~/CommonPropertiesPart.shader"
7981
common_properties = load_properties_from_shader(common_properties_path, "common")
8082
if not common_properties:
8183
return False
8284

8385
# Read the tessellation properties shader
84-
tessellation_properties_path = "com.unity.toonshader/Runtime/Integrated/Shaders/TessellationPropertiesPart.shader"
86+
tessellation_properties_path = "common.unity.toonshader/Runtime/Shaders/Common/Parts~/TessellationPropertiesPart.shader"
8587
tessellation_properties = load_properties_from_shader(tessellation_properties_path, "tessellation")
8688
if tessellation_properties is None:
8789
return False
@@ -237,7 +239,8 @@ def append_property_line(stripped_line, allow_override):
237239
print(f"Generated new shader content. Original length: {len(original_content)}, New length: {len(new_content)}")
238240

239241
# Write the new shader file
240-
with open(shader_path, 'w') as f:
242+
new_content = new_content.lstrip('\ufeff')
243+
with open(shader_path, 'w', encoding='utf-8') as f:
241244
f.write(new_content)
242245

243246
print(f"Successfully wrote {shader_path}")

test_generate_UnityToon.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static void Main()
1010
try
1111
{
1212
// Test reading the common properties shader
13-
string commonPropertiesPath = "com.unity.toonshader/Runtime/Integrated/Shaders/CommonPropertiesPart.shader";
13+
string commonPropertiesPath = "common.unity.toonshader/Runtime/Shaders/Common/Parts~/CommonPropertiesPart.shader";
1414
string commonPropertiesShader = File.ReadAllText(commonPropertiesPath);
1515

1616
if (string.IsNullOrEmpty(commonPropertiesShader))
@@ -28,7 +28,7 @@ static void Main()
2828
Console.WriteLine($"Successfully extracted common properties. Length: {commonProperties.Length} characters");
2929

3030
// Test reading the tessellation properties shader
31-
string tessellationPropertiesPath = "com.unity.toonshader/Runtime/Integrated/Shaders/TessellationPropertiesPart.shader";
31+
string tessellationPropertiesPath = "common.unity.toonshader/Runtime/Shaders/Common/Parts~/TessellationPropertiesPart.shader";
3232
string tessellationPropertiesShader = File.ReadAllText(tessellationPropertiesPath);
3333

3434
if (string.IsNullOrEmpty(tessellationPropertiesShader))

test_generate_UnityToon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def test_shader_generation():
1313
try:
1414
# Test reading the common properties shader
15-
common_properties_path = "com.unity.toonshader/Runtime/Integrated/Shaders/CommonPropertiesPart.shader"
15+
common_properties_path = "common.unity.toonshader/Runtime/Shaders/Common/Parts~/CommonPropertiesPart.shader"
1616
with open(common_properties_path, 'r') as f:
1717
common_properties_shader = f.read()
1818

@@ -28,7 +28,7 @@ def test_shader_generation():
2828
print(f"Successfully extracted common properties. Length: {len(common_properties)} characters")
2929

3030
# Test reading the tessellation properties shader
31-
tessellation_properties_path = "com.unity.toonshader/Runtime/Integrated/Shaders/TessellationPropertiesPart.shader"
31+
tessellation_properties_path = "common.unity.toonshader/Runtime/Shaders/Common/Parts~/TessellationPropertiesPart.shader"
3232
with open(tessellation_properties_path, 'r') as f:
3333
tessellation_properties_shader = f.read()
3434

0 commit comments

Comments
 (0)