Improve AmbientScope and OutlineScope

This commit is contained in:
2025-02-02 17:04:05 +09:00
parent ecd0cfdb9f
commit 281dfbc4f0
11 changed files with 200 additions and 143 deletions

View File

@@ -6,106 +6,110 @@ namespace Misaki.HdrpToon.Editor
{
public class AmbientScope : MaterialUIScope<ShaderGUIExpandable>
{
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.AmbientMode;
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Ambient;
protected override GUIContent Header => new("Ambient Settings");
private static class Properties
{
public static MaterialProperty IndirectDiffuseMode;
public static MaterialProperty IndirectDiffuseIntensity;
public static MaterialProperty IndirectSpecularMode;
public static MaterialProperty IndirectReflectionIntensity;
public static MaterialProperty EnableSSAO;
public static MaterialProperty SSAOFactor;
public static MaterialProperty EnableSSGI;
public static MaterialProperty SSGIFactor;
public static MaterialProperty EnableSSR;
public static MaterialProperty indirectDiffuseMode;
public static MaterialProperty indirectSpecularMode;
public static MaterialProperty indirectDiffuseMatCapMap;
public static MaterialProperty indirectDiffuseMatCapLod;
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 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 IndirectDiffuseIntensityText =
new("Indirect Diffuse Intensity",
"The Environment Light color is added to the material color according to the GI Intensity value.");
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 IndirectSpecularModeText =
new("Indirect Specular Mode", "Specifies indirect specular mode.");
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 IndirectReflectionIntensityText =
new("Indirect Reflection Intensity",
"The Environment Light color is added to the material color according to the GI Intensity value.");
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 EnableSSAOText = new("Enable SSAO", "Enable SSAO.");
public static readonly GUIContent SSAOFactorText = new("SSAO Factor", "The weight of SSAO.");
public static readonly GUIContent EnableSSGIText = new("Enable SSGI", "Enable SSGI.");
public static readonly GUIContent SSGIFactorText = new("SSGI Factor", "The weight of SSGI.");
public static readonly GUIContent EnableSSRText = new("Enable SSR", "Enable SSR.");
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");
}
private readonly string[] _indirectDiffuseModeDefines =
{ "_INDIRECT_DIFFUSE_OFF", "_INDIRECT_DIFFUSE_IBL", "_INDIRECT_DIFFUSE_MATCAP", "_INDIRECT_DIFFUSE_RAMP" };
private readonly string[] _indirectSpecularModeDefines =
{ "_INDIRECT_SPECULAR_OFF", "_INDIRECT_SPECULAR_IBL", "_INDIRECT_SPECULAR_MATCAP" };
public override void LoadMaterialProperties()
{
Properties.IndirectDiffuseMode = FindProperty("_Indirect_Diffuse_Mode");
Properties.IndirectDiffuseIntensity = FindProperty("_ID_Intensity");
Properties.IndirectSpecularMode = FindProperty("_Indirect_Specular_Mode");
Properties.IndirectReflectionIntensity = FindProperty("_IR_Intensity");
Properties.EnableSSAO = FindProperty("_ReceivesSSAO");
Properties.SSAOFactor = FindProperty("_AO_Factor");
Properties.EnableSSGI = FindProperty("_ReceivesSSGI");
Properties.SSGIFactor = FindProperty("_GI_Factor");
Properties.EnableSSR = FindProperty("_ReceivesSSR");
Properties.indirectDiffuseMode = FindProperty("_Indirect_Diffuse_Mode");
Properties.indirectSpecularMode = FindProperty("_Indirect_Specular_Mode");
Properties.indirectDiffuseMatCapMap = FindProperty("_IndirectDiffuseMatCapMap");
Properties.indirectDiffuseMatCapLod = FindProperty("_IndirectDiffuseMatCapLod");
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");
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.IndirectDiffuseMode, Styles.IndirectDiffuseModeText);
for (int i = 0; i < _indirectDiffuseModeDefines.Length; i++)
{
editor.SetKeyword(_indirectDiffuseModeDefines[i], Properties.IndirectDiffuseMode.intValue == i);
}
editor.ShaderProperty(Properties.indirectDiffuseMode, Styles.indirectDiffuseModeText);
editor.ShaderProperty(Properties.indirectSpecularMode, Styles.indirectSpecularModeText);
if (Properties.IndirectDiffuseMode.intValue != 0)
var indirectDiffuseMode = Properties.indirectDiffuseMode.GetEnumValue<IndirectDiffuseMode>();
var indirectSpecularMode = Properties.indirectSpecularMode.GetEnumValue<IndirectSpecularMode>();
if (indirectDiffuseMode != IndirectDiffuseMode.Off)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Indirect Diffuse", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.IndirectDiffuseIntensity, Styles.IndirectDiffuseIntensityText);
editor.ShaderProperty(Properties.EnableSSAO, Styles.EnableSSAOText);
if (Properties.EnableSSAO.floatValue > 0)
if (indirectDiffuseMode == IndirectDiffuseMode.Matcap)
{
EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.SSAOFactor, Styles.SSAOFactorText);
EditorGUI.indentLevel--;
editor.TexturePropertySingleLine(Styles.indirectDiffuseMatCapMapText, Properties.indirectDiffuseMatCapMap, Properties.indirectDiffuseMatCapLod);
}
editor.ShaderProperty(Properties.EnableSSGI, Styles.EnableSSGIText);
if (Properties.EnableSSGI.floatValue > 0)
editor.ShaderProperty(Properties.indirectDiffuseIntensity, Styles.indirectDiffuseIntensityText);
editor.ShaderProperty(Properties.ssaoWeight, Styles.ssaoWeightText);
if (indirectDiffuseMode == IndirectDiffuseMode.IBL)
{
EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.SSGIFactor, Styles.SSGIFactorText);
EditorGUI.indentLevel--;
editor.ShaderProperty(Properties.ssgiWeight, Styles.ssgiWeightText);
}
EditorGUI.indentLevel--;
}
editor.ShaderProperty(Properties.IndirectSpecularMode, Styles.IndirectSpecularModeText);
for (int i = 0; i < _indirectSpecularModeDefines.Length; i++)
if (indirectSpecularMode != (int)IndirectSpecularMode.Off)
{
editor.SetKeyword(_indirectSpecularModeDefines[i], Properties.IndirectSpecularMode.intValue == i);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Indirect Specular", EditorStyles.boldLabel);
if (Properties.IndirectSpecularMode.intValue != 0)
{
EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.IndirectReflectionIntensity, Styles.IndirectReflectionIntensityText);
editor.ShaderProperty(Properties.EnableSSR, Styles.EnableSSRText);
if (indirectSpecularMode == IndirectSpecularMode.Matcap)
{
editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod);
}
editor.ShaderProperty(Properties.indirectReflectionIntensity, Styles.indirectReflectionIntensityText);
editor.ShaderProperty(Properties.ssrWeight, Styles.ssrWeightText);
EditorGUI.indentLevel--;
}
}