using System; using UnityEditor; namespace UnityEngine.Rendering.Universal { internal enum DefaultMaterialType { Default, Particle, Terrain, Sprite, SpriteMask, Decal } public partial class UniversalRenderPipelineAsset { #region Materials Material GetMaterial(DefaultMaterialType materialType) { #if UNITY_EDITOR Material material = null; if (scriptableRendererData != null) material = scriptableRendererData.GetDefaultMaterial(materialType); if (material == null) { if (GraphicsSettings.TryGetRenderPipelineSettings(out var defaultMaterials)) { return materialType switch { DefaultMaterialType.Default => defaultMaterials.defaultMaterial, DefaultMaterialType.Particle => defaultMaterials.defaultParticleUnlitMaterial, DefaultMaterialType.Terrain => defaultMaterials.defaultTerrainLitMaterial, DefaultMaterialType.Decal => defaultMaterials.defaultDecalMaterial, _ => null }; } } return material; #else return null; #endif } /// /// Returns the default Material. /// /// Returns the default Material. public override Material defaultMaterial => GetMaterial(DefaultMaterialType.Default); /// /// Returns the default particle Material. /// /// Returns the default particle Material. public override Material defaultParticleMaterial => GetMaterial(DefaultMaterialType.Particle); /// /// Returns the default line Material. /// /// Returns the default line Material. public override Material defaultLineMaterial => GetMaterial(DefaultMaterialType.Particle); /// /// Returns the default terrain Material. /// /// Returns the default terrain Material. public override Material defaultTerrainMaterial => GetMaterial(DefaultMaterialType.Terrain); /// /// Returns the default material for the 2D renderer. /// /// Returns the material containing the default lit and unlit shader passes for sprites in the 2D renderer. public override Material default2DMaterial => GetMaterial(DefaultMaterialType.Sprite); /// /// Returns the default sprite mask material for the 2D renderer. /// /// Returns the material containing the default shader pass for sprite mask in the 2D renderer. public override Material default2DMaskMaterial => GetMaterial(DefaultMaterialType.SpriteMask); /// /// Returns the Material that Unity uses to render decals. /// /// Returns the Material containing the Unity decal shader. public Material decalMaterial => GetMaterial(DefaultMaterialType.Decal); #endregion #region Shaders #if UNITY_EDITOR private UniversalRenderPipelineEditorShaders defaultShaders => GraphicsSettings.GetRenderPipelineSettings(); #endif Shader m_DefaultShader; /// /// 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. /// /// Returns the default shader for the specified renderer. public override Shader defaultShader { get { #if UNITY_EDITOR // TODO: When importing project, AssetPreviewUpdater:CreatePreviewForAsset will be called multiple time // which in turns calls this property to get the default shader. // The property should never return null as, when null, it loads the data using AssetDatabase.LoadAssetAtPath. // However it seems there's an issue that LoadAssetAtPath will not load the asset in some cases. so adding the null check // here to fix template tests. if (scriptableRendererData != null) { Shader defaultShader = scriptableRendererData.GetDefaultShader(); 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) m_DefaultShader = Shader.Find(ShaderUtils.GetShaderPath(ShaderPathID.Lit)); return m_DefaultShader; } } #if UNITY_EDITOR #region Autodesk /// /// Returns the Autodesk Interactive shader that this asset uses. /// /// Returns the Autodesk Interactive shader that this asset uses. public override Shader autodeskInteractiveShader => defaultShaders?.autodeskInteractiveShader; /// /// Returns the Autodesk Interactive transparent shader that this asset uses. /// /// Returns the Autodesk Interactive transparent shader that this asset uses. public override Shader autodeskInteractiveTransparentShader => defaultShaders?.autodeskInteractiveTransparentShader; /// /// Returns the Autodesk Interactive mask shader that this asset uses. /// /// Returns the Autodesk Interactive mask shader that this asset uses public override Shader autodeskInteractiveMaskedShader => defaultShaders?.autodeskInteractiveMaskedShader; #endregion #region Terrain /// /// Returns the terrain detail lit shader that this asset uses. /// /// Returns the terrain detail lit shader that this asset uses. public override Shader terrainDetailLitShader => defaultShaders?.terrainDetailLitShader; /// /// Returns the terrain detail grass shader that this asset uses. /// /// Returns the terrain detail grass shader that this asset uses. public override Shader terrainDetailGrassShader => defaultShaders?.terrainDetailGrassShader; /// /// Returns the terrain detail grass billboard shader that this asset uses. /// /// Returns the terrain detail grass billboard shader that this asset uses. public override Shader terrainDetailGrassBillboardShader => defaultShaders?.terrainDetailGrassBillboardShader; #endregion #region SpeedTree /// /// Returns the default SpeedTree7 shader that this asset uses. /// /// Returns the default SpeedTree7 shader that this asset uses. public override Shader defaultSpeedTree7Shader => defaultShaders?.defaultSpeedTree7Shader; /// /// Returns the default SpeedTree8 shader that this asset uses. /// /// Returns the default SpeedTree8 shader that this asset uses. public override Shader defaultSpeedTree8Shader => defaultShaders?.defaultSpeedTree8Shader; /// /// Returns the default SpeedTree9 shader that this asset uses. /// /// Returns the default SpeedTree9 shader that this asset uses. public override Shader defaultSpeedTree9Shader => defaultShaders?.defaultSpeedTree9Shader; #endregion #endif #endregion } }