diff --git a/Cancerspace.shader b/Cancerspace.shader index 479fa0a..6ff1d03 100644 --- a/Cancerspace.shader +++ b/Cancerspace.shader @@ -4,6 +4,16 @@ [Enum(UnityEngine.Rendering.CullMode)] _CullMode ("Cull Mode", Float) = 0 [Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Int) = 4 + [Enum(Off, 0, On, 1)] _ZWrite ("ZWrite", Int) = 1 + _ColorMask ("Color Mask", Int) = 15 + + _StencilRef ("Ref", Int) = 0 + [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("Compare Function", Int) = 8 + [Enum(UnityEngine.Rendering.StencilOp)] _StencilPassOp ("Pass Operation", Int) = 0 + [Enum(UnityEngine.Rendering.StencilOp)] _StencilFailOp ("Fail Operation", Int) = 0 + [Enum(UnityEngine.Rendering.StencilOp)] _StencilZFailOp ("ZFail Operation", Int) = 0 + _StencilReadMask ("Read Mask", Int) = 255 + _StencilWriteMask ("Write Mask", Int) = 255 _Puffiness ("Puffiness", Float) = 0 @@ -52,8 +62,20 @@ SubShader { Tags { "Queue" = "Transparent+3" } + Stencil { + Ref [_StencilRef] + ReadMask [_StencilReadMask] + WriteMask [_StencilWriteMask] + Comp [_StencilComp] + Pass [_StencilPassOp] + Fail [_StencilFailOp] + ZFail [_StencilZFailOp] + } + Cull [_CullMode] ZTest [_ZTest] + ZWrite [_ZWrite] + ColorMask [_ColorMask] GrabPass { "_Garb" } diff --git a/Editor/CancerspaceInspector.cs b/Editor/CancerspaceInspector.cs index 5879fe6..30ae2db 100644 --- a/Editor/CancerspaceInspector.cs +++ b/Editor/CancerspaceInspector.cs @@ -1,5 +1,6 @@ using UnityEditor; using UnityEngine; +using UnityEngine.Rendering; using System; using System.IO; using System.Text.RegularExpressions; @@ -26,6 +27,7 @@ public static class Styles { public static string overlaySettingsTitle = "Overlay"; public static string screenColorAdjustmentsTitle = "Screen Color Adjustment"; public static string screenTransformTitle = "Screen Transformations"; + public static string stencilTitle = "Stencil Testing"; public static string miscSettingsTitle = "Misc"; public static string renderQueueExportTitle = "Custom Render Queue Exporter"; public static string customRenderQueueSliderText = "Custom Render Queue"; @@ -50,6 +52,16 @@ public CSCategory(string nname, GUIStyle sstyle, CSCategorySetup ssetupDelegate) protected MaterialProperty cullMode; protected MaterialProperty zTest; + protected MaterialProperty zWrite; + protected MaterialProperty colorMask; + + protected MaterialProperty stencilRef; + protected MaterialProperty stencilComp; + protected MaterialProperty stencilPass; + protected MaterialProperty stencilFail; + protected MaterialProperty stencilZFail; + protected MaterialProperty stencilReadMask; + protected MaterialProperty stencilWriteMask; protected MaterialProperty puffiness; @@ -103,6 +115,16 @@ public void FindProperties(MaterialProperty[] props) { cullMode = FindProperty("_CullMode", props); zTest = FindProperty("_ZTest", props); + zWrite = FindProperty("_ZWrite", props); + colorMask = FindProperty("_ColorMask", props); + + stencilRef = FindProperty("_StencilRef", props); + stencilComp = FindProperty("_StencilComp", props); + stencilPass = FindProperty("_StencilPassOp", props); + stencilFail = FindProperty("_StencilFailOp", props); + stencilZFail = FindProperty("_StencilZFailOp", props); + stencilReadMask = FindProperty("_StencilReadMask", props); + stencilWriteMask = FindProperty("_StencilWriteMask", props); puffiness = FindProperty("_Puffiness", props); @@ -219,9 +241,21 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro me.ShaderProperty(puffiness, puffiness.displayName); }), + new CSCategory(Styles.stencilTitle, defaultStyle, me => { + DisplayIntSlider(me, stencilRef, 0, 255); + me.ShaderProperty(stencilComp, stencilComp.displayName); + me.ShaderProperty(stencilPass, stencilPass.displayName); + me.ShaderProperty(stencilFail, stencilFail.displayName); + me.ShaderProperty(stencilZFail, stencilZFail.displayName); + DisplayIntSlider(me, stencilReadMask, 0, 255); + DisplayIntSlider(me, stencilWriteMask, 0, 255); + }), + new CSCategory(Styles.miscSettingsTitle, defaultStyle, me => { me.ShaderProperty(cullMode, cullMode.displayName); me.ShaderProperty(zTest, zTest.displayName); + me.ShaderProperty(zWrite, zWrite.displayName); + ShowColorMaskFlags(me, colorMask); me.ShaderProperty(mirrorReflectionMode, mirrorReflectionMode.displayName); }), @@ -318,4 +352,42 @@ void DisplayVec3Field(MaterialEditor materialEditor, MaterialProperty property) } EditorGUI.showMixedValue = false; } + + void DisplayIntField(MaterialEditor materialEditor, MaterialProperty property) { + EditorGUI.showMixedValue = property.hasMixedValue; + int v = (int) property.floatValue; + EditorGUI.BeginChangeCheck(); + v = EditorGUILayout.IntField(property.displayName, v); + if (EditorGUI.EndChangeCheck()) { + materialEditor.RegisterPropertyChangeUndo(property.displayName); + property.floatValue = (float) v; + } + EditorGUI.showMixedValue = false; + } + + void DisplayIntSlider(MaterialEditor materialEditor, MaterialProperty property, int min, int max) { + EditorGUI.showMixedValue = property.hasMixedValue; + int v = (int) property.floatValue; + EditorGUI.BeginChangeCheck(); + v = EditorGUILayout.IntSlider(property.displayName, v, min, max); + if (EditorGUI.EndChangeCheck()) { + materialEditor.RegisterPropertyChangeUndo(property.displayName); + property.floatValue = (float) v; + } + EditorGUI.showMixedValue = false; + } + + void ShowColorMaskFlags(MaterialEditor materialEditor, MaterialProperty property) { + EditorGUI.showMixedValue = property.hasMixedValue; + ColorWriteMask v = (ColorWriteMask) ((int) property.floatValue); + EditorGUI.BeginChangeCheck(); + v = (ColorWriteMask) EditorGUILayout.EnumFlagsField(property.displayName, v); + if (EditorGUI.EndChangeCheck()) { + materialEditor.RegisterPropertyChangeUndo(property.displayName); + int x = (int) v; + if (x == -1) x = 15; + property.floatValue = (float) x; + } + EditorGUI.showMixedValue = false; + } }