diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/MaterialHeaderScope.cs b/com.unity.render-pipelines.high-definition/Editor/Material/MaterialHeaderScope.cs index d30f3f851a8..edb6b3fd2b8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/MaterialHeaderScope.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/MaterialHeaderScope.cs @@ -26,6 +26,15 @@ internal struct MaterialHeaderScope : IDisposable int oldIndentLevel; #endif + /// + /// Creates a material header scope to display the foldout in the material UI. + /// + /// Title of the header. + /// Bit index which specifies the state of the header (whether it is open or collapsed) inside Editor Prefs. + /// The current material editor. + /// Set this to true to make the block include space at the bottom of its UI. Set to false to not include any space. + /// Specify a color to display a dot, like in the layered UI. + /// Set to true to make this into a sub-header. This affects the style of the header. Set to false to make this use the standard style. public MaterialHeaderScope(string title, uint bitExpanded, MaterialEditor materialEditor, bool spaceAtEnd = true, Color colorDot = default(Color), bool subHeader = false) { bool beforeExpended = materialEditor.GetExpandedAreas(bitExpanded); @@ -66,6 +75,7 @@ internal struct MaterialHeaderScope : IDisposable ++EditorGUI.indentLevel; } + /// Disposes of the material scope header and cleans up any resources it used. void IDisposable.Dispose() { if (expanded) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/HDShaderGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/HDShaderGUI.cs index fa9564aad1c..166412d8318 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/HDShaderGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/HDShaderGUI.cs @@ -17,14 +17,25 @@ namespace UnityEditor.Rendering.HighDefinition // of the material you must use Material UI Blocks, examples of doing so can be found in the classes UnlitGUI, // LitGUI or LayeredLitGUI. - abstract class HDShaderGUI : ShaderGUI + /// + /// Use this class to build your custom Shader GUI for HDRP. + /// You can use a class that inherits from HDShaderGUI in the Shader Graph Custom EditorGUI field. + /// + internal abstract class HDShaderGUI : ShaderGUI { - protected bool m_FirstFrame = true; + internal protected bool m_FirstFrame = true; // The following set of functions are call by the ShaderGraph // It will allow to display our common parameters + setup keyword correctly for them + protected abstract void SetupMaterialKeywordsAndPassInternal(Material material); + /// + /// Unity calls this function when you assign a new shader to the material. + /// + /// The current material. + /// The shader the material currently uses. + /// The new shader to assign to the material. public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { base.AssignNewShaderToMaterial(material, oldShader, newShader); @@ -32,6 +43,11 @@ public override void AssignNewShaderToMaterial(Material material, Shader oldShad SetupMaterialKeywordsAndPassInternal(material); } + /// + /// Sets up the keywords and passes for the material. You must call this function after you change a property on a material to ensure it's validity. + /// + /// GUI.changed is the usual value for this parameter. If this value is false, the function just exits. + /// The materials to perform the setup on. protected void ApplyKeywordsAndPassesIfNeeded(bool changed, Material[] materials) { // !!! HACK !!! @@ -49,6 +65,9 @@ protected void ApplyKeywordsAndPassesIfNeeded(bool changed, Material[] materials } } + /// + /// Unity calls this function when it displays the GUI. This method is sealed so you cannot override it. To implement your custom GUI, use OnMaterialGUI instead. + /// public sealed override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { if (!(RenderPipelineManager.currentPipeline is HDRenderPipeline)) @@ -61,12 +80,21 @@ public sealed override void OnGUI(MaterialEditor materialEditor, MaterialPropert } } + /// + /// Implement your custom GUI in this function. To display a UI similar to HDRP shaders, use a MaterialUIBlock. + /// + /// The current material editor. + /// The list of properties the material has. protected abstract void OnMaterialGUI(MaterialEditor materialEditor, MaterialProperty[] props); readonly static string[] floatPropertiesToSynchronize = { kUseSplitLighting }; + /// + /// Synchronize a set of properties that Unity requires for Shader Graph materials to work correctly. This function is for Shader Graph only. + /// + /// The target material. protected static void SynchronizeShaderGraphProperties(Material material) { var defaultProperties = new Material(material.shader); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs index ea185d8bbaf..96a23f8c2ec 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/LightingShaderGraphGUI.cs @@ -9,7 +9,7 @@ namespace UnityEditor.Rendering.HighDefinition /// /// Common GUI for Lit ShaderGraphs /// - class LightingShaderGraphGUI : HDShaderGUI + internal class LightingShaderGraphGUI : HDShaderGUI { // For surface option shader graph we only want all unlit features but alpha clip and back then front rendering const SurfaceOptionUIBlock.Features surfaceOptionFeatures = SurfaceOptionUIBlock.Features.Lit @@ -22,6 +22,11 @@ class LightingShaderGraphGUI : HDShaderGUI new AdvancedOptionsUIBlock(MaterialUIBlock.Expandable.Advance, ~AdvancedOptionsUIBlock.Features.SpecularOcclusion) }; + /// + /// Implement your custom GUI in this function. To display a UI similar to HDRP shaders, use a MaterialUIBlock. + /// + /// The current material editor. + /// The list of properties the material has. protected override void OnMaterialGUI(MaterialEditor materialEditor, MaterialProperty[] props) { using (var changed = new EditorGUI.ChangeCheckScope()) @@ -31,6 +36,10 @@ protected override void OnMaterialGUI(MaterialEditor materialEditor, MaterialPro } } + /// + /// Sets up the keywords and passes for a Lit Shader Graph material. + /// + /// The target material. public static void SetupMaterialKeywordsAndPass(Material material) { SynchronizeShaderGraphProperties(material); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/MaterialUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/MaterialUIBlock.cs index 54469704fc1..b4b0b60656f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/MaterialUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/MaterialUIBlock.cs @@ -6,16 +6,23 @@ namespace UnityEditor.Rendering.HighDefinition { + /// + /// Base implementation of a material GUI block to be disabled in the material inspector. + /// abstract class MaterialUIBlock { + /// The current material editor. protected MaterialEditor materialEditor; + /// The list of selected materials to edit. protected Material[] materials; + /// The list of available properties in the selected materials. protected MaterialProperty[] properties; + /// Parent of the UI block. protected MaterialUIBlockList parent; [Flags] - public enum Expandable : uint + internal enum Expandable : uint { // Standard Base = 1<<0, @@ -52,7 +59,7 @@ public enum Expandable : uint LayeringOption3 = 1 << 30 } - public void Initialize(MaterialEditor materialEditor, MaterialProperty[] properties, MaterialUIBlockList parent) + internal void Initialize(MaterialEditor materialEditor, MaterialProperty[] properties, MaterialUIBlockList parent) { this.materialEditor = materialEditor; this.parent = parent; @@ -62,12 +69,18 @@ public void Initialize(MaterialEditor materialEditor, MaterialProperty[] materialEditor.InitExpandableState(); } - public void UpdateMaterialProperties(MaterialProperty[] properties) + internal void UpdateMaterialProperties(MaterialProperty[] properties) { this.properties = properties; LoadMaterialProperties(); } + /// + /// Find a material property in the list of available properties. + /// + /// Name of the property. + /// Specifies whether the property is mandatory for your Inspector. + /// Returns the material property if it exists. Returns null otherwise. protected MaterialProperty FindProperty(string propertyName, bool isMandatory = false) { // ShaderGUI.FindProperty is a protected member of ShaderGUI so we can't call it here: @@ -83,6 +96,13 @@ protected MaterialProperty FindProperty(string propertyName, bool isMandatory = return null; } + /// + /// Find a material property with layering option + /// + /// Name of the property. + /// Number of layers of the shader. + /// Specifies whether the property is mandatory for your Inspector. + /// Returns the material property if it exists. Returns null otherwise. protected MaterialProperty[] FindPropertyLayered(string propertyName, int layerCount, bool isMandatory = false) { MaterialProperty[] properties = new MaterialProperty[layerCount]; @@ -99,7 +119,14 @@ protected MaterialProperty[] FindPropertyLayered(string propertyName, int layerC return properties; } + /// + /// Use this function to load the material properties you need in your block. + /// public abstract void LoadMaterialProperties(); + + /// + /// Renders the properties in your block. + /// public abstract void OnGUI(); } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitGUI.cs index b416dccea53..c8d2b76f70f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitGUI.cs @@ -10,7 +10,7 @@ namespace UnityEditor.Rendering.HighDefinition /// /// GUI for HDRP Unlit shader graphs /// - class HDUnlitGUI : HDShaderGUI + internal class HDUnlitGUI : HDShaderGUI { const SurfaceOptionUIBlock.Features surfaceOptionFeatures = SurfaceOptionUIBlock.Features.Unlit; @@ -21,6 +21,11 @@ class HDUnlitGUI : HDShaderGUI new AdvancedOptionsUIBlock(MaterialUIBlock.Expandable.Advance, ~AdvancedOptionsUIBlock.Features.SpecularOcclusion) }; + /// + /// Implement your custom GUI in this function. To display a UI similar to HDRP shaders, use a MaterialUIBlock. + /// + /// The current material editor. + /// The list of properties the material has. protected override void OnMaterialGUI(MaterialEditor materialEditor, MaterialProperty[] props) { using (var changed = new EditorGUI.ChangeCheckScope()) @@ -30,6 +35,10 @@ protected override void OnMaterialGUI(MaterialEditor materialEditor, MaterialPro } } + /// + /// Sets up the keywords and passes for an Unlit Shader Graph material. + /// + /// The target material. public static void SetupMaterialKeywordsAndPass(Material material) { SynchronizeShaderGraphProperties(material);