diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index b43c3b804ac..c99607810a8 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -6,16 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [7.5.0] - 2020-06-08 -Version Updated -The version number for this package has increased due to a version update of a related graphics package. - ### Added - Added option to enable/disable Adaptive Performance when it's package is available. ### Fixed - - Fixed an issue where URP Simple Lit shader had attributes swapped incorrectly for BaseMap and BaseColor properties. - Fixed an issue where camera stacking with MSAA on OpenGL resulted in a black screen. [case 1250602](https://issuetracker.unity3d.com/issues/urp-camera-stacking-results-in-black-screen-when-msaa-and-opengl-graphics-api-are-used) +- Fixed issue with Model Importer materials using the Legacy standard shader instead of URP's Lit shader when import happens at Editor startup. ## [7.4.1] - 2020-06-03 diff --git a/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/FBXMaterialDescriptionPreprocessor.cs b/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/FBXMaterialDescriptionPreprocessor.cs index 28d0b538dae..4a760b98d4c 100644 --- a/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/FBXMaterialDescriptionPreprocessor.cs +++ b/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/FBXMaterialDescriptionPreprocessor.cs @@ -2,6 +2,7 @@ using System.IO; using UnityEditor.AssetImporters; using UnityEngine; +using UnityEngine.Rendering.Universal; namespace UnityEditor.Rendering.Universal { @@ -25,8 +26,9 @@ public void OnPreprocessMaterialDescription(MaterialDescription description, Mat var lowerCaseExtension = Path.GetExtension(assetPath).ToLower(); if (lowerCaseExtension != ".fbx" && lowerCaseExtension != ".obj" && lowerCaseExtension != ".blend" && lowerCaseExtension != ".mb" && lowerCaseExtension != ".ma" && lowerCaseExtension != ".max") return; - - var shader = Shader.Find("Universal Render Pipeline/Lit"); + + string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit)); + var shader = AssetDatabase.LoadAssetAtPath(path); if (shader == null) return; diff --git a/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/SketchupMaterialDescriptionPostprocessor.cs b/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/SketchupMaterialDescriptionPostprocessor.cs index 2f3c27a36b4..a3e57f71e78 100644 --- a/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/SketchupMaterialDescriptionPostprocessor.cs +++ b/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/SketchupMaterialDescriptionPostprocessor.cs @@ -2,6 +2,7 @@ using System.IO; using UnityEngine; using UnityEditor.AssetImporters; +using UnityEngine.Rendering.Universal; namespace UnityEditor.Rendering.Universal { @@ -27,7 +28,8 @@ public void OnPreprocessMaterialDescription(MaterialDescription description, Mat if (lowerCasePath != ".skp") return; - var shader = Shader.Find("Universal Render Pipeline/Lit"); + string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit)); + var shader = AssetDatabase.LoadAssetAtPath(path); if (shader == null) return; material.shader = shader; diff --git a/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/ThreeDSMaterialDescriptionPostprocessor.cs b/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/ThreeDSMaterialDescriptionPostprocessor.cs index 1220365215a..10535eeea45 100644 --- a/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/ThreeDSMaterialDescriptionPostprocessor.cs +++ b/com.unity.render-pipelines.universal/Editor/AssetPostProcessors/ThreeDSMaterialDescriptionPostprocessor.cs @@ -2,6 +2,7 @@ using System.IO; using UnityEngine; using UnityEditor.AssetImporters; +using UnityEngine.Rendering.Universal; namespace UnityEditor.Rendering.Universal { @@ -27,7 +28,8 @@ public void OnPreprocessMaterialDescription(MaterialDescription description, Mat if (lowerCasePath != ".3ds") return; - var shader = Shader.Find("Universal Render Pipeline/Lit"); + string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit)); + var shader = AssetDatabase.LoadAssetAtPath(path); if (shader == null) return; material.shader = shader; diff --git a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs index 112bac9ed1d..d7bca39b780 100644 --- a/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs +++ b/com.unity.render-pipelines.universal/Runtime/Data/UniversalRenderPipelineAsset.cs @@ -4,8 +4,10 @@ using UnityEditor; using UnityEditor.ProjectWindowCallback; using System.IO; +using UnityEditorInternal; #endif using System.ComponentModel; +using System.Linq; namespace UnityEngine.Rendering.LWRP { @@ -296,9 +298,10 @@ UniversalRenderPipelineEditorResources editorResources { if (m_EditorResourcesAsset != null && !m_EditorResourcesAsset.Equals(null)) return m_EditorResourcesAsset; - + string resourcePath = AssetDatabase.GUIDToAssetPath(editorResourcesGUID); - m_EditorResourcesAsset = AssetDatabase.LoadAssetAtPath(resourcePath); + var objs = InternalEditorUtility.LoadSerializedFileAndForget(resourcePath); + m_EditorResourcesAsset = objs != null && objs.Length > 0 ? objs.First() as UniversalRenderPipelineEditorResources : null; return m_EditorResourcesAsset; } } @@ -756,6 +759,12 @@ public override Shader defaultShader if (defaultShader != null) return defaultShader; } + + if (m_DefaultShader == null) + { + string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit)); + m_DefaultShader = AssetDatabase.LoadAssetAtPath(path); + } #endif if (m_DefaultShader == null) diff --git a/com.unity.render-pipelines.universal/Runtime/ShaderUtils.cs b/com.unity.render-pipelines.universal/Runtime/ShaderUtils.cs index 0ae2ecd96a8..01149ae8fae 100644 --- a/com.unity.render-pipelines.universal/Runtime/ShaderUtils.cs +++ b/com.unity.render-pipelines.universal/Runtime/ShaderUtils.cs @@ -53,5 +53,31 @@ public static bool IsLWShader(Shader shader) { return s_ShaderPaths.Contains(shader.name); } + +#if UNITY_EDITOR + static readonly string[] s_ShaderGUIDs = + { + "933532a4fcc9baf4fa0491de14d08ed7", + "8d2bb70cbf9db8d4da26e15b26e74248", + "650dd9526735d5b46b79224bc6e94025", + "69c1f799e772cb6438f56c23efccb782", + "b7839dad95683814aa64166edc107ae2", + "8516d7a69675844a7a0b7095af7c46af", + "0406db5a14f94604a8c57ccfbc9f3b46", + "0ca6dca7396eb48e5849247ffd444914", + }; + + internal static string GetShaderGUID(ShaderPathID id) + { + int index = (int)id; + if (index < 0 && index >= (int)ShaderPathID.Count) + { + Debug.LogError("Trying to access universal shader path out of bounds"); + return ""; + } + + return s_ShaderGUIDs[index]; + } +#endif } } diff --git a/com.unity.render-pipelines.universal/Tests/Editor/EditorTests.cs b/com.unity.render-pipelines.universal/Tests/Editor/EditorTests.cs index 9bfa9a37c7a..dc5e2bce579 100644 --- a/com.unity.render-pipelines.universal/Tests/Editor/EditorTests.cs +++ b/com.unity.render-pipelines.universal/Tests/Editor/EditorTests.cs @@ -64,6 +64,24 @@ public void ValidateBuiltinResourceFiles() Assert.IsFalse(string.IsNullOrEmpty(editorResourcesPath)); } + // Validate that ShaderUtils.GetShaderGUID results are valid and that ShaderUtils.GetShaderPath match shader names. + [TestCase(ShaderPathID.Lit)] + [TestCase(ShaderPathID.SimpleLit)] + [TestCase(ShaderPathID.Unlit)] + [TestCase(ShaderPathID.TerrainLit)] + [TestCase(ShaderPathID.ParticlesLit)] + [TestCase(ShaderPathID.ParticlesSimpleLit)] + [TestCase(ShaderPathID.ParticlesUnlit)] + [TestCase(ShaderPathID.BakedLit)] + public void ValidateShaderResources(ShaderPathID shaderPathID) + { + string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(shaderPathID)); + Assert.IsFalse(string.IsNullOrEmpty(path)); + + var shader = AssetDatabase.LoadAssetAtPath(path); + Assert.AreEqual(shader.name, ShaderUtils.GetShaderPath(shaderPathID)); + } + // When creating URP all required resources should be initialized. [Test] public void ValidateNewAssetResources()