Shader code cleanupand bug fix.

This commit is contained in:
2025-02-17 22:15:27 +09:00
parent eacbbc9b8b
commit 4ce84572d0
20 changed files with 375 additions and 467 deletions

View File

@@ -1,20 +0,0 @@
namespace Misaki.HdrpToon.Editor
{
internal static class UTSShaderGUIHelpers
{
public static ShadingMode GetShadingMode(this UTSShaderGUI shaderGUI)
{
return (ShadingMode)shaderGUI.GetUIScope<SurfaceOptionsScope>().FindProperty("_Shading_Mode").floatValue;
}
public static PBRMode GetPBRMode(this UTSShaderGUI shaderGUI)
{
return (PBRMode)shaderGUI.GetUIScope<SurfaceOptionsScope>().FindProperty("_PBR_Mode").floatValue;
}
public static bool HasFeature(this UTSShaderGUI shaderGUI, SurfaceFeature feature)
{
return ((SurfaceFeature)shaderGUI.GetUIScope<SurfaceOptionsScope>().FindProperty("_Surface_Features").floatValue & feature) != 0;
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 4aa9e028e20a2014ab0e2a3ea6541f0e

View File

@@ -69,23 +69,24 @@ namespace Misaki.HdrpToon.Editor
{
editor.ShaderProperty(Properties.outlineState, Styles.outlineStateText);
using var disabledScope = new EditorGUI.DisabledScope(!Properties.outlineState.GetBooleanValue());
EditorGUILayout.Space();
editor.TexturePropertySingleLine(Styles.outlineWidthText, Properties.outlineWidthMap, Properties.outlineWidth);
editor.TexturePropertySingleLine(Styles.outlineColorText, Properties.outlineColorMap, Properties.outlineColor);
editor.ShaderProperty(Properties.albedoAffectOutline, Styles.albedoAffectOutlineText);
editor.ShaderProperty(Properties.skyColorAffectOutline, Styles.skyColorAffectOutlineText);
if (Properties.skyColorAffectOutline.GetBooleanValue())
if (Properties.outlineState.GetBooleanValue())
{
using var skyColorIndentLevelScope = new EditorGUI.IndentLevelScope();
editor.ShaderProperty(Properties.skyColorIntensity, Styles.skyColorIntensityText);
}
EditorGUILayout.Space();
editor.TexturePropertySingleLine(Styles.outlineWidthText, Properties.outlineWidthMap, Properties.outlineWidth);
editor.TexturePropertySingleLine(Styles.outlineColorText, Properties.outlineColorMap, Properties.outlineColor);
editor.ShaderProperty(Properties.albedoAffectOutline, Styles.albedoAffectOutlineText);
editor.ShaderProperty(Properties.skyColorAffectOutline, Styles.skyColorAffectOutlineText);
if (Properties.skyColorAffectOutline.GetBooleanValue())
{
using var skyColorIndentLevelScope = new EditorGUI.IndentLevelScope();
editor.ShaderProperty(Properties.skyColorIntensity, Styles.skyColorIntensityText);
}
EditorGUILayout.Space();
editor.ShaderProperty(Properties.fadeIn, Styles.fadeInText);
editor.ShaderProperty(Properties.fadeOut, Styles.fadeOutText);
editor.ShaderProperty(Properties.useSmoothedNormal, Styles.useSmoothedNormalText);
EditorGUILayout.Space();
editor.ShaderProperty(Properties.fadeIn, Styles.fadeInText);
editor.ShaderProperty(Properties.fadeOut, Styles.fadeOutText);
editor.ShaderProperty(Properties.useSmoothedNormal, Styles.useSmoothedNormalText);
}
}
}
}

View File

@@ -3,6 +3,8 @@ using System.Linq;
using UnityEditor;
using UnityEngine;
using static Misaki.HdrpToon.UtsShaderPropertyName.RimLight;
namespace Misaki.HdrpToon.Editor
{
public class RimLightScope : MaterialUIScope<ShaderGUIExpandable>
@@ -10,67 +12,61 @@ namespace Misaki.HdrpToon.Editor
private static class Properties
{
public static MaterialProperty rimLightColor;
public static MaterialProperty rimLightStrength;
public static MaterialProperty rimLightIntensity;
public static MaterialProperty screenSpaceRimLight;
public static MaterialProperty rimLightLevel;
public static MaterialProperty colorBlendingMode;
public static MaterialProperty adjustRimLightArea;
public static MaterialProperty rimLightFeatherOff;
public static MaterialProperty lightDirection;
public static MaterialProperty rimLightClipping;
public static MaterialProperty rimLightClippingLevel;
public static MaterialProperty lightBaseRimLight;
public static MaterialProperty lightDirectionRimLightLevel;
public static MaterialProperty invertedDirectionRimLight;
public static MaterialProperty invertedRimLightColor;
public static MaterialProperty inversedRimLightLevel;
public static MaterialProperty invertedRimLightFeatherOff;
public static MaterialProperty rimLightMaskMap;
public static MaterialProperty rimLightMaskLevel;
//public static MaterialProperty lightDirection;
//public static MaterialProperty invertedDirectionRimLight;
//public static MaterialProperty invertedRimLightColor;
//public static MaterialProperty inversedRimLightLevel;
//public static MaterialProperty invertedRimLightFeatherOff;
//public static MaterialProperty rimLightMaskMap;
//public static MaterialProperty rimLightMaskLevel;
}
private static class Styles
{
public static readonly GUIContent rimLightColorText =
new("Rim Light Color", "Specifies the color of rim light.");
public static readonly GUIContent rimLightColorText = new("Rim Light Color", "Specifies the color of rim light.");
public static readonly GUIContent rimLightIntensityText = new("Rim Light Strength", "Specifies Rim Light strength.");
public static readonly GUIContent rimLightStrengthText =
new("Rim Light Strength", "Specifies Rim Light strength.");
public static readonly GUIContent screenSpaceRimLightText = new("Screen Space Rim Light", "Enable to make the rim light width constant in screen space.");
public static readonly GUIContent rimLightLevelText = new("Rim Light Level", "Specifies Rim Light power intensity.");
public static readonly GUIContent rimLightClippingText = new("Rim Light Clipping", "Enable to Clip the rim light at specific level");
public static readonly GUIContent rimLightClippingLevelText = new("Clipping Level", "The Clipping value of the rim light.");
public static readonly GUIContent rimLightLevelText =
new("Rim Light Level", "Specifies Rim Light power intensity.");
public static readonly GUIContent lightBaseRimLightText = new("Light Base Rim Light", "Enable to let rim light calculate per light.");
public static readonly GUIContent lightDirectionRimLightLevelText = new("Light Direction Level", "Specifies intensity of Rim Light in the light source direction,");
public static readonly GUIContent colorBlendingModeText =
new("Color Blending Mode", "Rim light color blending mode. Multiply or Add.");
//public static readonly GUIContent lightDirectionText =
// new("Light Direction",
// "When Enabled, rim light is generated only in the direction of the light source.");
public static readonly GUIContent adjustRimLightAreaText =
new("Adjust Rim Light Area", "Increasing this value narrows the area of influence of Rim Light.");
public static readonly GUIContent rimLightFeatherOffText =
new("Rim Light Feather Off", "Disable Rim light feather.");
//public static readonly GUIContent invertedDirectionRimLightText =
// new("Inverted Direction Rim Light", "Rim light from inverted/antipodean direction.");
public static readonly GUIContent lightDirectionText =
new("Light Direction",
"When Enabled, rim light is generated only in the direction of the light source.");
//public static readonly GUIContent invertedRimLightColorText =
// new("Inverted Rim Light Color", "Specifies the color of inverted/antipodean rim light.");
public static readonly GUIContent lightDirectionRimLightLevelText =
new("Light Direction Rim Light Level",
"Specifies intensity of Rim Light in the light source direction,");
//public static readonly GUIContent inversedRimLightLevelText =
// new("Inversed Rim Light Level", "Specifies Inverted/Antipodean Rim Light Level.");
public static readonly GUIContent invertedDirectionRimLightText =
new("Inverted Direction Rim Light", "Rim light from inverted/antipodean direction.");
//public static readonly GUIContent invertedRimLightFeatherOffText =
// new("Inverted Rim Light Feather Off", "Disable Inverted Rim light feather.");
public static readonly GUIContent invertedRimLightColorText =
new("Inverted Rim Light Color", "Specifies the color of inverted/antipodean rim light.");
//public static readonly GUIContent rimLightMaskMapText = new("Rim Light Mask",
// "Rim Light Mask : Texture(linear). The white part of the texture is displayed as Rim Light, and the black part is masked and not displayed.");
public static readonly GUIContent inversedRimLightLevelText =
new("Inversed Rim Light Level", "Specifies Inverted/Antipodean Rim Light Level.");
public static readonly GUIContent invertedRimLightFeatherOffText =
new("Inverted Rim Light Feather Off", "Disable Inverted Rim light feather.");
public static readonly GUIContent rimLightMaskMapText = new("Rim Light Mask",
"Rim Light Mask : Texture(linear). The white part of the texture is displayed as Rim Light, and the black part is masked and not displayed.");
public static readonly GUIContent rimLightMaskLevelText =
new("Rim Light Mask Level",
"-1 gives 0% for the Rim Light effect, 0 gives 100% for the Rim Light and Mask effect, 1 gives 100% for the Rim Light and 0% for the Mask effect.");
//public static readonly GUIContent rimLightMaskLevelText =
// new("Rim Light Mask Level",
// "-1 gives 0% for the Rim Light effect, 0 gives 100% for the Rim Light and Mask effect, 1 gives 100% for the Rim Light and 0% for the Mask effect.");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Rimlight;
@@ -79,50 +75,69 @@ namespace Misaki.HdrpToon.Editor
public override void LoadMaterialProperties()
{
Properties.rimLightColor = FindProperty("_RimLightColor");
Properties.rimLightStrength = FindProperty("_RimLightStrength");
Properties.rimLightLevel = FindProperty("_RimLightLevel");
Properties.colorBlendingMode = FindProperty("_Is_BlendAddToRimColor");
Properties.adjustRimLightArea = FindProperty("_RimLight_InsideMask");
Properties.rimLightFeatherOff = FindProperty("_RimLight_FeatherOff");
Properties.lightDirection = FindProperty("_LightDirection_MaskOn");
Properties.lightDirectionRimLightLevel = FindProperty("_Tweak_LightDirection_MaskLevel");
Properties.invertedDirectionRimLight = FindProperty("_Add_Antipodean_RimLight");
Properties.invertedRimLightColor = FindProperty("_Ap_RimLightColor");
Properties.inversedRimLightLevel = FindProperty("_Ap_RimLight_Power");
Properties.invertedRimLightFeatherOff = FindProperty("_Ap_RimLight_FeatherOff");
Properties.rimLightMaskMap = FindProperty("_Set_RimLightMask");
Properties.rimLightMaskLevel = FindProperty("_Tweak_RimLightMaskLevel");
Properties.rimLightColor = FindProperty(RIM_LIGHT_COLOR);
Properties.rimLightIntensity = FindProperty(RIM_LIGHT_INTENSITY);
Properties.screenSpaceRimLight = FindProperty(SCREEN_SPACE_RIM_LIGHT);
Properties.rimLightLevel = FindProperty(RIM_LIGHT_LEVEL);
Properties.rimLightClipping = FindProperty(RIM_LIGHT_CLIPPING);
Properties.rimLightClippingLevel = FindProperty(RIM_LIGHT_CLIPPING_LEVEL);
Properties.lightBaseRimLight = FindProperty(LIGHT_BASE_RIM_LIGHT);
Properties.lightDirectionRimLightLevel = FindProperty(LIGHT_DIRECTION_RIM_LIGHT_LEVEL);
//Properties.lightDirection = FindProperty(LIGHT_DIRECTION);
//Properties.invertedDirectionRimLight = FindProperty(INVERTED_DIRECTION_RIM_LIGHT);
//Properties.invertedRimLightColor = FindProperty(INVERTED_RIM_LIGHT_COLOR);
//Properties.inversedRimLightLevel = FindProperty(INVERSED_RIM_LIGHT_LEVEL);
//Properties.invertedRimLightFeatherOff = FindProperty(INVERTED_RIM_LIGHT_FEATHER_OFF);
//Properties.rimLightMaskMap = FindProperty(RIM_LIGHT_MASK_MAP);
//Properties.rimLightMaskLevel = FindProperty(RIM_LIGHT_MASK_LEVEL);
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.rimLightColor, Styles.rimLightColorText);
editor.ShaderProperty(Properties.rimLightStrength, Styles.rimLightStrengthText);
editor.ShaderProperty(Properties.rimLightIntensity, Styles.rimLightIntensityText);
editor.ShaderProperty(Properties.screenSpaceRimLight, Styles.screenSpaceRimLightText);
editor.ShaderProperty(Properties.rimLightLevel, Styles.rimLightLevelText);
editor.ShaderProperty(Properties.colorBlendingMode, Styles.colorBlendingModeText);
editor.ShaderProperty(Properties.adjustRimLightArea, Styles.adjustRimLightAreaText);
editor.ShaderProperty(Properties.rimLightFeatherOff, Styles.rimLightFeatherOffText);
editor.ShaderProperty(Properties.lightDirection, Styles.lightDirectionText);
using (var lightDisabledGroup = new EditorGUI.DisabledScope(!Properties.lightDirection.GetBooleanValue()))
if (!Properties.screenSpaceRimLight.GetBooleanValue())
{
using var lightIndentLevelScope = new EditorGUI.IndentLevelScope();
editor.ShaderProperty(Properties.lightDirectionRimLightLevel, Styles.lightDirectionRimLightLevelText);
editor.ShaderProperty(Properties.invertedDirectionRimLight, Styles.invertedDirectionRimLightText);
using var invertedDirectionDisabledGroup = new EditorGUI.DisabledScope(!Properties.invertedDirectionRimLight.GetBooleanValue());
using var invertedDirectionIndentLevelScope = new EditorGUI.IndentLevelScope();
editor.ShaderProperty(Properties.invertedRimLightColor, Styles.invertedRimLightColorText);
editor.ShaderProperty(Properties.inversedRimLightLevel, Styles.inversedRimLightLevelText);
editor.ShaderProperty(Properties.invertedRimLightFeatherOff, Styles.invertedRimLightFeatherOffText);
editor.ShaderProperty(Properties.rimLightClipping, Styles.rimLightClippingText);
if (Properties.rimLightClipping.GetBooleanValue())
{
using var clippingLevelIndentLevelScope = new EditorGUI.IndentLevelScope();
editor.ShaderProperty(Properties.rimLightClippingLevel, Styles.rimLightClippingLevelText);
}
}
EditorGUILayout.Space();
editor.TexturePropertySingleLine(Styles.rimLightMaskMapText, Properties.rimLightMaskMap);
editor.ShaderProperty(Properties.rimLightMaskLevel, Styles.rimLightMaskLevelText);
editor.ShaderProperty(Properties.lightBaseRimLight, Styles.lightBaseRimLightText);
if (Properties.lightBaseRimLight.GetBooleanValue())
{
editor.ShaderProperty(Properties.lightDirectionRimLightLevel, Styles.lightDirectionRimLightLevelText);
}
//using (var lightDisabledGroup = new EditorGUI.DisabledScope(!Properties.lightDirection.GetBooleanValue()))
//{
// using var lightIndentLevelScope = new EditorGUI.IndentLevelScope();
// editor.ShaderProperty(Properties.lightDirectionRimLightLevel, Styles.lightDirectionRimLightLevelText);
// editor.ShaderProperty(Properties.invertedDirectionRimLight, Styles.invertedDirectionRimLightText);
// using var invertedDirectionDisabledGroup = new EditorGUI.DisabledScope(!Properties.invertedDirectionRimLight.GetBooleanValue());
// using var invertedDirectionIndentLevelScope = new EditorGUI.IndentLevelScope();
// editor.ShaderProperty(Properties.invertedRimLightColor, Styles.invertedRimLightColorText);
// editor.ShaderProperty(Properties.inversedRimLightLevel, Styles.inversedRimLightLevelText);
// editor.ShaderProperty(Properties.invertedRimLightFeatherOff, Styles.invertedRimLightFeatherOffText);
//}
//EditorGUILayout.Space();
//editor.TexturePropertySingleLine(Styles.rimLightMaskMapText, Properties.rimLightMaskMap);
//editor.ShaderProperty(Properties.rimLightMaskLevel, Styles.rimLightMaskLevelText);
}
}
}

View File

@@ -157,7 +157,7 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.emissiveIntensity, Styles.emissiveIntensityText);
if (EditorGUI.EndChangeCheck())
{
editor.ApplyChange(material =>
foreach (var material in editor.GetMaterials())
{
if (material.HasProperty(EMISSIVE_COLOR_LDR) && material.HasProperty(EMISSIVE_INTENSITY) && material.HasProperty(EMISSIVE_COLOR))
{
@@ -167,7 +167,7 @@ namespace Misaki.HdrpToon.Editor
var emissiveColorLDRLinear = new Color(Mathf.GammaToLinearSpace(emissiveColorLDR.r), Mathf.GammaToLinearSpace(emissiveColorLDR.g), Mathf.GammaToLinearSpace(emissiveColorLDR.b));
material.SetColor(EMISSIVE_COLOR, emissiveColorLDRLinear * material.GetFloat(EMISSIVE_INTENSITY));
}
});
}
}
EditorGUILayout.Space();

View File

@@ -72,7 +72,16 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.cullMode, Styles.cullingModeText);
editor.ShaderProperty(Properties.shadingMode, Styles.shadingModeText);
EditorGUI.BeginChangeCheck();
editor.ShaderProperty(Properties.materialType, Styles.materialTypeText);
if (EditorGUI.EndChangeCheck())
{
foreach (var material in editor.GetMaterials())
{
material.SetShaderPassEnabled(UtsShaderPassName.HAIR_SHADOW_CASTER_PASS_NAME, Properties.materialType.GetEnumValue<MaterialType>() == MaterialType.FrontHair);
}
}
editor.ShaderProperty(Properties.pbrMode, Styles.pbrModeText);
EditorGUI.BeginChangeCheck();