From 7752a9d11ea60551fddd8dbc4bbcd1780b2de08b Mon Sep 17 00:00:00 2001 From: sin Date: Thu, 11 Jun 2026 14:58:34 +0900 Subject: [PATCH 01/12] mask support --- .../Runtime/Shaders/URP/ToonURP_3Das2D.shader | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index db9d6e907..be7c389cb 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader @@ -70,9 +70,9 @@ Shader "Toon/Toon 3D as 2D (URP)"{ ZWrite On Stencil{ - Ref 128 // Put this in the last bit of our stencil value for maximum compatibility with sprite mask - Comp always - Pass replace + Ref 1 + Comp NotEqual // render where mask is NOT present + Pass Keep } Pass{ From 56b3d03535d6b1cc2b38197005244cfae5df133a Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:16:27 +0900 Subject: [PATCH 02/12] add stencil configuration [skip ci] --- .../Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 49 +++++++++++++++++++ .../Runtime/Scripts/ToonConstants.cs | 7 ++- .../Runtime/Shaders/URP/ToonURP_3Das2D.shader | 15 ++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index e316c6433..850d5559b 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -34,6 +34,8 @@ public override void OnGUI(MaterialEditor mEditor, MaterialProperty[] props) { m_materialState.useOutline = Toon3Das2DMaterialUtility.IsOutlineEnabled(mats[0]); DrawOutlineGUI(mEditor, mats, m_materialPropertyUIElements, ref m_outlineFoldout, ref m_materialState); + DrawShaderSettingsGUI(mEditor, mats, m_materialPropertyUIElements, ref m_shaderSettingsFoldout); + if (EditorGUI.EndChangeCheck()) { mEditor.PropertiesChanged(); @@ -236,6 +238,26 @@ static void DrawOutlineGUI(MaterialEditor mEditor, Material[] mats, Dictionary uiElements, ref bool foldout) { + + ToonEditorGUIUtility.DrawFoldoutGUI(ref foldout, SHADER_SETTINGS_FOLDOUT); + if (!foldout) + return; + + ToonEditorGUIUtility.DrawRangePropertyGUI(mEditor, uiElements[ToonConstants.SHADER_PROP_STENCIL_REF]); + ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_COMP], + m_stencilCompEnums, m_stencilCompIndices, out int _); + ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_PASS], + m_stencilOpEnums, m_stencilOpIndices, out int _); + ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_FAIL], + m_stencilOpEnums, m_stencilOpIndices, out int _); + + EditorGUILayout.Space(); + } + //---------------------------------------------------------------------------------------------------------------------- void InitMaterialPropertyUIElements(MaterialProperty[] allProps) { @@ -537,6 +559,24 @@ public override void AssignNewShaderToMaterial( }, //Outline End + // Shader Settings + new MaterialUIElement { + mainPropertyName = new MaterialName(ToonConstants.SHADER_PROP_STENCIL_REF), + label = new GUIContent("Stencil Ref", "Stencil reference value (0–255)."), + }, + new MaterialUIElement { + mainPropertyName = new MaterialName(ToonConstants.SHADER_PROP_STENCIL_COMP), + label = new GUIContent("Stencil Compare", "Stencil comparison function."), + }, + new MaterialUIElement { + mainPropertyName = new MaterialName(ToonConstants.SHADER_PROP_STENCIL_OP_PASS), + label = new GUIContent("Pass Op", "What to do when stencil test passes."), + }, + new MaterialUIElement { + mainPropertyName = new MaterialName(ToonConstants.SHADER_PROP_STENCIL_OP_FAIL), + label = new GUIContent("Fail Op", "What to do when stencil test fails."), + }, + }; @@ -551,6 +591,14 @@ internal enum HighlightMode { private static readonly GUIContent[] m_highlightModeEnums = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(HighlightMode)); private static readonly int[] m_highlightModeValues = ToonEnumUtility.ToIntValues(typeof(HighlightMode)); + private static readonly GUIContent[] m_stencilCompEnums = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.CompareFunction)); + private static readonly int[] m_stencilCompIndices = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.CompareFunction)); + private static readonly GUIContent[] m_stencilOpEnums = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.StencilOp)); + private static readonly int[] m_stencilOpIndices = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.StencilOp)); + + static readonly GUIContent SHADER_SETTINGS_FOLDOUT = + EditorGUIUtility.TrTextContent("Shader Settings", "Low-level shader settings such as stencil."); + static readonly GUIContent COLORS_FOLDOUT = EditorGUIUtility.TrTextContent("Colors", "Colors for basic cel-shading settings in Unity Toon Shader."); @@ -564,6 +612,7 @@ static readonly GUIContent LIGHTING_FOLDOUT bool m_normalMapFoldout = false; bool m_outlineFoldout = false; bool m_lightingFoldout = false; + bool m_shaderSettingsFoldout = false; private Material m_lastMaterial; diff --git a/com.unity.toonshader/Runtime/Scripts/ToonConstants.cs b/com.unity.toonshader/Runtime/Scripts/ToonConstants.cs index 3d9ca26e3..0ce2463c4 100644 --- a/com.unity.toonshader/Runtime/Scripts/ToonConstants.cs +++ b/com.unity.toonshader/Runtime/Scripts/ToonConstants.cs @@ -79,7 +79,12 @@ internal static class ToonConstants { internal const string SHADER_PROP_OUTLINE_FAR = "_OutlineFar"; internal const string SHADER_PROP_OUTLINE_USE_NORMAL_MAP = "_Outline_UseNormalMap"; internal const string SHADER_PROP_OUTLINE_NORMAL_MAP = "_Outline_NormalMap"; - + + internal const string SHADER_PROP_STENCIL_REF = "_StencilRef"; + internal const string SHADER_PROP_STENCIL_COMP = "_StencilComp"; + internal const string SHADER_PROP_STENCIL_OP_PASS = "_StencilOpPass"; + internal const string SHADER_PROP_STENCIL_OP_FAIL = "_StencilOpFail"; + internal static readonly int SHADER_PROPERTY_MATERIAL_VERSION = Shader.PropertyToID("_ToonMaterialVersion"); internal const string SHADER_PROP_DIRECTIONAL_LIGHT_DIRECTION = "_DirectionalLight_Direction"; diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index be7c389cb..5cef18ff9 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader @@ -54,7 +54,13 @@ Shader "Toon/Toon 3D as 2D (URP)"{ _Outline_UseNormalMap ("Outline: Use Outline Normal Map", Integer ) = 0 _Outline_NormalMap ("Outline Normal Map", 2D) = "bump" {} [HideInInspector] _ToonMaterialVersion ("Toon Material Version", Integer ) = 0 - + + // Stencil Properties + [IntRange] _StencilRef ("Stencil Reference", Range(0, 255)) = 1 + [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Compare", Float) = 6 // NotEqual + [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpPass ("Stencil Pass Op", Float) = 0 // Keep + [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpFail ("Stencil Fail Op", Float) = 0 // Keep + } SubShader{ @@ -70,9 +76,10 @@ Shader "Toon/Toon 3D as 2D (URP)"{ ZWrite On Stencil{ - Ref 1 - Comp NotEqual // render where mask is NOT present - Pass Keep + Ref[_StencilRef] + Comp[_StencilComp] + Pass[_StencilOpPass] + Fail[_StencilOpFail] } Pass{ From 92f7c72a4b732fe5ff11beed66bfc250cfe416ca Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:24:08 +0900 Subject: [PATCH 03/12] remove unused cmments --- .../Runtime/Shaders/URP/ToonURP_3Das2D.shader | 9 --------- 1 file changed, 9 deletions(-) diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index 5cef18ff9..bb649060b 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader @@ -324,15 +324,6 @@ Shader "Toon/Toon 3D as 2D (URP)"{ // Cull [_SRPDefaultUnlitColMode] // ColorMask [_SPRDefaultUnlitColorMask] Blend SrcAlpha OneMinusSrcAlpha -// Stencil -// { -// Ref[_StencilNo] -// Comp[_StencilComp] -// Pass[_StencilOpPass] -// Fail[_StencilOpFail] -// -// } - HLSLPROGRAM #pragma target 3.0 From 46535bf3d949d048ee84ba6d2f42682449a0d560 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:24:25 +0900 Subject: [PATCH 04/12] change the default stencil values --- .../Runtime/Shaders/URP/ToonURP_3Das2D.shader | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index bb649060b..27b01f981 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader @@ -56,9 +56,12 @@ Shader "Toon/Toon 3D as 2D (URP)"{ [HideInInspector] _ToonMaterialVersion ("Toon Material Version", Integer ) = 0 // Stencil Properties - [IntRange] _StencilRef ("Stencil Reference", Range(0, 255)) = 1 - [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Compare", Float) = 6 // NotEqual - [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpPass ("Stencil Pass Op", Float) = 0 // Keep + + // Put this in the last bit of our stencil value for maximum compatibility with sprite mask + [IntRange] _StencilRef ("Stencil Reference", Range(0, 255)) = 128 + + [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Compare", Float) = 8 // Always + [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpPass ("Stencil Pass Op", Float) = 2 // Replace [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpFail ("Stencil Fail Op", Float) = 0 // Keep } From 9c349c8a6796ef87e9330c703680784bc9cb0a33 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:37:21 +0900 Subject: [PATCH 05/12] move to ToonEditorConstants --- .../Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 10 +++------- .../Editor/Scripts/ToonEditorConstants.cs | 10 ++++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index 850d5559b..7881e162c 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -249,11 +249,11 @@ static void DrawShaderSettingsGUI(MaterialEditor mEditor, Material[] mats, ToonEditorGUIUtility.DrawRangePropertyGUI(mEditor, uiElements[ToonConstants.SHADER_PROP_STENCIL_REF]); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_COMP], - m_stencilCompEnums, m_stencilCompIndices, out int _); + ToonEditorConstants.STENCIL_COMP_ENUMS, ToonEditorConstants.STENCIL_COMP_INDICES, out int _); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_PASS], - m_stencilOpEnums, m_stencilOpIndices, out int _); + ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_FAIL], - m_stencilOpEnums, m_stencilOpIndices, out int _); + ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); EditorGUILayout.Space(); } @@ -591,10 +591,6 @@ internal enum HighlightMode { private static readonly GUIContent[] m_highlightModeEnums = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(HighlightMode)); private static readonly int[] m_highlightModeValues = ToonEnumUtility.ToIntValues(typeof(HighlightMode)); - private static readonly GUIContent[] m_stencilCompEnums = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.CompareFunction)); - private static readonly int[] m_stencilCompIndices = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.CompareFunction)); - private static readonly GUIContent[] m_stencilOpEnums = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.StencilOp)); - private static readonly int[] m_stencilOpIndices = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.StencilOp)); static readonly GUIContent SHADER_SETTINGS_FOLDOUT = EditorGUIUtility.TrTextContent("Shader Settings", "Low-level shader settings such as stencil."); diff --git a/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs b/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs index a367ca2e5..1a1b7120d 100644 --- a/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs +++ b/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs @@ -1,6 +1,7 @@ using System.IO; using Unity.Rendering.Toon; +using UnityEngine; namespace UnityEditor.Rendering.Toon { @@ -13,9 +14,14 @@ internal static class ToonEditorConstants { internal static readonly string TOON_SHADER_PATH = Path.Combine(PACKAGE_PATH,"Runtime/Shaders/UnityToon.shader").Replace('\\','/'); - internal static readonly string TOON_TESS_SHADER_PATH = + internal static readonly string TOON_TESS_SHADER_PATH = Path.Combine(PACKAGE_PATH,"Runtime/Shaders/UnityToonTessellation.shader").Replace('\\','/'); - + + internal static readonly GUIContent[] STENCIL_COMP_ENUMS = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.CompareFunction)); + internal static readonly int[] STENCIL_COMP_INDICES = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.CompareFunction)); + internal static readonly GUIContent[] STENCIL_OP_ENUMS = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.StencilOp)); + internal static readonly int[] STENCIL_OP_INDICES = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.StencilOp)); + } From 9cfad5ee92c626a45daab3e1e6b781b2be50dee7 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:40:42 +0900 Subject: [PATCH 06/12] change order --- com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index 7881e162c..bcec7e2a5 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -25,6 +25,7 @@ public override void OnGUI(MaterialEditor mEditor, MaterialProperty[] props) { } EditorGUI.BeginChangeCheck(); + DrawShaderSettingsGUI(mEditor, mats, m_materialPropertyUIElements, ref m_shaderSettingsFoldout); DrawThreeColorsGUI(mEditor, mats, m_materialPropertyUIElements, ref m_colorsFoldout); DrawShadingGUI(mEditor, mats, m_materialPropertyUIElements, ref m_shadingFoldout); DrawLightingGUI(mEditor, mats, m_materialPropertyUIElements, ref m_lightingFoldout); @@ -34,8 +35,6 @@ public override void OnGUI(MaterialEditor mEditor, MaterialProperty[] props) { m_materialState.useOutline = Toon3Das2DMaterialUtility.IsOutlineEnabled(mats[0]); DrawOutlineGUI(mEditor, mats, m_materialPropertyUIElements, ref m_outlineFoldout, ref m_materialState); - DrawShaderSettingsGUI(mEditor, mats, m_materialPropertyUIElements, ref m_shaderSettingsFoldout); - if (EditorGUI.EndChangeCheck()) { mEditor.PropertiesChanged(); From b57c77fd3241d98c13ea6be322c5009a13c4c60d Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:46:12 +0900 Subject: [PATCH 07/12] stencil foldout --- .../Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index bcec7e2a5..ef98b28a1 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -25,7 +25,7 @@ public override void OnGUI(MaterialEditor mEditor, MaterialProperty[] props) { } EditorGUI.BeginChangeCheck(); - DrawShaderSettingsGUI(mEditor, mats, m_materialPropertyUIElements, ref m_shaderSettingsFoldout); + DrawShaderSettingsGUI(mEditor, mats, m_materialPropertyUIElements, ref m_shaderSettingsFoldout, ref m_stencilFoldout); DrawThreeColorsGUI(mEditor, mats, m_materialPropertyUIElements, ref m_colorsFoldout); DrawShadingGUI(mEditor, mats, m_materialPropertyUIElements, ref m_shadingFoldout); DrawLightingGUI(mEditor, mats, m_materialPropertyUIElements, ref m_lightingFoldout); @@ -240,19 +240,23 @@ static void DrawOutlineGUI(MaterialEditor mEditor, Material[] mats, Dictionary uiElements, ref bool foldout) { + Dictionary uiElements, ref bool foldout, ref bool stencilFoldout) { ToonEditorGUIUtility.DrawFoldoutGUI(ref foldout, SHADER_SETTINGS_FOLDOUT); if (!foldout) return; - ToonEditorGUIUtility.DrawRangePropertyGUI(mEditor, uiElements[ToonConstants.SHADER_PROP_STENCIL_REF]); - ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_COMP], - ToonEditorConstants.STENCIL_COMP_ENUMS, ToonEditorConstants.STENCIL_COMP_INDICES, out int _); - ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_PASS], - ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); - ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_FAIL], - ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); + stencilFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(stencilFoldout, "Stencil"); + if (stencilFoldout) { + ToonEditorGUIUtility.DrawRangePropertyGUI(mEditor, uiElements[ToonConstants.SHADER_PROP_STENCIL_REF]); + ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_COMP], + ToonEditorConstants.STENCIL_COMP_ENUMS, ToonEditorConstants.STENCIL_COMP_INDICES, out int _); + ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_PASS], + ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); + ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_FAIL], + ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); + } + EditorGUILayout.EndFoldoutHeaderGroup(); EditorGUILayout.Space(); } @@ -608,6 +612,7 @@ static readonly GUIContent LIGHTING_FOLDOUT bool m_outlineFoldout = false; bool m_lightingFoldout = false; bool m_shaderSettingsFoldout = false; + bool m_stencilFoldout = false; private Material m_lastMaterial; From 6500b265bb9b3c07abcf83d102a7b49cda217453 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:57:10 +0900 Subject: [PATCH 08/12] indent --- .../Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 8 ++++++-- .../Editor/Scripts/Utilities/ToonEditorGUIUtility.cs | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index ef98b28a1..c006deb01 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -246,8 +246,11 @@ static void DrawShaderSettingsGUI(MaterialEditor mEditor, Material[] mats, if (!foldout) return; - stencilFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(stencilFoldout, "Stencil"); + Rect rect = ToonEditorGUIUtility.GetIndentedHeaderRect(INDENT_SIZE); + stencilFoldout = EditorGUI.BeginFoldoutHeaderGroup(rect, stencilFoldout, "Stencil"); if (stencilFoldout) { + const int INDENT_DEPTH = 2; + EditorGUI.indentLevel += (INDENT_SIZE * INDENT_DEPTH); ToonEditorGUIUtility.DrawRangePropertyGUI(mEditor, uiElements[ToonConstants.SHADER_PROP_STENCIL_REF]); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_COMP], ToonEditorConstants.STENCIL_COMP_ENUMS, ToonEditorConstants.STENCIL_COMP_INDICES, out int _); @@ -255,8 +258,9 @@ static void DrawShaderSettingsGUI(MaterialEditor mEditor, Material[] mats, ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_FAIL], ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); + EditorGUI.indentLevel -= (INDENT_SIZE * INDENT_DEPTH); } - EditorGUILayout.EndFoldoutHeaderGroup(); + EditorGUI.EndFoldoutHeaderGroup(); EditorGUILayout.Space(); } diff --git a/com.unity.toonshader/Editor/Scripts/Utilities/ToonEditorGUIUtility.cs b/com.unity.toonshader/Editor/Scripts/Utilities/ToonEditorGUIUtility.cs index 8b7f1cd75..f908c4542 100644 --- a/com.unity.toonshader/Editor/Scripts/Utilities/ToonEditorGUIUtility.cs +++ b/com.unity.toonshader/Editor/Scripts/Utilities/ToonEditorGUIUtility.cs @@ -141,6 +141,13 @@ internal static bool DrawFoldoutWithToggleGUI(MaterialEditor mEditor, Material[] } + internal static Rect GetIndentedHeaderRect(int indentLevel, bool hasLabel = false) { + EditorGUI.indentLevel += indentLevel; + Rect rect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(hasLabel, EditorGUIUtility.singleLineHeight)); + EditorGUI.indentLevel -= indentLevel; + return rect; + } + static void DrawBGRect(Rect lineRect) { float initialPadding = lineRect.x; From 3a02bbe6ce2257221ea92b95f10811ecf5979b89 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 11:58:19 +0900 Subject: [PATCH 09/12] set the stencil foldout to true --- com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index c006deb01..56efde919 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -616,7 +616,7 @@ static readonly GUIContent LIGHTING_FOLDOUT bool m_outlineFoldout = false; bool m_lightingFoldout = false; bool m_shaderSettingsFoldout = false; - bool m_stencilFoldout = false; + bool m_stencilFoldout = true; private Material m_lastMaterial; From 8e42eef2eda048b99a882b2840073db29deb5581 Mon Sep 17 00:00:00 2001 From: sin Date: Fri, 12 Jun 2026 12:11:51 +0900 Subject: [PATCH 10/12] use integer --- .../Runtime/Shaders/URP/ToonURP_3Das2D.shader | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader index 27b01f981..bdffc899a 100644 --- a/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader +++ b/com.unity.toonshader/Runtime/Shaders/URP/ToonURP_3Das2D.shader @@ -60,9 +60,9 @@ Shader "Toon/Toon 3D as 2D (URP)"{ // Put this in the last bit of our stencil value for maximum compatibility with sprite mask [IntRange] _StencilRef ("Stencil Reference", Range(0, 255)) = 128 - [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Compare", Float) = 8 // Always - [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpPass ("Stencil Pass Op", Float) = 2 // Replace - [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpFail ("Stencil Fail Op", Float) = 0 // Keep + [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Stencil Compare", Integer) = 8 // Always + [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpPass ("Stencil Pass Op", Integer) = 2 // Replace + [Enum(UnityEngine.Rendering.StencilOp)] _StencilOpFail ("Stencil Fail Op", Integer) = 0 // Keep } From bfb2999704fdf0cb71dc34f186aa31b0360a9efa Mon Sep 17 00:00:00 2001 From: sin Date: Mon, 15 Jun 2026 16:35:35 +0900 Subject: [PATCH 11/12] values --- .../Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 6 +++--- com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index 56efde919..2d1241033 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -253,11 +253,11 @@ static void DrawShaderSettingsGUI(MaterialEditor mEditor, Material[] mats, EditorGUI.indentLevel += (INDENT_SIZE * INDENT_DEPTH); ToonEditorGUIUtility.DrawRangePropertyGUI(mEditor, uiElements[ToonConstants.SHADER_PROP_STENCIL_REF]); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_COMP], - ToonEditorConstants.STENCIL_COMP_ENUMS, ToonEditorConstants.STENCIL_COMP_INDICES, out int _); + ToonEditorConstants.STENCIL_COMP_ENUMS, ToonEditorConstants.STENCIL_COMP_VALUES, out int _); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_PASS], - ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); + ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_VALUES, out int _); ToonEditorGUIUtility.DrawIntPopupGUI(mEditor, mats, uiElements[ToonConstants.SHADER_PROP_STENCIL_OP_FAIL], - ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_INDICES, out int _); + ToonEditorConstants.STENCIL_OP_ENUMS, ToonEditorConstants.STENCIL_OP_VALUES, out int _); EditorGUI.indentLevel -= (INDENT_SIZE * INDENT_DEPTH); } EditorGUI.EndFoldoutHeaderGroup(); diff --git a/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs b/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs index 1a1b7120d..8eb1ff75a 100644 --- a/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs +++ b/com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs @@ -18,9 +18,9 @@ internal static class ToonEditorConstants { Path.Combine(PACKAGE_PATH,"Runtime/Shaders/UnityToonTessellation.shader").Replace('\\','/'); internal static readonly GUIContent[] STENCIL_COMP_ENUMS = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.CompareFunction)); - internal static readonly int[] STENCIL_COMP_INDICES = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.CompareFunction)); + internal static readonly int[] STENCIL_COMP_VALUES = ToonEnumUtility.ToIntValues(typeof(UnityEngine.Rendering.CompareFunction)); internal static readonly GUIContent[] STENCIL_OP_ENUMS = ToonEnumUtility.ToInspectorNamesAsGUIContent(typeof(UnityEngine.Rendering.StencilOp)); - internal static readonly int[] STENCIL_OP_INDICES = ToonEnumUtility.ToIndices(typeof(UnityEngine.Rendering.StencilOp)); + internal static readonly int[] STENCIL_OP_VALUES = ToonEnumUtility.ToIntValues(typeof(UnityEngine.Rendering.StencilOp)); } From 3415469eaded0877f680bf05abc39aa882608428 Mon Sep 17 00:00:00 2001 From: sin Date: Mon, 15 Jun 2026 16:38:40 +0900 Subject: [PATCH 12/12] refresh foldout --- .../Editor/Scripts/GUI/UnityToon3Das2DGUI.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs index 2d1241033..8f15cf96f 100644 --- a/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs +++ b/com.unity.toonshader/Editor/Scripts/GUI/UnityToon3Das2DGUI.cs @@ -50,6 +50,8 @@ public override void OnGUI(MaterialEditor mEditor, MaterialProperty[] props) { void RefreshFoldouts(Material mat, Dictionary uiElements) { + m_shaderSettingsFoldout = false; + m_stencilFoldout = true; m_colorsFoldout = true; m_shadingFoldout = true; @@ -610,13 +612,13 @@ internal enum HighlightMode { static readonly GUIContent LIGHTING_FOLDOUT = EditorGUIUtility.TrTextContent("Lighting", "Lighting settings."); + bool m_shaderSettingsFoldout = false; + bool m_stencilFoldout = true; bool m_colorsFoldout = true; bool m_shadingFoldout = true; bool m_normalMapFoldout = false; bool m_outlineFoldout = false; bool m_lightingFoldout = false; - bool m_shaderSettingsFoldout = false; - bool m_stencilFoldout = true; private Material m_lastMaterial;