From 8c661736cd30db1705fc490a0e7e98b5b5bb7477 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 16:35:59 +0900 Subject: [PATCH 1/8] Rename MToon10 --- Assets/VRM10/Tests/MaterialImportTests.cs | 2 +- .../VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader | 2 +- .../MToon10/Runtime/UnityShaderLab/Properties/MToon10Meta.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/VRM10/Tests/MaterialImportTests.cs b/Assets/VRM10/Tests/MaterialImportTests.cs index 503b30a33..cbe82ce0b 100644 --- a/Assets/VRM10/Tests/MaterialImportTests.cs +++ b/Assets/VRM10/Tests/MaterialImportTests.cs @@ -26,7 +26,7 @@ namespace UniVRM10 var matDesc = new Vrm10MaterialDescriptorGenerator().Get(data, 0); Assert.AreEqual("Alicia_body", matDesc.Name); - Assert.AreEqual("Hidden/VRM10/vrmc_materials_mtoon", matDesc.ShaderName); + Assert.AreEqual("VRM10/MToon10", matDesc.ShaderName); Assert.AreEqual("Alicia_body", matDesc.TextureSlots["_MainTex"].UnityObjectName); Assert.AreEqual("Alicia_body", matDesc.TextureSlots["_ShadeTex"].UnityObjectName); 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 9b9e53978..d32578c9e 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader @@ -1,4 +1,4 @@ -Shader "Hidden/VRM10/vrmc_materials_mtoon" +Shader "VRM10/MToon10" { Properties { diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Meta.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Meta.cs index 331a7e7af..8141abb90 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Meta.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/UnityShaderLab/Properties/MToon10Meta.cs @@ -2,6 +2,6 @@ { public static class MToon10Meta { - public static readonly string UnityShaderName = "Hidden/VRM10/vrmc_materials_mtoon"; + public static readonly string UnityShaderName = "VRM10/MToon10"; } } \ No newline at end of file From f71e1fbbce087174bde68c5812c8c3e8c76ef737 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 18:05:34 +0900 Subject: [PATCH 2/8] 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; From 23a50ae7b37298fad14ab9a8e5a7da1c68bb4d75 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 19:05:51 +0900 Subject: [PATCH 3/8] Add migration Tests --- .../VRM10/MToon10/Runtime/MToon10Migrator.cs | 4 +- Assets/VRMShaders/VRM10/MToon10/Tests.meta | 8 ++++ .../VRM10/MToon10/Tests/MigrationTests.cs | 48 +++++++++++++++++++ .../MToon10/Tests/MigrationTests.cs.meta | 3 ++ .../VRMShaders.VRM10.MToon10.Tests.asmdef | 18 +++++++ ...VRMShaders.VRM10.MToon10.Tests.asmdef.meta | 7 +++ 6 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 Assets/VRMShaders/VRM10/MToon10/Tests.meta create mode 100644 Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs create mode 100644 Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs.meta create mode 100644 Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef create mode 100644 Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef.meta diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon10Migrator.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon10Migrator.cs index 317b40c48..cd49fa111 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon10Migrator.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon10Migrator.cs @@ -25,8 +25,8 @@ namespace VRMShaders.VRM10.MToon10.Runtime { var (rangeMin, rangeMax) = GetShadingRange0X(shadingToony0X, shadingShift0X); - // new shadingShift is the center of range. - return Mathf.Clamp((rangeMax - rangeMin) * 0.5f, -1, +1); + // new shadingShift is the center of range inverted. + return Mathf.Clamp((rangeMax + rangeMin) * 0.5f * -1f, -1, +1); } /// diff --git a/Assets/VRMShaders/VRM10/MToon10/Tests.meta b/Assets/VRMShaders/VRM10/MToon10/Tests.meta new file mode 100644 index 000000000..00f95abe0 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Tests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f5d3d10dc09b0524abb5c55599bb14e8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs b/Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs new file mode 100644 index 000000000..7be8d4939 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs @@ -0,0 +1,48 @@ +using NUnit.Framework; +using VRMShaders.VRM10.MToon10.Runtime; + +namespace VRMShaders.VRM10.MToon10.Tests +{ + public sealed class MigrationTests + { + [Test] + public void MigrateToonyAndShift() + { + var delta = 0.001f; + + // 0.x default + Assert.AreEqual(0.95f,MToon10Migrator.MigrateToShadingToony(0.9f, 0f), delta); + Assert.AreEqual(-0.05f,MToon10Migrator.MigrateToShadingShift(0.9f, 0f), delta); + + // lambert + Assert.AreEqual(0.5f, MToon10Migrator.MigrateToShadingToony(0, 0), delta); + Assert.AreEqual(-0.5f, MToon10Migrator.MigrateToShadingShift(0, 0), delta); + + // half lambert + Assert.AreEqual(0.0f, MToon10Migrator.MigrateToShadingToony(0, -1), delta); + Assert.AreEqual(0.0f, MToon10Migrator.MigrateToShadingShift(0, -1), delta); + + // random + Assert.AreEqual(0.79f, MToon10Migrator.MigrateToShadingToony(0.7f, -0.4f), delta); + Assert.AreEqual(0.19f, MToon10Migrator.MigrateToShadingShift(0.7f, -0.4f), delta); + } + + [Test] + public void MigrateGiIntensity() + { + var delta = 0.001f; + + // normal + Assert.AreEqual(0f, MToon10Migrator.MigrateToGiEqualization(1f)); + + // equalized + Assert.AreEqual(1f, MToon10Migrator.MigrateToGiEqualization(0f)); + + // intermediate + Assert.AreEqual(0.25f, MToon10Migrator.MigrateToGiEqualization(0.75f)); + Assert.AreEqual(0.333f, MToon10Migrator.MigrateToGiEqualization(0.667f)); + Assert.AreEqual(0.125f, MToon10Migrator.MigrateToGiEqualization(0.875f)); + Assert.AreEqual(0.75f, MToon10Migrator.MigrateToGiEqualization(0.25f)); + } + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs.meta new file mode 100644 index 000000000..ce9e95fba --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Tests/MigrationTests.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6530bdc57fd7d354db37f84b93222964 +timeCreated: 1626335293 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef b/Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef new file mode 100644 index 000000000..369b3e938 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef @@ -0,0 +1,18 @@ +{ + "name": "VRMShaders.VRM10.MToon10.Tests", + "references": [ + "VRMShaders.VRM10.MToon10.Runtime" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": false, + "defineConstraints": [] +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef.meta b/Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef.meta new file mode 100644 index 000000000..69489d908 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Tests/VRMShaders.VRM10.MToon10.Tests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: a8e4a462662564e48931da8e2a390e60 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: From 93d4507db7717d11a5000f4ef2b5e472dfe84df1 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 19:16:02 +0900 Subject: [PATCH 4/8] Add Shade & Toony presets. --- .../MToon10/Editor/MToon10EditorEditMode.cs | 8 ++++ .../Editor/MToon10EditorEditMode.cs.meta | 3 ++ .../VRM10/MToon10/Editor/MToonInspector.cs | 43 ++++++++++++++++++- .../VRM10/vrmc_materials_mtoon.shader | 4 +- 4 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs create mode 100644 Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs.meta diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs new file mode 100644 index 000000000..07855be10 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs @@ -0,0 +1,8 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public enum MToon10EditorEditMode + { + Basic = 0, + Advanced = 1, + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs.meta new file mode 100644 index 000000000..924035f7a --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToon10EditorEditMode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 22a9170004064d029bc205fc5b5a1acc +timeCreated: 1626335293 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs index a3e452ae9..438e4bb34 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs @@ -77,16 +77,55 @@ namespace VRMShaders.VRM10.MToon10.Editor } EditorGUILayout.Space(); - materialEditor.ShaderProperty(props[MToon10Prop.ShadingToonyFactor], "Shading Toony"); - materialEditor.ShaderProperty(props[MToon10Prop.ShadingShiftFactor], "Shading Shift"); if (isAdvancedEditMode) { + materialEditor.ShaderProperty(props[MToon10Prop.ShadingToonyFactor], "Shading Toony"); + materialEditor.ShaderProperty(props[MToon10Prop.ShadingShiftFactor], "Shading Shift"); materialEditor.TexturePropertySingleLine( new GUIContent("Additive Shading Shift", "Shading Shift (R)"), props[MToon10Prop.ShadingShiftTexture], props[MToon10Prop.ShadingShiftTextureScale] ); } + else + { + EditorGUILayout.BeginHorizontal(); + GUILayout.Label("Presets"); + if (GUILayout.Button("Default")) + { + props[MToon10Prop.ShadingToonyFactor].floatValue = 0.95f; + props[MToon10Prop.ShadingShiftFactor].floatValue = -0.05f; + props[MToon10Prop.ShadingShiftTexture].textureValue = null; + } + if (GUILayout.Button("Lambert")) + { + props[MToon10Prop.ShadingToonyFactor].floatValue = 0.5f; + props[MToon10Prop.ShadingShiftFactor].floatValue = -0.5f; + props[MToon10Prop.ShadingShiftTexture].textureValue = null; + } + if (GUILayout.Button("Cartoon")) + { + props[MToon10Prop.ShadingToonyFactor].floatValue = 1.0f; + props[MToon10Prop.ShadingShiftFactor].floatValue = 0.0f; + props[MToon10Prop.ShadingShiftTexture].textureValue = null; + } + EditorGUILayout.EndHorizontal(); + + GUILayout.BeginVertical(GUI.skin.box); + materialEditor.ShaderProperty(props[MToon10Prop.ShadingToonyFactor], "Shading Toony"); + materialEditor.ShaderProperty(props[MToon10Prop.ShadingShiftFactor], "Shading Shift"); + GUILayout.EndVertical(); + } + + if (props[MToon10Prop.ShadingShiftTexture].textureValue == null) + { + var toony = props[MToon10Prop.ShadingToonyFactor].floatValue; + var shift = props[MToon10Prop.ShadingShiftFactor].floatValue; + if (toony - shift < 1.0f - 0.001f) + { + EditorGUILayout.HelpBox("The lit area includes non-lit area.", MessageType.Warning); + } + } } if (isAdvancedEditMode) 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 53927223f..f4c59d7d0 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader @@ -16,10 +16,10 @@ Shader "VRM10/MToon10" _ShadeTex ("mtoon.shadeMultiplyTexture", 2D) = "white" {} [Normal] _BumpMap ("normalTexture", 2D) = "bump" {} // Unity specified name _BumpScale ("normalTexture.scale", Float) = 1.0 // Unity specified name - _ShadingShiftFactor ("mtoon.shadingShiftFactor", Range(-1, 1)) = 0 + _ShadingShiftFactor ("mtoon.shadingShiftFactor", Range(-1, 1)) = -0.05 _ShadingShiftTex ("mtoon.shadingShiftTexture", 2D) = "black" {} // channel R _ShadingShiftTexScale ("mtoon.shadingShiftTexture.scale", Float) = 1 - _ShadingToonyFactor ("mtoon.shadingToonyFactor", Range(0, 1)) = 0.9 + _ShadingToonyFactor ("mtoon.shadingToonyFactor", Range(0, 1)) = 0.95 // GI _GiEqualization ("mtoon.giEqualizationFactor", Range(0, 1)) = 0.9 From 3cb5d97c44649b8acc18d32ca88c8aa72bcf8565 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 19:44:06 +0900 Subject: [PATCH 5/8] fix outline normal --- .../Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl index f7a74039e..b7dc73cac 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_vertex.hlsl @@ -24,15 +24,16 @@ Varyings MToonVertex(const Attributes v) // v is UnityCG macro specified name. const VertexPositionInfo position = MToon_GetOutlineVertex(v.vertex.xyz, normalize(v.normalOS), output.uv); output.pos = position.positionCS; output.positionWS = position.positionWS; + output.normalWS = UnityObjectToWorldNormal(-v.normalOS); } else { const VertexPositionInfo position = MToon_GetVertex(v.vertex.xyz); output.pos = position.positionCS; output.positionWS = position.positionWS; + output.normalWS = UnityObjectToWorldNormal(v.normalOS); } - output.normalWS = UnityObjectToWorldNormal(v.normalOS); output.viewDirWS = MToon_GetWorldSpaceNormalizedViewDir(output.positionWS); #if defined(_NORMALMAP) From eb532c4aa678f278d795d0c6d7ccd1c09a24bc0a Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 19:47:22 +0900 Subject: [PATCH 6/8] Add Pbr Correct mode. --- .../Resources/VRM10/vrmc_materials_mtoon_define.hlsl | 6 ++++++ .../VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl index cb983736f..fcd7c8d64 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl @@ -18,6 +18,12 @@ #define MTOON_IS_FRONT_VFACE(VAL, FRONT, BACK) ((VAL > 0.0) ? (FRONT) : (BACK)) #endif +// Compile-time constant +inline bool MToon_IsPbrCorrectOn() +{ + return false; +} + // Compile-time constant inline bool MToon_IsForwardBasePass() { diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl index bee7da2dd..ca7ea9eaa 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl @@ -38,6 +38,12 @@ inline half GetMToonLighting_Shade(const UnityLighting lighting, const MToonInpu const half shadeShift = GetMToonLighting_Reflectance_ShadingShift(input); const half shadeToony = _ShadingToonyFactor; + if (MToon_IsPbrCorrectOn()) + { + const half shadeInput = dotNL; + return mtoon_linearstep(-1.0 + shadeToony, +1.0 - shadeToony, shadeInput + shadeShift); + } + if (MToon_IsForwardBasePass()) { const half shadeInput = lerp(-1, 1, mtoon_linearstep(-1, 1, dotNL) * lighting.directLightAttenuation); @@ -52,6 +58,11 @@ inline half GetMToonLighting_Shade(const UnityLighting lighting, const MToonInpu inline half GetMToonLighting_Shadow(const UnityLighting lighting, const half dotNL) { + if (MToon_IsPbrCorrectOn()) + { + return lighting.directLightAttenuation * (min(0, dotNL) + 1); + } + if (MToon_IsForwardBasePass()) { return 1; From 1549db1a8110004a19df29dd1c7d5f0d6e0e33da Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 19:57:21 +0900 Subject: [PATCH 7/8] fix pbr correct mode. --- .../MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl | 1 + .../Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl index fcd7c8d64..cec236313 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_define.hlsl @@ -19,6 +19,7 @@ #endif // Compile-time constant +// EXPERIMENTAL inline bool MToon_IsPbrCorrectOn() { return false; diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl index ca7ea9eaa..c1d3513bf 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl @@ -60,7 +60,7 @@ inline half GetMToonLighting_Shadow(const UnityLighting lighting, const half dot { if (MToon_IsPbrCorrectOn()) { - return lighting.directLightAttenuation * (min(0, dotNL) + 1); + return lighting.directLightAttenuation * step(0, dotNL); } if (MToon_IsForwardBasePass()) From 8e0322aa7044758458b8633127dcaa1d66ff61de Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 15 Jul 2021 19:57:43 +0900 Subject: [PATCH 8/8] fix direcitonal light attenuation multiply. --- .../Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl index c1d3513bf..494ceb559 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_lighting_mtoon.hlsl @@ -46,8 +46,8 @@ inline half GetMToonLighting_Shade(const UnityLighting lighting, const MToonInpu if (MToon_IsForwardBasePass()) { - const half shadeInput = lerp(-1, 1, mtoon_linearstep(-1, 1, dotNL) * lighting.directLightAttenuation); - return mtoon_linearstep(-1.0 + shadeToony, +1.0 - shadeToony, shadeInput + shadeShift); + const half shadeInput = lerp(-1, 1, mtoon_linearstep(-1, 1, dotNL)); + return mtoon_linearstep(-1.0 + shadeToony, +1.0 - shadeToony, shadeInput + shadeShift) * lighting.directLightAttenuation; } else {