ShaderUtils.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Linq;
  3. namespace UnityEngine.Rendering.Universal
  4. {
  5. public enum ShaderPathID
  6. {
  7. Lit,
  8. SimpleLit,
  9. Unlit,
  10. TerrainLit,
  11. ParticlesLit,
  12. ParticlesSimpleLit,
  13. ParticlesUnlit,
  14. BakedLit,
  15. SpeedTree7,
  16. SpeedTree7Billboard,
  17. SpeedTree8,
  18. // If you add a value here, also add it to ShaderID in Editor/ShaderUtils.cs
  19. }
  20. public static class ShaderUtils
  21. {
  22. static readonly string[] s_ShaderPaths =
  23. {
  24. "Universal Render Pipeline/Lit",
  25. "Universal Render Pipeline/Simple Lit",
  26. "Universal Render Pipeline/Unlit",
  27. "Universal Render Pipeline/Terrain/Lit",
  28. "Universal Render Pipeline/Particles/Lit",
  29. "Universal Render Pipeline/Particles/Simple Lit",
  30. "Universal Render Pipeline/Particles/Unlit",
  31. "Universal Render Pipeline/Baked Lit",
  32. "Universal Render Pipeline/Nature/SpeedTree7",
  33. "Universal Render Pipeline/Nature/SpeedTree7 Billboard",
  34. "Universal Render Pipeline/Nature/SpeedTree8",
  35. };
  36. public static string GetShaderPath(ShaderPathID id)
  37. {
  38. int index = (int)id;
  39. int arrayLength = s_ShaderPaths.Length;
  40. if (arrayLength > 0 && index >= 0 && index < arrayLength)
  41. return s_ShaderPaths[index];
  42. Debug.LogError("Trying to access universal shader path out of bounds: (" + id + ": " + index + ")");
  43. return "";
  44. }
  45. public static ShaderPathID GetEnumFromPath(string path)
  46. {
  47. var index = Array.FindIndex(s_ShaderPaths, m => m == path);
  48. return (ShaderPathID)index;
  49. }
  50. public static bool IsLWShader(Shader shader)
  51. {
  52. return s_ShaderPaths.Contains(shader.name);
  53. }
  54. #if UNITY_EDITOR
  55. static readonly string[] s_ShaderGUIDs =
  56. {
  57. "933532a4fcc9baf4fa0491de14d08ed7",
  58. "8d2bb70cbf9db8d4da26e15b26e74248",
  59. "650dd9526735d5b46b79224bc6e94025",
  60. "69c1f799e772cb6438f56c23efccb782",
  61. "b7839dad95683814aa64166edc107ae2",
  62. "8516d7a69675844a7a0b7095af7c46af",
  63. "0406db5a14f94604a8c57ccfbc9f3b46",
  64. "0ca6dca7396eb48e5849247ffd444914",
  65. "0f4122b9a743b744abe2fb6a0a88868b",
  66. "5ec81c81908db34429b4f6ddecadd3bd",
  67. "99134b1f0c27d54469a840832a28fadf",
  68. };
  69. /// <summary>
  70. /// Returns shader from shader path id.
  71. /// </summary>
  72. /// <param name="id">Id of shader path.</param>
  73. /// <returns></returns>
  74. public static string GetShaderGUID(ShaderPathID id)
  75. {
  76. int index = (int)id;
  77. int arrayLength = s_ShaderGUIDs.Length;
  78. if (arrayLength > 0 && index >= 0 && index < arrayLength)
  79. return s_ShaderGUIDs[index];
  80. Debug.LogError("Trying to access universal shader GUID out of bounds: (" + id + ": " + index + ")");
  81. return "";
  82. }
  83. #endif
  84. }
  85. }