Updated OutlineScope;

Reorgnize shader code;
This commit is contained in:
2025-02-03 13:46:31 +09:00
parent 281dfbc4f0
commit 886432db7b
24 changed files with 275 additions and 293 deletions

View File

@@ -1,4 +1,5 @@
using Misaki.ShaderGUI;
using System.Linq;
using UnityEditor;
using UnityEditor.Rendering;
using UnityEngine;
@@ -32,42 +33,21 @@ namespace Misaki.HdrpToon.Editor
private static class Styles
{
public static readonly GUIContent NormalMapText =
new("Normal Map", "A texture that dictates the bumpiness of the material.");
public static readonly GUIContent NormalMapText = new("Normal Map", "A texture that dictates the bumpiness of the material.");
public static readonly GUIContent MaskMapText = new("Mask Map", "A texture that dictates the physical properties of the material. R channel for metallic, G channel for ambient occlusion, A channel for smoothness");
public static readonly GUIContent MetallicText = new("Metallic", "Specifies the metallic value of the material.");
public static readonly GUIContent MetallicRemap = new("Metallic Remap", "Remap the max and min value of metallic");
public static readonly GUIContent AORemap = new GUIContent("AO Remap", "Remap the max and min value of ambient occlusion");
public static readonly GUIContent RoughnessRemap = new GUIContent("Smoothness Remap", "Remap the max and min value of smoothness");
public static readonly GUIContent SmoothnessText = new("Smoothness", "Specifies the smoothness of the material.");
public static readonly GUIContent MaskMapText = new("Mask Map",
"A texture that dictates the physical properties of the material. R channel for metallic, G channel for ambient occlusion, A channel for smoothness");
public static readonly GUIContent AnisotropyMapText = new("Anisotropy Map", "Specifies the anisotropy map of the material.");
public static readonly GUIContent KKColorText = new("KK specular Color", "Specifies the color of KK specular.");
public static readonly GUIContent BSDFContributionText = new("BSDF Contribution", "BSDF smoothness contribution, 1 means KK Hair smoothness will fully contribute bsdf calculation");
public static readonly GUIContent MetallicText =
new("Metallic", "Specifies the metallicness of the material.");
public static readonly GUIContent MetallicRemap =
new("Metallic Remap", "Remap the max and min value of metallic");
public static readonly GUIContent AORemap =
new GUIContent("AO Remap", "Remap the max and min value of ambient occlusion");
public static readonly GUIContent RoughnessRemap =
new GUIContent("Smoothness Remap", "Remap the max and min value of smoothness");
public static readonly GUIContent SmoothnessText =
new("Smoothness", "Specifies the smoothness of the material.");
public static readonly GUIContent AnisotropyMapText =
new("Anisotropy Map", "Specifies the anisotropy map of the material.");
public static readonly GUIContent KKColorText = new("KK specular Color",
"Specifies the color of KK specular.");
public static readonly GUIContent BSDFContributionText = new("BSDF Contribution",
"BSDF smoothness contribution, 1 means KK Hair smoothness will fully contribute bsdf calculation");
public static readonly GUIContent SpecularColorMapText = new("Specular Color Map",
"Specifies the specular color map of the material.");
public static readonly GUIContent SpecRemap = new("Specular Remap",
"Feather and step value of Toon Specular");
public static readonly GUIContent SpecularColorMapText = new("Specular Color Map", "Specifies the specular color map of the material.");
public static readonly GUIContent SpecRemap = new("Specular Remap", "Feather and step value of Toon Specular");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.SurfaceInputs;
@@ -99,35 +79,18 @@ namespace Misaki.HdrpToon.Editor
protected override void DrawContent()
{
editor.KeywordTexturePropertySingleLine(Styles.NormalMapText, Properties.NormalMap, Properties.NormalMapScale);
//var materials = editor.GetMaterials().ToList();
//foreach (var material in materials)
//{
// material.SetKeyword(new LocalKeyword(material.shader, "_NORMAL_MAP"),
// Properties.NormalMap.textureValue != null);
//}
var pbrMode = SurfaceOptionsScope.GetPBRMode();
if (pbrMode != PBRMode.Off)
if (editor.GetMaterials().All(mat => mat.GetPBRMode() != PBRMode.Off))
{
if (editor.KeywordTexturePropertySingleLine(Styles.MaskMapText, Properties.MaskMap))
{
//foreach (var material in materials)
//{
// material.EnableKeyword(new LocalKeyword(material.shader, "_MASKMAP"));
//}
editor.MinMaxShaderProperty(Properties.MetallicRemapMin, Properties.MetallicRemapMax, 0, 1, Styles.MetallicRemap);
editor.MinMaxShaderProperty(Properties.AORemapMin, Properties.AORemapMax, 0, 1, Styles.AORemap);
editor.MinMaxShaderProperty(Properties.RoughnessRemapMin, Properties.RoughnessRemapMax, 0, 1, Styles.RoughnessRemap);
}
else
{
//foreach (var material in materials)
//{
// material.DisableKeyword(new LocalKeyword(material.shader, "_MASKMAP"));
//}
if (pbrMode != PBRMode.KKHair)
if (editor.GetMaterials().All(mat => mat.GetPBRMode() != PBRMode.KKHair))
{
editor.ShaderProperty(Properties.Metallic, Styles.MetallicText);
}
@@ -135,72 +98,24 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.Smoothness, Styles.SmoothnessText);
}
}
else
{
editor.SetKeyword("_MASKMAP", false);
editor.SetKeyword("_ANISOTROPY_MAP", false);
editor.SetKeyword("_SPECULAR_COLOR_MAP", false);
//foreach (var material in materials)
//{
// material.DisableKeyword(new LocalKeyword(material.shader, "_MASKMAP"));
// material.DisableKeyword(new LocalKeyword(material.shader, "_ANISOTROPY_MAP"));
// material.DisableKeyword(new LocalKeyword(material.shader, "_SPECULAR_COLOR_MAP"));
//}
if (editor.GetMaterials().All(mat => mat.GetPBRMode() == PBRMode.Anisotropy || mat.GetPBRMode() == PBRMode.KKHair))
{
editor.KeywordTexturePropertySingleLine(Styles.AnisotropyMapText, Properties.AnisotropyMap, Properties.Anisotropy);
if (editor.GetMaterials().All(mat => mat.GetPBRMode() == PBRMode.KKHair))
{
editor.ShaderProperty(Properties.KKColor, Styles.KKColorText);
editor.ShaderProperty(Properties.BSDFContribution, Styles.BSDFContributionText);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Anisotropy Map only ST");
editor.TextureScaleOffsetProperty(Properties.AnisotropyMap);
}
switch (pbrMode)
else if (editor.GetMaterials().All(mat => mat.GetPBRMode() == PBRMode.Toon))
{
case PBRMode.Anisotropy or PBRMode.KKHair:
{
editor.KeywordTexturePropertySingleLine(Styles.AnisotropyMapText, Properties.AnisotropyMap, Properties.Anisotropy);
if (pbrMode == PBRMode.KKHair)
{
editor.ShaderProperty(Properties.KKColor, Styles.KKColorText);
editor.ShaderProperty(Properties.BSDFContribution, Styles.BSDFContributionText);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Anisotropy Map only ST");
editor.TextureScaleOffsetProperty(Properties.AnisotropyMap);
//if (Properties.AnisotropyMap.textureValue == null)
//{
// foreach (var material in materials)
// {
// material.DisableKeyword(new LocalKeyword(material.shader, "_ANISOTROPY_MAP"));
// }
//}
//else
//{
// foreach (var material in materials)
// {
// material.EnableKeyword(new LocalKeyword(material.shader, "_ANISOTROPY_MAP"));
// }
//}
break;
}
case PBRMode.Toon:
{
editor.KeywordTexturePropertySingleLine(Styles.SpecularColorMapText, Properties.SpecularColorMap, Properties.SpecularColor);
//if (Properties.SpecularColorMap.textureValue == null)
//{
// foreach (var material in materials)
// {
// material.DisableKeyword(new LocalKeyword(material.shader, "_SPECULAR_COLOR_MAP"));
// }
//}
//else
//{
// foreach (var material in materials)
// {
// material.EnableKeyword(new LocalKeyword(material.shader, "_SPECULAR_COLOR_MAP"));
// }
//}
editor.MinMaxShaderProperty(Properties.SpecularFeather, Properties.SpecularStep, 0, 1, Styles.SpecRemap);
break;
}
editor.KeywordTexturePropertySingleLine(Styles.SpecularColorMapText, Properties.SpecularColorMap, Properties.SpecularColor);
editor.MinMaxShaderProperty(Properties.SpecularFeather, Properties.SpecularStep, 0, 1, Styles.SpecRemap);
}
}
}