diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/LabelScope.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/LabelScope.cs new file mode 100644 index 000000000..29c7a973d --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/LabelScope.cs @@ -0,0 +1,21 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace VRMShaders.VRM10.MToon10.Editor +{ + public readonly struct LabelScope : IDisposable + { + public LabelScope(string label) + { + EditorGUILayout.LabelField(label, EditorStyles.boldLabel); + EditorGUILayout.BeginVertical(GUI.skin.box); + } + + public void Dispose() + { + EditorGUILayout.EndVertical(); + EditorGUILayout.Space(); + } + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/LabelScope.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/LabelScope.cs.meta new file mode 100644 index 000000000..c37a2b161 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/LabelScope.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: af7abf08bb63495fae1f334377be0b23 +timeCreated: 1623133727 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/DoubleSidedMode.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/DoubleSidedMode.cs new file mode 100644 index 000000000..5c7ef2fb8 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/DoubleSidedMode.cs @@ -0,0 +1,8 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public enum DoubleSidedMode + { + Off = 0, + On = 1, + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/DoubleSidedMode.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/DoubleSidedMode.cs.meta new file mode 100644 index 000000000..a536f092a --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/DoubleSidedMode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c3c422f6c0ac416bbcd70ee3203bca6a +timeCreated: 1623135734 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/EmissiveMapKeyword.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/EmissiveMapKeyword.cs new file mode 100644 index 000000000..96a8aac95 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/EmissiveMapKeyword.cs @@ -0,0 +1,7 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public static class EmissiveMapKeyword + { + public const string On = "_MTOON_EMISSIVEMAP"; + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/EmissiveMapKeyword.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/EmissiveMapKeyword.cs.meta new file mode 100644 index 000000000..347d15734 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/EmissiveMapKeyword.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c9f4547527b3411aa87d8322ce9d9132 +timeCreated: 1623144877 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/NormalMapKeyword.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/NormalMapKeyword.cs new file mode 100644 index 000000000..1c9358db3 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/NormalMapKeyword.cs @@ -0,0 +1,7 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public static class NormalMapKeyword + { + public const string On = "_NORMALMAP"; + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/NormalMapKeyword.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/NormalMapKeyword.cs.meta new file mode 100644 index 000000000..61146abd3 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/NormalMapKeyword.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 78ea3fe03cac402083bd53882d186b95 +timeCreated: 1623144639 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineMode.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineMode.cs new file mode 100644 index 000000000..5c157566a --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineMode.cs @@ -0,0 +1,9 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public enum OutlineMode + { + None = 0, + World = 1, + Screen = 2, + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineMode.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineMode.cs.meta new file mode 100644 index 000000000..c7bca3ebf --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineMode.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8aece52be2cb42de9bfde4a072e5a6a0 +timeCreated: 1623149007 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineModeKeyword.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineModeKeyword.cs new file mode 100644 index 000000000..408821b31 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineModeKeyword.cs @@ -0,0 +1,8 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public static class OutlineModeKeyword + { + public const string World = "_MTOON_OUTLINE_WORLD"; + public const string Screen = "_MTOON_OUTLINE_SCREEN"; + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineModeKeyword.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineModeKeyword.cs.meta new file mode 100644 index 000000000..e60fbf098 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/OutlineModeKeyword.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 94313b3f0f4943d681f40e4cfbd5b600 +timeCreated: 1623144868 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/ParameterMapKeyword.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/ParameterMapKeyword.cs new file mode 100644 index 000000000..7d83c8789 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/ParameterMapKeyword.cs @@ -0,0 +1,7 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public static class ParameterMapKeyword + { + public const string On = "_MTOON_PARAMETERMAP"; + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/ParameterMapKeyword.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/ParameterMapKeyword.cs.meta new file mode 100644 index 000000000..b6b097f44 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/ParameterMapKeyword.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4cf6251408b74e228660a1a43f4de9c9 +timeCreated: 1623144871 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/RimMapKeyword.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/RimMapKeyword.cs new file mode 100644 index 000000000..ed2f61ce7 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/RimMapKeyword.cs @@ -0,0 +1,7 @@ +namespace VRMShaders.VRM10.MToon10.Editor +{ + public static class RimMapKeyword + { + public const string On = "_MTOON_RIMMAP"; + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/RimMapKeyword.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/RimMapKeyword.cs.meta new file mode 100644 index 000000000..8dc55a15e --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonDefined/RimMapKeyword.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f22a9af9be334674ad2638be0af0c818 +timeCreated: 1623144874 \ 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 4a59eead2..e7102aad0 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonInspector.cs @@ -8,7 +8,7 @@ using UnityEngine.Rendering; namespace VRMShaders.VRM10.MToon10.Editor { - public class MToonInspector : ShaderGUI + public sealed class MToonInspector : ShaderGUI { public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { @@ -16,24 +16,164 @@ namespace VRMShaders.VRM10.MToon10.Editor .ToDictionary(x => x.Key, x => FindProperty(x.Value, properties)); var materials = materialEditor.targets.Select(x => x as Material).ToArray(); - EditorGUILayout.LabelField("Rendering", EditorStyles.boldLabel); - EditorGUILayout.BeginVertical(GUI.skin.box); + EditorGUI.BeginChangeCheck(); + + using (new LabelScope("Rendering")) { - EditorGUILayout.LabelField("Mode", EditorStyles.boldLabel); - if (PopupEnum("Alpha Mode", props[Prop.AlphaMode], materialEditor)) + PopupEnum("Alpha Mode", props[Prop.AlphaMode], materialEditor); + var alphaMode = (AlphaMode) (int) props[Prop.AlphaMode].floatValue; + + if (alphaMode == AlphaMode.Transparent) { - Validate(materials); + PopupEnum( + "Transparent With ZWrite Mode", + props[Prop.TransparentWithZWrite], + materialEditor + ); } - if (PopupEnum("Transparent With ZWrite Mode", props[Prop.TransparentWithZWrite], materialEditor)) + if (alphaMode == AlphaMode.Cutout) { - Validate(materials); + materialEditor.ShaderProperty(props[Prop.AlphaCutoff], "Cutoff"); + } + + PopupEnum("Double Sided", props[Prop.DoubleSided], materialEditor); + + materialEditor.ShaderProperty(props[Prop.RenderQueueOffsetNumber], "RenderQueue Offset"); + } + + using (new LabelScope("Lighting")) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Lit Color, Alpha", "Lit (RGB), Alpha (A)"), + props[Prop.BaseColorTexture], + props[Prop.BaseColorFactor] + ); + materialEditor.TexturePropertySingleLine( + new GUIContent("Shade Color", "Shade (RGB)"), + props[Prop.ShadeColorTexture], + props[Prop.ShadeColorFactor] + ); + materialEditor.TexturePropertySingleLine( + new GUIContent("Normal Map", "Normal Map (RGB)"), + props[Prop.NormalTexture], + props[Prop.NormalTextureScale] + ); + materialEditor.ShaderProperty(props[Prop.ShadingShiftFactor], "Shading Shift"); + materialEditor.ShaderProperty(props[Prop.ShadingToonyFactor], "Shading Toony"); + materialEditor.TexturePropertySingleLine( + new GUIContent("Additive Shading Shift", "Shading Shift (R)"), + props[Prop.ShadingShiftTexture], + props[Prop.ShadingShiftTextureScale] + ); + } + + using (new LabelScope("Global Illumination")) + { + materialEditor.ShaderProperty(props[Prop.GiEqualizationFactor], "GI Equalization"); + } + + using (new LabelScope("Emission")) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Emission", "Emission (RGB)"), + props[Prop.EmissiveTexture], + props[Prop.EmissiveFactor] + ); + } + + using (new LabelScope("Rim Lighting")) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Rim Color", "Rim Color (RGB)"), + props[Prop.RimMultiplyTexture] + ); + materialEditor.ShaderProperty( + props[Prop.RimLightingMixFactor], + new GUIContent("Rim LightingMix") + ); + EditorGUILayout.Space(); + + materialEditor.TexturePropertySingleLine( + new GUIContent("Matcap Rim", "Matcap Rim (RGB)"), + props[Prop.MatcapTexture] + ); + EditorGUILayout.Space(); + + materialEditor.ShaderProperty( + props[Prop.ParametricRimColorFactor], + new GUIContent("Parametric Rim Color") + ); + materialEditor.ShaderProperty( + props[Prop.ParametricRimFresnelPowerFactor], + new GUIContent("Parametric Rim Fresnel Power") + ); + materialEditor.ShaderProperty( + props[Prop.ParametricRimLiftFactor], + new GUIContent("Parametric Rim Lift") + ); + } + + using (new LabelScope("Outline")) + { + PopupEnum("Outline Mode", props[Prop.OutlineWidthMode], materialEditor); + materialEditor.TexturePropertySingleLine( + new GUIContent("Outline Width", "Outline Width (G) [meter]"), + props[Prop.OutlineWidthMultiplyTexture], + props[Prop.OutlineWidthFactor] + ); + materialEditor.ShaderProperty( + props[Prop.OutlineColorFactor], + new GUIContent("Outline Color") + ); + materialEditor.ShaderProperty( + props[Prop.OutlineLightingMixFactor], + new GUIContent("Outline LightingMix") + ); + } + + using (new LabelScope("UV Animation")) + { + materialEditor.TexturePropertySingleLine( + new GUIContent("Mask", "Mask (B)"), + props[Prop.UvAnimationMaskTexture] + ); + materialEditor.ShaderProperty( + props[Prop.UvAnimationScrollXSpeedFactor], + new GUIContent("Translate X") + ); + materialEditor.ShaderProperty( + props[Prop.UvAnimationScrollYSpeedFactor], + new GUIContent("Translate Y") + ); + materialEditor.ShaderProperty( + props[Prop.UvAnimationRotationSpeedFactor], + new GUIContent("Rotation") + ); + } + + if (EditorGUI.EndChangeCheck()) + { + Validate(materials); + } + + using (new LabelScope("Debug")) + { + if (materials.Length == 1) + { + var mat = materials[0]; + + EditorGUILayout.LabelField("RenderQueue", mat.renderQueue.ToString()); + EditorGUILayout.LabelField("Cull", ((CullMode) props[Prop.UnityCullMode].floatValue).ToString()); + EditorGUILayout.LabelField("SrcBlend", ((BlendMode) props[Prop.UnitySrcBlend].floatValue).ToString()); + EditorGUILayout.LabelField("DstBlend", ((BlendMode) props[Prop.UnityDstBlend].floatValue).ToString()); + EditorGUILayout.LabelField("ZWrite", ((UnityZWriteMode) props[Prop.UnityZWrite].floatValue).ToString()); + EditorGUILayout.LabelField("AlphaToMask", ((UnityAlphaToMaskMode) props[Prop.UnityAlphaToMask].floatValue).ToString()); + EditorGUILayout.LabelField("Enabled Keywords", string.Join("\n", mat.shaderKeywords), EditorStyles.textArea); } } - EditorGUILayout.EndVertical(); - EditorGUILayout.Space(); - base.OnGUI(materialEditor, properties); + // base.OnGUI(materialEditor, properties); } private static void Validate(Material[] materials) diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonValidator.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonValidator.cs index 6528ae130..d105722dd 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Editor/MToonValidator.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MToonValidator.cs @@ -17,13 +17,17 @@ namespace VRMShaders.VRM10.MToon10.Editor { var alphaMode = (AlphaMode) _material.GetInt(Prop.AlphaMode); var zWriteMode = (TransparentWithZWriteMode) _material.GetInt(Prop.TransparentWithZWrite); - SetUnityRenderSettings(_material, alphaMode, zWriteMode); + var renderQueueOffset = _material.GetInt(Prop.RenderQueueOffsetNumber); + var doubleSidedMode = (DoubleSidedMode) _material.GetInt(Prop.DoubleSided); + SetUnityShaderPassSettings(_material, alphaMode, zWriteMode, renderQueueOffset, doubleSidedMode); + SetUnityShaderVariants(_material); } - private static void SetUnityRenderSettings(Material material, AlphaMode alphaMode, TransparentWithZWriteMode zWriteMode) + private static void SetUnityShaderPassSettings(Material material, AlphaMode alphaMode, TransparentWithZWriteMode zWriteMode, int renderQueueOffset, DoubleSidedMode doubleSidedMode) { material.SetInt(Prop.AlphaMode, (int) alphaMode); material.SetInt(Prop.TransparentWithZWrite, (int) zWriteMode); + material.SetInt(Prop.DoubleSided, (int) doubleSidedMode); switch (alphaMode) { @@ -33,9 +37,8 @@ namespace VRMShaders.VRM10.MToon10.Editor material.SetInt(Prop.UnityDstBlend, (int) BlendMode.Zero); material.SetInt(Prop.UnityZWrite, (int) UnityZWriteMode.On); material.SetInt(Prop.UnityAlphaToMask, (int) UnityAlphaToMaskMode.Off); - material.SetKeyword(UnityAlphaModeKeyword.AlphaTest, false); - material.SetKeyword(UnityAlphaModeKeyword.AlphaBlend, false); - material.SetKeyword(UnityAlphaModeKeyword.AlphaPremultiply, false); + + renderQueueOffset = 0; material.renderQueue = (int) RenderQueue.Geometry; break; case AlphaMode.Cutout: @@ -44,9 +47,8 @@ namespace VRMShaders.VRM10.MToon10.Editor material.SetInt(Prop.UnityDstBlend, (int) BlendMode.Zero); material.SetInt(Prop.UnityZWrite, (int) UnityZWriteMode.On); material.SetInt(Prop.UnityAlphaToMask, (int) UnityAlphaToMaskMode.On); - material.SetKeyword(UnityAlphaModeKeyword.AlphaTest, true); - material.SetKeyword(UnityAlphaModeKeyword.AlphaBlend, false); - material.SetKeyword(UnityAlphaModeKeyword.AlphaPremultiply, false); + + renderQueueOffset = 0; material.renderQueue = (int) RenderQueue.AlphaTest; break; case AlphaMode.Transparent when zWriteMode == TransparentWithZWriteMode.Off: @@ -55,10 +57,9 @@ namespace VRMShaders.VRM10.MToon10.Editor material.SetInt(Prop.UnityDstBlend, (int) BlendMode.OneMinusSrcAlpha); material.SetInt(Prop.UnityZWrite, (int) UnityZWriteMode.Off); material.SetInt(Prop.UnityAlphaToMask, (int) UnityAlphaToMaskMode.Off); - material.SetKeyword(UnityAlphaModeKeyword.AlphaTest, false); - material.SetKeyword(UnityAlphaModeKeyword.AlphaBlend, true); - material.SetKeyword(UnityAlphaModeKeyword.AlphaPremultiply, false); - material.renderQueue = (int) RenderQueue.Transparent; + + renderQueueOffset = Mathf.Clamp(renderQueueOffset, -9, 0); + material.renderQueue = (int) RenderQueue.Transparent + renderQueueOffset; break; case AlphaMode.Transparent when zWriteMode == TransparentWithZWriteMode.On: material.SetOverrideTag(UnityRenderTag.Key, UnityRenderTag.TransparentValue); @@ -66,15 +67,76 @@ namespace VRMShaders.VRM10.MToon10.Editor material.SetInt(Prop.UnityDstBlend, (int) BlendMode.OneMinusSrcAlpha); material.SetInt(Prop.UnityZWrite, (int) UnityZWriteMode.On); material.SetInt(Prop.UnityAlphaToMask, (int) UnityAlphaToMaskMode.Off); - material.SetKeyword(UnityAlphaModeKeyword.AlphaTest, false); - material.SetKeyword(UnityAlphaModeKeyword.AlphaBlend, true); - material.SetKeyword(UnityAlphaModeKeyword.AlphaPremultiply, false); - material.renderQueue = (int) RenderQueue.GeometryLast + 1; // Transparent First + + renderQueueOffset = Mathf.Clamp(renderQueueOffset, 0, +9); + material.renderQueue = (int) RenderQueue.GeometryLast + 1 + renderQueueOffset; // Transparent First + N break; default: - SetUnityRenderSettings(material, AlphaMode.Opaque, TransparentWithZWriteMode.Off); - break; + throw new ArgumentOutOfRangeException(nameof(alphaMode), alphaMode, null); } + + switch (doubleSidedMode) + { + case DoubleSidedMode.Off: + material.SetInt(Prop.UnityCullMode, (int) CullMode.Back); + break; + case DoubleSidedMode.On: + material.SetInt(Prop.UnityCullMode, (int) CullMode.Off); + break; + default: + throw new ArgumentOutOfRangeException(nameof(doubleSidedMode), doubleSidedMode, null); + } + + // Set after validation + material.SetInt(Prop.RenderQueueOffsetNumber, renderQueueOffset); + } + + private static void SetUnityCullingSettings(Material material, DoubleSidedMode doubleSidedMode) + { + + } + + private static void SetUnityShaderVariants(Material material) + { + material.SetKeyword( + UnityAlphaModeKeyword.AlphaTest, + (AlphaMode) material.GetInt(Prop.AlphaMode) == AlphaMode.Cutout + ); + material.SetKeyword( + UnityAlphaModeKeyword.AlphaBlend, + (AlphaMode) material.GetInt(Prop.AlphaMode) == AlphaMode.Transparent + ); + material.SetKeyword( + UnityAlphaModeKeyword.AlphaPremultiply, + false + ); + material.SetKeyword( + NormalMapKeyword.On, + material.GetTexture(Prop.NormalTexture) != null + ); + material.SetKeyword( + EmissiveMapKeyword.On, + material.GetTexture(Prop.EmissiveTexture) != null + ); + material.SetKeyword( + RimMapKeyword.On, + material.GetTexture(Prop.MatcapTexture) != null || // Matcap + material.GetTexture(Prop.RimMultiplyTexture) != null // Rim + ); + material.SetKeyword( + ParameterMapKeyword.On, + material.GetTexture(Prop.ShadingShiftTexture) != null || // Shading Shift (R) + material.GetTexture(Prop.OutlineWidthMultiplyTexture) != null || // Outline Width (G) + material.GetTexture(Prop.UvAnimationMaskTexture) != null // UV Anim Mask (B) + ); + material.SetKeyword( + OutlineModeKeyword.World, + (OutlineMode) material.GetInt(Prop.OutlineWidthMode) == OutlineMode.World + ); + material.SetKeyword( + OutlineModeKeyword.Screen, + (OutlineMode) material.GetInt(Prop.OutlineWidthMode) == OutlineMode.Screen + ); } } } \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/MaterialExtensions.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/MaterialExtensions.cs index a9a5c3ba0..4e16d4547 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Editor/MaterialExtensions.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/MaterialExtensions.cs @@ -25,5 +25,10 @@ namespace VRMShaders.VRM10.MToon10.Editor { mat.SetInt(prop.ToName(), val); } + + public static Texture GetTexture(this Material mat, Prop prop) + { + return mat.GetTexture(prop.ToName()); + } } } \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/Prop.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/Prop.cs index 31b369a55..da59898a2 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Editor/Prop.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/Prop.cs @@ -11,6 +11,43 @@ // Lighting BaseColorFactor, + BaseColorTexture, + ShadeColorFactor, + ShadeColorTexture, + NormalTexture, + NormalTextureScale, + ShadingShiftFactor, + ShadingShiftTexture, + ShadingShiftTextureScale, + ShadingToonyFactor, + + // GI + GiEqualizationFactor, + + // Emission + EmissiveFactor, + EmissiveTexture, + + // Rim Lighting + MatcapTexture, + ParametricRimColorFactor, + ParametricRimFresnelPowerFactor, + ParametricRimLiftFactor, + RimMultiplyTexture, + RimLightingMixFactor, + + // Outline + OutlineWidthMode, + OutlineWidthFactor, + OutlineWidthMultiplyTexture, + OutlineColorFactor, + OutlineLightingMixFactor, + + // UV Animation + UvAnimationMaskTexture, + UvAnimationScrollXSpeedFactor, + UvAnimationScrollYSpeedFactor, + UvAnimationRotationSpeedFactor, // Unity Required UnityCullMode, diff --git a/Assets/VRMShaders/VRM10/MToon10/Editor/PropExtensions.cs b/Assets/VRMShaders/VRM10/MToon10/Editor/PropExtensions.cs index 795ae0e8a..33be0e628 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Editor/PropExtensions.cs +++ b/Assets/VRMShaders/VRM10/MToon10/Editor/PropExtensions.cs @@ -11,7 +11,41 @@ namespace VRMShaders.VRM10.MToon10.Editor [Prop.AlphaCutoff] = "_Cutoff", [Prop.RenderQueueOffsetNumber] = "_RenderQueueOffset", [Prop.DoubleSided] = "_DoubleSided", + [Prop.BaseColorFactor] = "_Color", + [Prop.BaseColorTexture] = "_MainTex", + [Prop.ShadeColorFactor] = "_ShadeColor", + [Prop.ShadeColorTexture] = "_ShadeTex", + [Prop.NormalTexture] = "_BumpMap", + [Prop.NormalTextureScale] = "_BumpScale", + [Prop.ShadingShiftFactor] = "_ShadingShiftFactor", + [Prop.ShadingShiftTexture] = "_ShadingShiftTex", + [Prop.ShadingShiftTextureScale] = "_ShadingShiftTexScale", + [Prop.ShadingToonyFactor] = "_ShadingToonyFactor", + + [Prop.GiEqualizationFactor] = "_GiEqualization", + + [Prop.EmissiveFactor] = "_EmissionColor", + [Prop.EmissiveTexture] = "_EmissionMap", + + [Prop.MatcapTexture] = "_MatcapTex", + [Prop.ParametricRimColorFactor] = "_RimColor", + [Prop.ParametricRimFresnelPowerFactor] = "_RimFresnelPower", + [Prop.ParametricRimLiftFactor] = "_RimLift", + [Prop.RimMultiplyTexture] = "_RimTex", + [Prop.RimLightingMixFactor] = "_RimLightingMix", + + [Prop.OutlineWidthMode] = "_OutlineWidthMode", + [Prop.OutlineWidthFactor] = "_OutlineWidth", + [Prop.OutlineWidthMultiplyTexture] = "_OutlineWidthTex", + [Prop.OutlineColorFactor] = "_OutlineColor", + [Prop.OutlineLightingMixFactor] = "_OutlineLightingMix", + + [Prop.UvAnimationMaskTexture] = "_UvAnimMaskTex", + [Prop.UvAnimationScrollXSpeedFactor] = "_UvAnimScrollXSpeed", + [Prop.UvAnimationScrollYSpeedFactor] = "_UvAnimScrollYSpeed", + [Prop.UvAnimationRotationSpeedFactor] = "_UvAnimRotationSpeed", + [Prop.UnityCullMode] = "_M_CullMode", [Prop.UnitySrcBlend] = "_M_SrcBlend", [Prop.UnityDstBlend] = "_M_DstBlend", 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 7ff2cfa53..beae6a3c5 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon.shader @@ -33,17 +33,17 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" // Rim Lighting _MatcapTex ("mtoon.matcapTexture", 2D) = "black" {} _RimColor ("mtoon.parametricRimColorFactor", Color) = (0, 0, 0, 1) - _RimFresnelPower ("mtoon.parametricRimFresnelPowerFactor", Float) = 5.0 - _RimLift ("mtoon.parametricRimLiftFactor", Float) = 0 + _RimFresnelPower ("mtoon.parametricRimFresnelPowerFactor", Range(0, 100)) = 5.0 + _RimLift ("mtoon.parametricRimLiftFactor", Range(0, 1)) = 0 _RimTex ("mtoon.rimMultiplyTexture", 2D) = "white" {} - _RimLightingMix ("mtoon.rimLightingMixFactor", Float) = 1 + _RimLightingMix ("mtoon.rimLightingMixFactor", Range(0, 1)) = 1 // Outline _OutlineWidthMode ("mtoon.outlineWidthMode", Int) = 0 - _OutlineWidth ("mtoon.outlineWidthFactor", Float) = 0 + [PowerSlider(2.2)] _OutlineWidth ("mtoon.outlineWidthFactor", Range(0, 0.05)) = 0 _OutlineWidthTex ("mtoon.outlineWidthMultiplyTexture", 2D) = "white" {} // channel G _OutlineColor ("mtoon.outlineColorFactor", Color) = (0, 0, 0, 1) - _OutlineLightingMix ("mtoon.outlineLightingMixFactor", Float) = 1 + _OutlineLightingMix ("mtoon.outlineLightingMixFactor", Range(0, 1)) = 1 // UV Animation _UvAnimMaskTex ("mtoon.uvAnimationMaskTexture", 2D) = "white" {} // channel B @@ -91,6 +91,7 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" #pragma multi_compile_local __ _ALPHATEST_ON _ALPHABLEND_ON #pragma multi_compile_local __ _NORMALMAP #pragma multi_compile_local __ _MTOON_EMISSIVEMAP + #pragma multi_compile_local __ _MTOON_RIMMAP #pragma multi_compile_local __ _MTOON_PARAMETERMAP #pragma vertex MToonVertex @@ -125,7 +126,9 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" #pragma multi_compile_local __ _ALPHATEST_ON _ALPHABLEND_ON #pragma multi_compile_local __ _NORMALMAP #pragma multi_compile_local __ _MTOON_EMISSIVEMAP + #pragma multi_compile_local __ _MTOON_RIMMAP #pragma multi_compile_local __ _MTOON_PARAMETERMAP + #pragma multi_compile_local __ _MTOON_OUTLINE_WORLD _MTOON_OUTLINE_SCREEN #define MTOON_PASS_OUTLINE @@ -161,6 +164,7 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" #pragma multi_compile_local __ _ALPHATEST_ON _ALPHABLEND_ON #pragma multi_compile_local __ _NORMALMAP #pragma multi_compile_local __ _MTOON_EMISSIVEMAP + #pragma multi_compile_local __ _MTOON_RIMMAP #pragma multi_compile_local __ _MTOON_PARAMETERMAP #pragma vertex MToonVertex @@ -186,6 +190,7 @@ Shader "Hidden/VRM10/vrmc_materials_mtoon" // Unity defined keywords #pragma multi_compile_shadowcaster nolightmap nodynlightmap nodirlightmap novertexlight + #pragma multi_compile_instancing #pragma multi_compile_local __ _ALPHATEST_ON _ALPHABLEND_ON 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 59cad75b6..adfbe8d1c 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 @@ -48,6 +48,16 @@ inline bool MToon_IsEmissiveMapOn() #endif } +// Compile-time constant +inline bool MToon_IsRimMapOn() +{ +#if defined(_MTOON_RIMMAP) + return true; +#else + return false; +#endif +} + // Compile-time constant inline bool MToon_IsParameterMapOn() { @@ -61,7 +71,7 @@ inline bool MToon_IsParameterMapOn() // Compile-time constant inline bool MToon_IsOutlineModeWorldCoordinates() { - #if defined(MTOON_OUTLINE_WIDTH_WORLD) + #if defined(_MTOON_OUTLINE_WORLD) return true; #else return false; @@ -71,11 +81,21 @@ inline bool MToon_IsOutlineModeWorldCoordinates() // Compile-time constant inline bool MToon_IsOutlineModeScreenCoordinates() { - #if defined(MTOON_OUTLINE_WIDTH_SCREEN) + #if defined(_MTOON_OUTLINE_SCREEN) return true; #else return false; #endif } +// Compile-time constant +inline bool MToon_IsOutlineModeDisabled() +{ + #if defined(_MTOON_OUTLINE_WORLD) || defined(_MTOON_OUTLINE_SCREEN) + return false; +#else + return true; +#endif +} + #endif diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl index 5d9dc4a57..32973855f 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_forward_fragment.hlsl @@ -13,6 +13,11 @@ half4 MToonFragment(const Varyings input) : SV_Target { + if (MToon_IsOutlinePass() && MToon_IsOutlineModeDisabled()) + { + clip(-1); + } + // Get MToon UV (with UVAnimation) const float2 uv = GetMToonGeometry_Uv(input.uv); diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl index ed1f1556c..5a9e9ac46 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_uv.hlsl @@ -23,20 +23,13 @@ inline float2 GetMToonGeometry_Uv(const float2 geometryUv) // get raw uv with _MainTex_ST const float2 uvRaw = TRANSFORM_TEX(geometryUv, _MainTex); - if (MToon_IsParameterMapOn()) - { - const float uvAnimationTime = GetMToonGeometry_Uv_Time(uvRaw); - const float2 translate = uvAnimationTime * float2(_UvAnimScrollXSpeed, _UvAnimScrollYSpeed); - const float rotateRad = uvAnimationTime * _UvAnimRotationSpeed * PI_2; - const float cosRotate = cos(rotateRad); - const float sinRotate = sin(rotateRad); - const float2 rotatePivot = float2(0.5, 0.5); - return mul(float2x2(cosRotate, -sinRotate, sinRotate, cosRotate), uvRaw + translate - rotatePivot) + rotatePivot; - } - else - { - return uvRaw; - } + const float uvAnimationTime = GetMToonGeometry_Uv_Time(uvRaw); + const float2 translate = uvAnimationTime * float2(_UvAnimScrollXSpeed, _UvAnimScrollYSpeed); + const float rotateRad = frac(uvAnimationTime * _UvAnimRotationSpeed) * PI_2; + const float cosRotate = cos(rotateRad); + const float sinRotate = sin(rotateRad); + const float2 rotatePivot = float2(0.5, 0.5); + return mul(float2x2(cosRotate, -sinRotate, sinRotate, cosRotate), uvRaw + translate - rotatePivot) + rotatePivot; } #endif diff --git a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl index d9c024edc..6bbec95c2 100644 --- a/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl +++ b/Assets/VRMShaders/VRM10/MToon10/Resources/VRM10/vrmc_materials_mtoon_geometry_vertex.hlsl @@ -40,7 +40,7 @@ inline VertexPositionInfo MToon_GetOutlineVertex(const float3 positionOS, const else if (MToon_IsOutlineModeScreenCoordinates()) { const float3 positionWS = mul(unity_ObjectToWorld, float4(positionOS, 1)).xyz; - const half outlineWidth = _OutlineWidth * UNITY_SAMPLE_TEX2D_LOD(_OutlineWidthTex, uv, 0); + const half outlineWidth = MToon_GetOutlineVertex_OutlineWidth(uv); const float4 nearUpperRight = mul(unity_CameraInvProjection, float4(1, 1, UNITY_NEAR_CLIP_VALUE, _ProjectionParams.y)); const half aspect = abs(nearUpperRight.y / nearUpperRight.x); @@ -61,7 +61,7 @@ inline VertexPositionInfo MToon_GetOutlineVertex(const float3 positionOS, const else { VertexPositionInfo output; - output.positionWS = mul(unity_ObjectToWorld, float4(positionOS, 1)); + output.positionWS = mul(unity_ObjectToWorld, float4(positionOS * 0.001, 1)); output.positionCS = UnityWorldToClipPos(output.positionWS); return output; } 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 d701769fa..9727c262a 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 @@ -79,7 +79,7 @@ inline half3 GetMToonLighting_Emissive(const MToonInput input) inline half3 GetMToonLighting_Rim_Matcap(const MToonInput input) { - if (MToon_IsParameterMapOn()) + if (MToon_IsRimMapOn()) { const half3 worldUpWS = half3(0, 1, 0); // TODO: use view space axis if abs(dot(viewDir, worldUp)) == 1.0 @@ -101,7 +101,15 @@ inline half3 GetMToonLighting_Rim(const MToonInput input, const half3 lighting) const half3 parametricRimFactor = pow(saturate(1.0 - dot(input.normalWS, input.viewDirWS) + _RimLift), _RimFresnelPower) * _RimColor.rgb; const half3 rimLightingFactor = lerp(half3(1, 1, 1), lighting, _RimLightingMix); const half3 matcapFactor = GetMToonLighting_Rim_Matcap(input); - return (matcapFactor + parametricRimFactor) * UNITY_SAMPLE_TEX2D(_RimTex, input.uv).rgb * rimLightingFactor; + + if (MToon_IsRimMapOn()) + { + return (matcapFactor + parametricRimFactor) * rimLightingFactor * UNITY_SAMPLE_TEX2D(_RimTex, input.uv).rgb; + } + else + { + return (matcapFactor + parametricRimFactor) * rimLightingFactor; + } } else {