From 72a4f411ff04375caffebc557592b98bcf700ae1 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 22 May 2024 15:51:37 -0700 Subject: Add stochastic cutout rendering mode Use a randomized threshold instead of a static one when rendering transparency in cutout mode. This lets us render things like fabrics. Requires UVs to work properly. --- Editor/tooner.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'Editor') diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 9409dbc..ca2d1c8 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -324,7 +324,7 @@ public class ToonerGUI : ShaderGUI { mode = (NormalsMode) EditorGUILayout.EnumPopup( MakeLabel("Normals mode"), mode); if (EditorGUI.EndChangeCheck()) { - RecordAction("Rendering Mode"); + RecordAction("Rendering mode"); } bc.floatValue = (float) mode; @@ -620,6 +620,11 @@ public class ToonerGUI : ShaderGUI { Fade } + enum CutoutMode { + Cutoff, + Stochastic + } + void DoRendering() { RenderingMode mode = RenderingMode.Opaque; if (target.IsKeywordEnabled("_RENDERING_CUTOUT")) { @@ -630,13 +635,13 @@ public class ToonerGUI : ShaderGUI { EditorGUI.BeginChangeCheck(); mode = (RenderingMode) EditorGUILayout.EnumPopup( - MakeLabel("Rendering Mode"), mode); + MakeLabel("Rendering mode"), mode); BlendMode src_blend = BlendMode.One; BlendMode dst_blend = BlendMode.Zero; bool zwrite = false; if (EditorGUI.EndChangeCheck()) { - RecordAction("Rendering Mode"); + RecordAction("Rendering mode"); SetKeyword("_RENDERING_CUTOUT", mode == RenderingMode.Cutout); SetKeyword("_RENDERING_FADE", mode == RenderingMode.Fade); @@ -676,8 +681,19 @@ public class ToonerGUI : ShaderGUI { MaterialProperty bc; if (mode == RenderingMode.Cutout) { - bc = FindProperty("_Alpha_Cutoff"); - editor.ShaderProperty(bc, MakeLabel(bc)); + EditorGUI.BeginChangeCheck(); + bc = FindProperty("_Cutout_Mode"); + CutoutMode cmode = (CutoutMode) Math.Round(bc.floatValue); + cmode = (CutoutMode) EditorGUILayout.EnumPopup( + MakeLabel("Cutout mode"), cmode); + EditorGUI.EndChangeCheck(); + bc.floatValue = (float) cmode; + SetKeyword("_RENDERING_CUTOUT_STOCHASTIC", cmode == CutoutMode.Stochastic); + + if (cmode == CutoutMode.Cutoff) { + bc = FindProperty("_Alpha_Cutoff"); + editor.ShaderProperty(bc, MakeLabel(bc)); + } } bc = FindProperty("_Cull"); -- cgit v1.2.3