ShaderSettings.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Rendering;
  4. namespace Siccity.GLTFUtility {
  5. /// <summary> Defines which shaders to use in the gltf import process </summary>
  6. [Serializable]
  7. public class ShaderSettings {
  8. [SerializeField] private Shader metallic;
  9. public Shader Metallic { get { return metallic != null ? metallic : GetDefaultMetallic(); } }
  10. [SerializeField] private Shader metallicBlend;
  11. public Shader MetallicBlend { get { return metallicBlend != null ? metallicBlend : GetDefaultMetallicBlend(); } }
  12. [SerializeField] private Shader specular;
  13. public Shader Specular { get { return specular != null ? specular : GetDefaultSpecular(); } }
  14. [SerializeField] private Shader specularBlend;
  15. public Shader SpecularBlend { get { return specularBlend != null ? specularBlend : GetDefaultSpecularBlend(); } }
  16. /// <summary> Caches default shaders so that async import won't try to search for them while on a separate thread </summary>
  17. public void CacheDefaultShaders() {
  18. metallic = Metallic;
  19. metallicBlend = MetallicBlend;
  20. specular = Specular;
  21. specularBlend = SpecularBlend;
  22. }
  23. public Shader GetDefaultMetallic() {
  24. #if UNITY_2019_1_OR_NEWER
  25. if (GraphicsSettings.renderPipelineAsset) return Shader.Find("GLTFUtility/URP/Standard (Metallic)");
  26. else
  27. #endif
  28. return Shader.Find("GLTFUtility/Standard (Metallic)");
  29. }
  30. public Shader GetDefaultMetallicBlend() {
  31. #if UNITY_2019_1_OR_NEWER
  32. if (GraphicsSettings.renderPipelineAsset) return Shader.Find("GLTFUtility/URP/Standard Transparent (Metallic)");
  33. else
  34. #endif
  35. return Shader.Find("GLTFUtility/Standard Transparent (Metallic)");
  36. }
  37. public Shader GetDefaultSpecular() {
  38. #if UNITY_2019_1_OR_NEWER
  39. if (GraphicsSettings.renderPipelineAsset) return Shader.Find("GLTFUtility/URP/Standard (Specular)");
  40. else
  41. #endif
  42. return Shader.Find("GLTFUtility/Standard (Specular)");
  43. }
  44. public Shader GetDefaultSpecularBlend() {
  45. #if UNITY_2019_1_OR_NEWER
  46. if (GraphicsSettings.renderPipelineAsset) return Shader.Find("GLTFUtility/URP/Standard Transparent (Specular)");
  47. else
  48. #endif
  49. return Shader.Find("GLTFUtility/Standard Transparent (Specular)");
  50. }
  51. }
  52. }