-
Notifications
You must be signed in to change notification settings - Fork 860
[HOLD][case 1347209] Only process materials of the same SRP that the MaterialPostProcessor #5071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2e1dd52
2cd1ee3
d5ece55
ca0bac9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| using UnityEngine; | ||
| using UnityEngine.Rendering.Universal; | ||
| using static Unity.Rendering.Universal.ShaderUtils; | ||
| using UnityEditor.Rendering.Universal.ShaderGraph; | ||
|
|
||
| namespace UnityEditor.Rendering.Universal | ||
| { | ||
|
|
@@ -25,9 +26,27 @@ class MaterialReimporter : Editor | |
| { | ||
| static bool s_NeedToCheckProjSettingExistence = true; | ||
|
|
||
|
|
||
| internal static bool IsURPShader(Shader shader) | ||
| { | ||
| if (shader == null) | ||
| return false; | ||
|
|
||
| if (shader.IsShaderGraphAsset()) | ||
| { | ||
| return shader.TryGetMetadataOfType<UniversalMetadata>(out _); | ||
| } | ||
| else if (ShaderUtils.IsLWShader(shader)) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| return shader.name.Contains("Universal Render Pipeline"); | ||
| } | ||
|
|
||
| static void ReimportAllMaterials() | ||
| { | ||
| string[] guids = AssetDatabase.FindAssets("t:material", null); | ||
| string[] guids = AssetDatabase.FindAssets($"glob:\"*.mat\""); | ||
| // There can be several materials subAssets per guid ( ie : FBX files ), remove duplicate guids. | ||
| var distinctGuids = guids.Distinct(); | ||
|
|
||
|
|
@@ -38,6 +57,13 @@ static void ReimportAllMaterials() | |
| materialIdx++; | ||
| var path = AssetDatabase.GUIDToAssetPath(asset); | ||
| EditorUtility.DisplayProgressBar("Material Upgrader re-import", string.Format("({0} of {1}) {2}", materialIdx, totalMaterials, path), (float)materialIdx / (float)totalMaterials); | ||
| var material = (Material)AssetDatabase.LoadAssetAtPath(asset, typeof(Material)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly this will slow up the import :/
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bastienunity do you have an idea on how i can properly enforce to process Materials from only the RenderPipeline I am interested in?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you can as you have to load them in memory to figure out the shader.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Bastien and I had a discussion there are some things I could implement for this PR. |
||
| if (material == null || material.shader == null) | ||
| continue; | ||
| if (!IsURPShader(material.shader)) | ||
| { | ||
| continue; | ||
| } | ||
| AssetDatabase.ImportAsset(path); | ||
| } | ||
| EditorUtility.ClearProgressBar(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be part of ShaderUtils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree but in URP ShaderUtils is part of the Runtime portion and most of these function are Editor only (IsShaderGraphAsset for ex)