Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UniversalRenderPipelineAsset.DefaultResources.cs 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using UnityEditor;
  3. namespace UnityEngine.Rendering.Universal
  4. {
  5. internal enum DefaultMaterialType
  6. {
  7. Default,
  8. Particle,
  9. Terrain,
  10. Sprite,
  11. SpriteMask,
  12. Decal
  13. }
  14. public partial class UniversalRenderPipelineAsset
  15. {
  16. #region Materials
  17. Material GetMaterial(DefaultMaterialType materialType)
  18. {
  19. #if UNITY_EDITOR
  20. Material material = null;
  21. if (scriptableRendererData != null)
  22. material = scriptableRendererData.GetDefaultMaterial(materialType);
  23. if (material == null)
  24. {
  25. if (GraphicsSettings.TryGetRenderPipelineSettings<UniversalRenderPipelineEditorMaterials>(out var defaultMaterials))
  26. {
  27. return materialType switch
  28. {
  29. DefaultMaterialType.Default => defaultMaterials.defaultMaterial,
  30. DefaultMaterialType.Particle => defaultMaterials.defaultParticleUnlitMaterial,
  31. DefaultMaterialType.Terrain => defaultMaterials.defaultTerrainLitMaterial,
  32. DefaultMaterialType.Decal => defaultMaterials.defaultDecalMaterial,
  33. _ => null
  34. };
  35. }
  36. }
  37. return material;
  38. #else
  39. return null;
  40. #endif
  41. }
  42. /// <summary>
  43. /// Returns the default Material.
  44. /// </summary>
  45. /// <returns>Returns the default Material.</returns>
  46. public override Material defaultMaterial => GetMaterial(DefaultMaterialType.Default);
  47. /// <summary>
  48. /// Returns the default particle Material.
  49. /// </summary>
  50. /// <returns>Returns the default particle Material.</returns>
  51. public override Material defaultParticleMaterial => GetMaterial(DefaultMaterialType.Particle);
  52. /// <summary>
  53. /// Returns the default line Material.
  54. /// </summary>
  55. /// <returns>Returns the default line Material.</returns>
  56. public override Material defaultLineMaterial => GetMaterial(DefaultMaterialType.Particle);
  57. /// <summary>
  58. /// Returns the default terrain Material.
  59. /// </summary>
  60. /// <returns>Returns the default terrain Material.</returns>
  61. public override Material defaultTerrainMaterial => GetMaterial(DefaultMaterialType.Terrain);
  62. /// <summary>
  63. /// Returns the default material for the 2D renderer.
  64. /// </summary>
  65. /// <returns>Returns the material containing the default lit and unlit shader passes for sprites in the 2D renderer.</returns>
  66. public override Material default2DMaterial => GetMaterial(DefaultMaterialType.Sprite);
  67. /// <summary>
  68. /// Returns the default sprite mask material for the 2D renderer.
  69. /// </summary>
  70. /// <returns>Returns the material containing the default shader pass for sprite mask in the 2D renderer.</returns>
  71. public override Material default2DMaskMaterial => GetMaterial(DefaultMaterialType.SpriteMask);
  72. /// <summary>
  73. /// Returns the Material that Unity uses to render decals.
  74. /// </summary>
  75. /// <returns>Returns the Material containing the Unity decal shader.</returns>
  76. public Material decalMaterial => GetMaterial(DefaultMaterialType.Decal);
  77. #endregion
  78. #region Shaders
  79. #if UNITY_EDITOR
  80. private UniversalRenderPipelineEditorShaders defaultShaders =>
  81. GraphicsSettings.GetRenderPipelineSettings<UniversalRenderPipelineEditorShaders>();
  82. #endif
  83. Shader m_DefaultShader;
  84. /// <summary>
  85. /// Returns the default shader for the specified renderer. When creating new objects in the editor, the materials of those objects will use the selected default shader.
  86. /// </summary>
  87. /// <returns>Returns the default shader for the specified renderer.</returns>
  88. public override Shader defaultShader
  89. {
  90. get
  91. {
  92. #if UNITY_EDITOR
  93. // TODO: When importing project, AssetPreviewUpdater:CreatePreviewForAsset will be called multiple time
  94. // which in turns calls this property to get the default shader.
  95. // The property should never return null as, when null, it loads the data using AssetDatabase.LoadAssetAtPath.
  96. // However it seems there's an issue that LoadAssetAtPath will not load the asset in some cases. so adding the null check
  97. // here to fix template tests.
  98. if (scriptableRendererData != null)
  99. {
  100. Shader defaultShader = scriptableRendererData.GetDefaultShader();
  101. if (defaultShader != null)
  102. return defaultShader;
  103. }
  104. if (m_DefaultShader == null)
  105. {
  106. string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit));
  107. m_DefaultShader = AssetDatabase.LoadAssetAtPath<Shader>(path);
  108. }
  109. #endif
  110. if (m_DefaultShader == null)
  111. m_DefaultShader = Shader.Find(ShaderUtils.GetShaderPath(ShaderPathID.Lit));
  112. return m_DefaultShader;
  113. }
  114. }
  115. #if UNITY_EDITOR
  116. #region Autodesk
  117. /// <summary>
  118. /// Returns the Autodesk Interactive shader that this asset uses.
  119. /// </summary>
  120. /// <returns>Returns the Autodesk Interactive shader that this asset uses.</returns>
  121. public override Shader autodeskInteractiveShader => defaultShaders?.autodeskInteractiveShader;
  122. /// <summary>
  123. /// Returns the Autodesk Interactive transparent shader that this asset uses.
  124. /// </summary>
  125. /// <returns>Returns the Autodesk Interactive transparent shader that this asset uses.</returns>
  126. public override Shader autodeskInteractiveTransparentShader => defaultShaders?.autodeskInteractiveTransparentShader;
  127. /// <summary>
  128. /// Returns the Autodesk Interactive mask shader that this asset uses.
  129. /// </summary>
  130. /// <returns>Returns the Autodesk Interactive mask shader that this asset uses</returns>
  131. public override Shader autodeskInteractiveMaskedShader => defaultShaders?.autodeskInteractiveMaskedShader;
  132. #endregion
  133. #region Terrain
  134. /// <summary>
  135. /// Returns the terrain detail lit shader that this asset uses.
  136. /// </summary>
  137. /// <returns>Returns the terrain detail lit shader that this asset uses.</returns>
  138. public override Shader terrainDetailLitShader => defaultShaders?.terrainDetailLitShader;
  139. /// <summary>
  140. /// Returns the terrain detail grass shader that this asset uses.
  141. /// </summary>
  142. /// <returns>Returns the terrain detail grass shader that this asset uses.</returns>
  143. public override Shader terrainDetailGrassShader => defaultShaders?.terrainDetailGrassShader;
  144. /// <summary>
  145. /// Returns the terrain detail grass billboard shader that this asset uses.
  146. /// </summary>
  147. /// <returns>Returns the terrain detail grass billboard shader that this asset uses.</returns>
  148. public override Shader terrainDetailGrassBillboardShader => defaultShaders?.terrainDetailGrassBillboardShader;
  149. #endregion
  150. #region SpeedTree
  151. /// <summary>
  152. /// Returns the default SpeedTree7 shader that this asset uses.
  153. /// </summary>
  154. /// <returns>Returns the default SpeedTree7 shader that this asset uses.</returns>
  155. public override Shader defaultSpeedTree7Shader => defaultShaders?.defaultSpeedTree7Shader;
  156. /// <summary>
  157. /// Returns the default SpeedTree8 shader that this asset uses.
  158. /// </summary>
  159. /// <returns>Returns the default SpeedTree8 shader that this asset uses.</returns>
  160. public override Shader defaultSpeedTree8Shader => defaultShaders?.defaultSpeedTree8Shader;
  161. /// <summary>
  162. /// Returns the default SpeedTree9 shader that this asset uses.
  163. /// </summary>
  164. /// <returns>Returns the default SpeedTree9 shader that this asset uses.</returns>
  165. public override Shader defaultSpeedTree9Shader => defaultShaders?.defaultSpeedTree9Shader;
  166. #endregion
  167. #endif
  168. #endregion
  169. }
  170. }