Skip to content

Refactor convert#789

Open
sindharta wants to merge 13 commits intomasterfrom
refactor-convert
Open

Refactor convert#789
sindharta wants to merge 13 commits intomasterfrom
refactor-convert

Conversation

@sindharta
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors toon shader conversion and editor tests to use centralized editor constants for package shader paths, reducing reliance on shader-name lookups.

Changes:

  • Added ToonEditorConstants shader asset paths for the main and tessellation toon shaders.
  • Updated the shader compile editor test to compile specific shaders via explicit package paths and added the needed editor assembly reference.
  • Updated converter code to load toon shaders via AssetDatabase.LoadAssetAtPath (with caching) instead of Shader.Find.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
com.unity.toonshader/Tests/Editor/Unity.ToonShader.EditorTests.asmdef Adds reference to the editor assembly so tests can access editor-side constants/APIs.
com.unity.toonshader/Tests/Editor/ShaderCompileTest.cs Switches test to compile specific shader assets using ToonEditorConstants paths and asserts they load.
com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs Introduces centralized shader asset path constants under the package path.
com.unity.toonshader/Editor/Converter/RenderPipelineConverterContainer.cs Replaces Shader.Find with cached load-by-path helper to assign toon shaders during conversion.
com.unity.toonshader/Editor/Converter/FromUTS2/BuiltInUTS2toIntegratedConverter.cs Uses the new shader loading helper during conversion.
com.unity.toonshader/Editor/AssemblyInfo.cs Adds InternalsVisibleTo for the editor tests assembly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[assembly: InternalsVisibleTo("Unity.VisualCompositor.Editor")]
[assembly: InternalsVisibleTo("Unity.VisualCompositor.EditorTests")]

[assembly: InternalsVisibleTo("Unity.ToonShader.EditorTests")]
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InternalsVisibleTo target assembly name casing doesn't match the test asmdef name (Unity.Toonshader.EditorTests). If the names don't match exactly, editor internals (e.g., ToonEditorConstants) won't be visible to the tests, causing compile errors. Update the attribute string to exactly match the asmdef's name value (and keep casing consistent across assemblies).

Suggested change
[assembly: InternalsVisibleTo("Unity.ToonShader.EditorTests")]
[assembly: InternalsVisibleTo("Unity.Toonshader.EditorTests")]

Copilot uses AI. Check for mistakes.
Comment on lines +244 to +259
protected Shader GetOrLoadToonShader(bool tess) {
if (tess) {
return GetOrLoadToonShader(ref m_toonTessShader, ToonEditorConstants.TOON_TESS_SHADER_PATH);
}

return GetOrLoadToonShader(ref m_toonShader, ToonEditorConstants.TOON_SHADER_PATH);

}

Shader GetOrLoadToonShader(ref Shader shader, string path) {
if (null != shader)
return shader;

shader = AssetDatabase.LoadAssetAtPath<Shader>(path);
return shader;
}
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetOrLoadToonShader can return null when the shader asset can't be loaded at the expected package path; the caller then assigns material.shader = null, which can break subsequent conversion steps. Add an explicit null check after LoadAssetAtPath (log an actionable error including the path/material), and consider a fallback to Shader.Find using the known shader names to preserve behavior if assets are relocated/missing.

Suggested change
protected Shader GetOrLoadToonShader(bool tess) {
if (tess) {
return GetOrLoadToonShader(ref m_toonTessShader, ToonEditorConstants.TOON_TESS_SHADER_PATH);
}
return GetOrLoadToonShader(ref m_toonShader, ToonEditorConstants.TOON_SHADER_PATH);
}
Shader GetOrLoadToonShader(ref Shader shader, string path) {
if (null != shader)
return shader;
shader = AssetDatabase.LoadAssetAtPath<Shader>(path);
return shader;
}
protected Shader GetOrLoadToonShader(bool tess, Material material = null) {
if (tess) {
return GetOrLoadToonShader(ref m_toonTessShader, ToonEditorConstants.TOON_TESS_SHADER_PATH, material);
}
return GetOrLoadToonShader(ref m_toonShader, ToonEditorConstants.TOON_SHADER_PATH, material);
}
Shader GetOrLoadToonShader(ref Shader shader, string path, Material material = null) {
if (null != shader)
return shader;
shader = AssetDatabase.LoadAssetAtPath<Shader>(path);
if (null != shader)
return shader;
string shaderFileName = Path.GetFileNameWithoutExtension(path);
shader = FindShaderAssetByFileName(shaderFileName);
if (null != shader) {
Debug.LogWarning($"Toon shader could not be loaded from expected path '{path}' for material '{(material != null ? material.name : "<unknown>")}'. Using relocated shader asset '{shader.name}' found by filename lookup instead.");
return shader;
}
shader = Shader.Find(shaderFileName);
if (null != shader) {
Debug.LogWarning($"Toon shader could not be loaded from expected path '{path}' for material '{(material != null ? material.name : "<unknown>")}'. Using Shader.Find('{shaderFileName}') as a fallback.");
return shader;
}
Debug.LogError($"Failed to load Toon shader from expected path '{path}' for material '{(material != null ? material.name : "<unknown>")}'. Ensure the shader asset exists at that path or pass the correct shader reference to the converter.");
return null;
}
private Shader FindShaderAssetByFileName(string shaderFileName) {
string[] guids = AssetDatabase.FindAssets($"{shaderFileName} t:Shader");
foreach (string guid in guids) {
string candidatePath = AssetDatabase.GUIDToAssetPath(guid);
if (!string.Equals(Path.GetFileNameWithoutExtension(candidatePath), shaderFileName, StringComparison.OrdinalIgnoreCase))
continue;
Shader candidateShader = AssetDatabase.LoadAssetAtPath<Shader>(candidatePath);
if (null != candidateShader)
return candidateShader;
}
return null;
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants