using System; using System.Linq; namespace UnityEngine.Rendering.Universal { /// /// Options to get a shader path to URP shaders when calling ShaderUtils.GetShaderGUID(); /// . /// public enum ShaderPathID { /// /// Use this for URP Lit shader. /// Lit, /// /// Use this for URP Simple Lit shader. /// SimpleLit, /// /// Use this for URP Unlit shader. /// Unlit, /// /// Use this for URP Terrain Lit shader. /// TerrainLit, /// /// Use this for URP Particles Lit shader. /// ParticlesLit, /// /// Use this for URP Particles Simple Lit shader. /// ParticlesSimpleLit, /// /// Use this for URP Particles Simple Unlit shader. /// ParticlesUnlit, /// /// Use this for URP Baked Lit shader. /// BakedLit, /// /// Use this for URP SpeedTree 7 shader. /// SpeedTree7, /// /// Use this for URP SpeedTree 7 Billboard shader. /// SpeedTree7Billboard, /// /// Use this for URP SpeedTree 8 shader. /// SpeedTree8, /// /// Use this for URP SpeedTree 9 shader. /// SpeedTree9, // If you add a value here, also add it to ShaderID in Editor/ShaderUtils.cs /// /// Use this for URP Complex Lit shader. /// ComplexLit, } /// /// Various utility functions for shaders in URP. /// public static class ShaderUtils { static readonly string[] s_ShaderPaths = { "Universal Render Pipeline/Lit", "Universal Render Pipeline/Simple Lit", "Universal Render Pipeline/Unlit", "Universal Render Pipeline/Terrain/Lit", "Universal Render Pipeline/Particles/Lit", "Universal Render Pipeline/Particles/Simple Lit", "Universal Render Pipeline/Particles/Unlit", "Universal Render Pipeline/Baked Lit", "Universal Render Pipeline/Nature/SpeedTree7", "Universal Render Pipeline/Nature/SpeedTree7 Billboard", "Universal Render Pipeline/Nature/SpeedTree8_PBRLit", "Universal Render Pipeline/Complex Lit", }; /// /// Retrieves a shader path for the given URP Shader Path ID. /// /// The URP Shader Path ID. /// The path to the URP shader. public static string GetShaderPath(ShaderPathID id) { int index = (int)id; int arrayLength = s_ShaderPaths.Length; if (arrayLength > 0 && index >= 0 && index < arrayLength) return s_ShaderPaths[index]; Debug.LogError("Trying to access universal shader path out of bounds: (" + id + ": " + index + ")"); return ""; } /// /// Retrieves a URP Shader Path ID from a path given. /// /// The path to the shader. /// The URP Shader Path ID. public static ShaderPathID GetEnumFromPath(string path) { var index = Array.FindIndex(s_ShaderPaths, m => m == path); return (ShaderPathID)index; } /// /// Checks if a given shader is a URP shader or not. /// /// The shader. /// True or false if it's a URP shader or not. public static bool IsLWShader(Shader shader) { return s_ShaderPaths.Contains(shader.name); } #if UNITY_EDITOR private static float s_MostRecentValidDeltaTime = 0.0f; #endif // A delta time that does not get reset to zero when stepping paused Play Mode or using the FrameDebugger // (unless Time.timeScale is zero) // * Can be zero on the first frame after domain reload (if Time.deltaTime is also zero) // * The value depends on when it was last called // * In in practice it should not get stale as it's called at least once during a URP frame // * Currently only used when calculating '_LastTimeParameters' for shader upload // * Please validate your use case if trying to reuse this somewhere else (as it might not transfer) internal static float PersistentDeltaTime { get { #if UNITY_EDITOR float deltaTime = Time.deltaTime; // The only case I'm aware of when a deltaTime of 0 is valid is when Time.timeScale is 0 if (deltaTime > 0.0f || Time.timeScale == 0.0f) s_MostRecentValidDeltaTime = deltaTime; return s_MostRecentValidDeltaTime; #else return Time.deltaTime; #endif } } #if UNITY_EDITOR static readonly string[] s_ShaderGUIDs = { "933532a4fcc9baf4fa0491de14d08ed7", "8d2bb70cbf9db8d4da26e15b26e74248", "650dd9526735d5b46b79224bc6e94025", "69c1f799e772cb6438f56c23efccb782", "b7839dad95683814aa64166edc107ae2", "8516d7a69675844a7a0b7095af7c46af", "0406db5a14f94604a8c57ccfbc9f3b46", "0ca6dca7396eb48e5849247ffd444914", "0f4122b9a743b744abe2fb6a0a88868b", "5ec81c81908db34429b4f6ddecadd3bd", "9920c1f1781549a46ba081a2a15a16ec", "ee7e4c9a5f6364b688a332c67fc32cca", }; /// /// Returns a GUID for a URP shader from Shader Path ID. /// /// ID of shader path. /// GUID for the shader. public static string GetShaderGUID(ShaderPathID id) { int index = (int)id; int arrayLength = s_ShaderGUIDs.Length; if (arrayLength > 0 && index >= 0 && index < arrayLength) return s_ShaderGUIDs[index]; Debug.LogError("Trying to access universal shader GUID out of bounds: (" + id + ": " + index + ")"); return ""; } #endif } }