From f71e1fbbce087174bde68c5812c8c3e8c76ef737 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 18:05:34 +0900 Subject: [PATCH] Add EditMode --- .../VRM10/MToon10/Editor/MToonInspector.cs | 154 +++++++++++------- .../VRM10/vrmc_materials_mtoon.shader | 3 + .../UnityShaderLab/Properties/MToon10Prop.cs | 3 + .../Properties/MToon10Properties.cs | 2 + 4 files changed, 103 insertions(+), 59 deletions(-) diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs index 7bf96ec6e..a3e452ae9 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs @@ -19,12 +19,21 @@ namespace VRMShaders.VRM10.MToon10.Editor EditorGUI.BeginChangeCheck(); + EditorGUILayout.HelpBox("This shader is for VRM 1.0.", MessageType.Info); + + using (new LabelScope("Editor Settings")) + { + PopupEnum("Edit Mode", props[MToon10Prop.EditorEditMode], materialEditor); + } + var editMode = (MToon10EditorEditMode) (int) props[MToon10Prop.EditorEditMode].floatValue; + var isAdvancedEditMode = editMode == MToon10EditorEditMode.Advanced; + using (new LabelScope("Rendering")) { PopupEnum("Alpha Mode", props[MToon10Prop.AlphaMode], materialEditor); var alphaMode = (MToon10AlphaMode) (int) props[MToon10Prop.AlphaMode].floatValue; - if (alphaMode == MToon10AlphaMode.Transparent) + if (isAdvancedEditMode && alphaMode == MToon10AlphaMode.Transparent) { PopupEnum( "Transparent With ZWrite Mode", @@ -40,7 +49,10 @@ namespace VRMShaders.VRM10.MToon10.Editor PopupEnum("Double Sided", props[MToon10Prop.DoubleSided], materialEditor); - materialEditor.ShaderProperty(props[MToon10Prop.RenderQueueOffsetNumber], "RenderQueue Offset"); + if (isAdvancedEditMode) + { + materialEditor.ShaderProperty(props[MToon10Prop.RenderQueueOffsetNumber], "RenderQueue Offset"); + } } using (new LabelScope("Lighting")) @@ -55,23 +67,34 @@ namespace VRMShaders.VRM10.MToon10.Editor props[MToon10Prop.ShadeColorTexture], props[MToon10Prop.ShadeColorFactor] ); - materialEditor.TexturePropertySingleLine( - new GUIContent("Normal Map", "Normal Map (RGB)"), - props[MToon10Prop.NormalTexture], - props[MToon10Prop.NormalTextureScale] - ); - materialEditor.ShaderProperty(props[MToon10Prop.ShadingShiftFactor], "Shading Shift"); + if (isAdvancedEditMode) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Normal Map", "Normal Map (RGB)"), + props[MToon10Prop.NormalTexture], + props[MToon10Prop.NormalTextureScale] + ); + } + EditorGUILayout.Space(); + materialEditor.ShaderProperty(props[MToon10Prop.ShadingToonyFactor], "Shading Toony"); - materialEditor.TexturePropertySingleLine( - new GUIContent("Additive Shading Shift", "Shading Shift (R)"), - props[MToon10Prop.ShadingShiftTexture], - props[MToon10Prop.ShadingShiftTextureScale] - ); + materialEditor.ShaderProperty(props[MToon10Prop.ShadingShiftFactor], "Shading Shift"); + if (isAdvancedEditMode) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Additive Shading Shift", "Shading Shift (R)"), + props[MToon10Prop.ShadingShiftTexture], + props[MToon10Prop.ShadingShiftTextureScale] + ); + } } - using (new LabelScope("Global Illumination")) + if (isAdvancedEditMode) { - materialEditor.ShaderProperty(props[MToon10Prop.GiEqualizationFactor], "GI Equalization"); + using (new LabelScope("Global Illumination")) + { + materialEditor.ShaderProperty(props[MToon10Prop.GiEqualizationFactor], "GI Equalization"); + } } using (new LabelScope("Emission")) @@ -89,16 +112,19 @@ namespace VRMShaders.VRM10.MToon10.Editor new GUIContent("Rim Color", "Rim Color (RGB)"), props[MToon10Prop.RimMultiplyTexture] ); - materialEditor.ShaderProperty( - props[MToon10Prop.RimLightingMixFactor], - new GUIContent("Rim LightingMix") - ); - EditorGUILayout.Space(); + if (isAdvancedEditMode) + { + materialEditor.ShaderProperty( + props[MToon10Prop.RimLightingMixFactor], + new GUIContent("Rim LightingMix") + ); + EditorGUILayout.Space(); - materialEditor.TexturePropertySingleLine( - new GUIContent("Matcap Rim", "Matcap Rim (RGB)"), - props[MToon10Prop.MatcapTexture] - ); + materialEditor.TexturePropertySingleLine( + new GUIContent("Matcap Rim", "Matcap Rim (RGB)"), + props[MToon10Prop.MatcapTexture] + ); + } EditorGUILayout.Space(); materialEditor.ShaderProperty( @@ -118,39 +144,50 @@ namespace VRMShaders.VRM10.MToon10.Editor using (new LabelScope("Outline")) { PopupEnum("Outline Mode", props[MToon10Prop.OutlineWidthMode], materialEditor); - materialEditor.TexturePropertySingleLine( - new GUIContent("Outline Width", "Outline Width (G) [meter]"), - props[MToon10Prop.OutlineWidthMultiplyTexture], - props[MToon10Prop.OutlineWidthFactor] - ); - materialEditor.ShaderProperty( - props[MToon10Prop.OutlineColorFactor], - new GUIContent("Outline Color") - ); - materialEditor.ShaderProperty( - props[MToon10Prop.OutlineLightingMixFactor], - new GUIContent("Outline LightingMix") - ); + var hasOutline = (MToon10OutlineMode) (int) props[MToon10Prop.OutlineWidthMode].floatValue != MToon10OutlineMode.None; + + if (hasOutline) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Outline Width", "Outline Width (G) [meter]"), + props[MToon10Prop.OutlineWidthMultiplyTexture], + props[MToon10Prop.OutlineWidthFactor] + ); + materialEditor.ShaderProperty( + props[MToon10Prop.OutlineColorFactor], + new GUIContent("Outline Color") + ); + if (isAdvancedEditMode) + { + materialEditor.ShaderProperty( + props[MToon10Prop.OutlineLightingMixFactor], + new GUIContent("Outline LightingMix") + ); + } + } } - using (new LabelScope("UV Animation")) + if (isAdvancedEditMode) { - materialEditor.TexturePropertySingleLine( - new GUIContent("Mask", "Mask (B)"), - props[MToon10Prop.UvAnimationMaskTexture] - ); - materialEditor.ShaderProperty( - props[MToon10Prop.UvAnimationScrollXSpeedFactor], - new GUIContent("Translate X") - ); - materialEditor.ShaderProperty( - props[MToon10Prop.UvAnimationScrollYSpeedFactor], - new GUIContent("Translate Y") - ); - materialEditor.ShaderProperty( - props[MToon10Prop.UvAnimationRotationSpeedFactor], - new GUIContent("Rotation") - ); + using (new LabelScope("UV Animation")) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Mask", "Mask (B)"), + props[MToon10Prop.UvAnimationMaskTexture] + ); + materialEditor.ShaderProperty( + props[MToon10Prop.UvAnimationScrollXSpeedFactor], + new GUIContent("Translate X") + ); + materialEditor.ShaderProperty( + props[MToon10Prop.UvAnimationScrollYSpeedFactor], + new GUIContent("Translate Y") + ); + materialEditor.ShaderProperty( + props[MToon10Prop.UvAnimationRotationSpeedFactor], + new GUIContent("Rotation") + ); + } } if (EditorGUI.EndChangeCheck()) @@ -158,12 +195,11 @@ namespace VRMShaders.VRM10.MToon10.Editor Validate(materials); } - using (new LabelScope("Debug")) + if (isAdvancedEditMode && materials.Length == 1) { - if (materials.Length == 1) + var mat = materials[0]; + using (new LabelScope("Debug")) { - var mat = materials[0]; - EditorGUILayout.LabelField("RenderQueue", mat.renderQueue.ToString()); EditorGUILayout.LabelField("Cull", ((CullMode) props[MToon10Prop.UnityCullMode].floatValue).ToString()); EditorGUILayout.LabelField("SrcBlend", ((BlendMode) props[MToon10Prop.UnitySrcBlend].floatValue).ToString()); @@ -193,7 +229,7 @@ namespace VRMShaders.VRM10.MToon10.Editor var changed = EditorGUI.EndChangeCheck(); if (changed) { - editor.RegisterPropertyChangeUndo("EnumPopUp"); + editor.RegisterPropertyChangeUndo($"Change {name}"); property.floatValue = ret; } diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader index d32578c9e..53927223f 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader @@ -58,6 +58,9 @@ Shader "VRM10/MToon10" // etc _M_DebugMode ("_DebugMode", Float) = 0.0 + + // for Editor + _M_EditMode ("_EditMode", Float) = 0.0 } // Shader Model 3.0 diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Prop.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Prop.cs index c7047cecf..6a0b6e386 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Prop.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Prop.cs @@ -55,5 +55,8 @@ UnityDstBlend, UnityZWrite, UnityAlphaToMask, + + // for Editor + EditorEditMode, } } \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Properties.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Properties.cs index 29aa35d7b..fb209cfcc 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Properties.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Properties.cs @@ -51,6 +51,8 @@ namespace VRMShaders.VRM10.MToon10.Runtime [MToon10Prop.UnityDstBlend] = "_M_DstBlend", [MToon10Prop.UnityZWrite] = "_M_ZWrite", [MToon10Prop.UnityAlphaToMask] = "_M_AlphaToMask", + + [MToon10Prop.EditorEditMode] = "_M_EditMode", }; public static IReadOnlyDictionary UnityShaderLabNames => _unityShaderLabNames;