using Misaki.ShaderGUI; using UnityEditor; using UnityEngine; namespace Misaki.HdrpToon.Editor { internal class AmbientScope : MaterialUIScope { protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Ambient; protected override GUIContent Header => new("Ambient Settings"); private static class Properties { public static MaterialProperty indirectDiffuseMode; public static MaterialProperty indirectSpecularMode; public static MaterialProperty indirectDiffuseMatCapMap; public static MaterialProperty indirectDiffuseMatCapLod; public static MaterialProperty indirectDiffuseRampMap; public static MaterialProperty indirectDiffuseRampIndex; public static MaterialProperty indirectDiffuseRampPosition; public static MaterialProperty indirectDiffuseIntensity; public static MaterialProperty ssaoWeight; public static MaterialProperty ssgiWeight; public static MaterialProperty indirectSpecularMatCapMap; public static MaterialProperty indirectSpecularMatCapLod; public static MaterialProperty indirectReflectionIntensity; public static MaterialProperty ssrWeight; } private static class Styles { public static readonly GUIContent indirectDiffuseModeText = new("Indirect Diffuse Mode", "Specifies indirect diffuse mode."); public static readonly GUIContent indirectSpecularModeText = new("Indirect Specular Mode", "Specifies indirect specular mode."); public static readonly GUIContent indirectDiffuseMatCapMapText = new("MatCap Map", "The material capture map for indirect diffuse evaluation, with the additional setting for controlling the LOD offset when sampling the indirect diffuse material capture map."); public static readonly GUIContent indirectDiffuseRampMapText = new("Ramp Map", "The ramp map for indirect diffuse evaluation, with the additional setting for controlling the sampling index of the ramp map."); public static readonly GUIContent indirectDiffuseRampPositionText = new("Ramp Position", "The ramp position for indirect diffuse evaluation."); public static readonly GUIContent indirectDiffuseIntensityText = new("Intensity", "The indirect diffuse color is added to the material color according to the intensity value."); public static readonly GUIContent ssaoWeightText = new("SSAO Weight", "The weight of SSAO."); public static readonly GUIContent ssgiWeightText = new("SSGI Weight", "The weight of SSGI."); public static readonly GUIContent indirectSpecularMatCapMapText = new("MatCap Map", "The material capture map for indirect specular evaluation, with the additional setting for controlling the LOD offset when sampling the indirect specular material capture map."); public static readonly GUIContent indirectReflectionIntensityText = new("Intensity", "The indirect reflection color is added to the material color according to the intensity value."); public static readonly GUIContent ssrWeightText = new("SSR Weight", "SSR Weight"); } protected override void LoadMaterialProperties() { Properties.indirectDiffuseMode = FindProperty("_Indirect_Diffuse_Mode"); Properties.indirectSpecularMode = FindProperty("_Indirect_Specular_Mode"); Properties.indirectDiffuseMatCapMap = FindProperty("_IndirectDiffuseMatCapMap"); Properties.indirectDiffuseMatCapLod = FindProperty("_IndirectDiffuseMatCapLod"); Properties.indirectDiffuseRampMap = FindProperty("_IndirectDiffuseRampMap"); Properties.indirectDiffuseRampIndex = FindProperty("_IndirectDiffuseRampIndex"); Properties.indirectDiffuseRampPosition = FindProperty("_IndirectDiffuseRampPosition"); Properties.indirectDiffuseIntensity = FindProperty("_IndirectDiffuseIntensity"); Properties.ssaoWeight = FindProperty("_SSAOWeight"); Properties.ssgiWeight = FindProperty("_SSGIWeight"); Properties.indirectSpecularMatCapMap = FindProperty("_IndirectSpecularMatCapMap"); Properties.indirectSpecularMatCapLod = FindProperty("_IndirectSpecularMatCapLod"); Properties.indirectReflectionIntensity = FindProperty("_IndirectSpecularIntensity"); Properties.ssrWeight = FindProperty("_SSRWeight"); } private static void DrawIndirectDiffuseHeader() { EditorGUILayout.Space(); using var indentLevelScope = new EditorGUI.IndentLevelScope(-1); EditorGUILayout.LabelField("Indirect Diffuse", EditorStyles.boldLabel); } private void DrawIndirectDiffuseProperties() { EditorGUILayout.Space(); editor.ShaderProperty(Properties.indirectDiffuseIntensity, Styles.indirectDiffuseIntensityText); editor.ShaderProperty(Properties.ssaoWeight, Styles.ssaoWeightText); } private void DrawIndirectSpecularProperties() { EditorGUILayout.Space(); editor.ShaderProperty(Properties.indirectReflectionIntensity, Styles.indirectReflectionIntensityText); editor.ShaderProperty(Properties.ssrWeight, Styles.ssrWeightText); } private static void DrawIndirectSpecularHeader() { EditorGUILayout.Space(); using var indentLevelScope = new EditorGUI.IndentLevelScope(-1); EditorGUILayout.LabelField("Indirect Specular", EditorStyles.boldLabel); } protected override void DrawContent() { editor.ShaderProperty(Properties.indirectDiffuseMode, Styles.indirectDiffuseModeText); editor.ShaderProperty(Properties.indirectSpecularMode, Styles.indirectSpecularModeText); var indirectDiffuseMode = Properties.indirectDiffuseMode.GetEnumValue(); var indirectSpecularMode = Properties.indirectSpecularMode.GetEnumValue(); if (indirectDiffuseMode != IndirectDiffuseMode.Off) { DrawIndirectDiffuseHeader(); switch (indirectDiffuseMode) { case IndirectDiffuseMode.IBL: editor.ShaderProperty(Properties.ssgiWeight, Styles.ssgiWeightText); break; case IndirectDiffuseMode.Matcap: editor.TexturePropertySingleLine(Styles.indirectDiffuseMatCapMapText, Properties.indirectDiffuseMatCapMap, Properties.indirectDiffuseMatCapLod); break; case IndirectDiffuseMode.Ramp: editor.TexturePropertySingleLine(Styles.indirectDiffuseRampMapText, Properties.indirectDiffuseRampMap, Properties.indirectDiffuseRampIndex); editor.ShaderProperty(Properties.indirectDiffuseRampPosition, Styles.indirectDiffuseRampPositionText); break; default: break; } DrawIndirectDiffuseProperties(); } if (indirectSpecularMode != IndirectSpecularMode.Off) { DrawIndirectSpecularHeader(); switch (indirectSpecularMode) { case IndirectSpecularMode.IBL: break; case IndirectSpecularMode.Matcap: editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod); break; default: break; } DrawIndirectSpecularProperties(); } } } }