From a627c1f915b86956b528af304fa85fee42dc11a0 Mon Sep 17 00:00:00 2001 From: yum Date: Fri, 2 Aug 2024 16:28:13 -0700 Subject: Add controls for overlays on transparent materials Add ability to constrain overlay to parts of the texture based on opacity. Min/max opacity are configurable. Add slider to multiply the overlay's alpha channel. This helps prevent transparent overlays from disappearing in less detailed mip maps. --- Editor/tooner.cs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'Editor') diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 4ad7fa7..f7bdc50 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -166,6 +166,23 @@ public class ToonerGUI : ShaderGUI { SetKeyword($"_PBR_OVERLAY{i}_MIX_MIN", mode == PbrAlbedoMixMode.Min); SetKeyword($"_PBR_OVERLAY{i}_MIX_MAX", mode == PbrAlbedoMixMode.Max); + bc = FindProperty($"_PBR_Overlay{i}_Constrain_By_Alpha"); + enabled = bc.floatValue > 1E-6; + EditorGUI.BeginChangeCheck(); + enabled = EditorGUILayout.Toggle("Constrain to transparent sections", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + if (enabled) { + EditorGUI.indentLevel += 1; + bc = FindProperty($"_PBR_Overlay{i}_Constrain_By_Alpha_Min"); + editor.RangeProperty(bc, "Min"); + bc = FindProperty($"_PBR_Overlay{i}_Constrain_By_Alpha_Max"); + editor.RangeProperty(bc, "Max"); + EditorGUI.indentLevel -= 1; + } + bc = FindProperty($"_PBR_Overlay{i}_Alpha_Multiplier"); + editor.RangeProperty(bc, "Alpha multiplier"); + bc = FindProperty($"_PBR_Overlay{i}_Emission"); bct = FindProperty($"_PBR_Overlay{i}_EmissionTex"); editor.TexturePropertySingleLine( @@ -223,6 +240,17 @@ public class ToonerGUI : ShaderGUI { EditorGUI.EndChangeCheck(); bc.floatValue = enabled ? 1.0f : 0.0f; } + } else { + SetKeyword($"_PBR_OVERLAY{i}_BASECOLOR_MAP", false); + SetKeyword($"_PBR_OVERLAY{i}_MIX_ALPHA_BLEND", false); + SetKeyword($"_PBR_OVERLAY{i}_MIX_ADD", false); + SetKeyword($"_PBR_OVERLAY{i}_MIX_MIN", false); + SetKeyword($"_PBR_OVERLAY{i}_MIX_MAX", false); + SetKeyword($"_PBR_OVERLAY{i}_EMISSION_MAP", false); + SetKeyword($"_PBR_OVERLAY{i}_NORMAL_MAP", false); + SetKeyword($"_PBR_OVERLAY{i}_METALLIC_MAP", false); + SetKeyword($"_PBR_OVERLAY{i}_ROUGHNESS_MAP", false); + SetKeyword($"_PBR_OVERLAY{i}_MASK", false); } EditorGUI.indentLevel -= 1; } @@ -1217,7 +1245,7 @@ public class ToonerGUI : ShaderGUI { case RenderingMode.TransClipping: queue = RenderQueue.AlphaTest; render_type = "Transparent"; - src_blend = BlendMode.One; + src_blend = BlendMode.SrcAlpha; dst_blend = BlendMode.OneMinusSrcAlpha; zwrite = true; break; -- cgit v1.2.3