Merge pull request #1015 from Santarh/mtoon2

Implements vrmc_materials_mtoon inspector
This commit is contained in:
ousttrue 2021-06-09 11:55:36 +09:00 committed by GitHub
commit 9f3cbfc1f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 461 additions and 54 deletions

View File

@ -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();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: af7abf08bb63495fae1f334377be0b23
timeCreated: 1623133727

View File

@ -0,0 +1,8 @@
namespace VRMShaders.VRM10.MToon10.Editor
{
public enum DoubleSidedMode
{
Off = 0,
On = 1,
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c3c422f6c0ac416bbcd70ee3203bca6a
timeCreated: 1623135734

View File

@ -0,0 +1,7 @@
namespace VRMShaders.VRM10.MToon10.Editor
{
public static class EmissiveMapKeyword
{
public const string On = "_MTOON_EMISSIVEMAP";
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c9f4547527b3411aa87d8322ce9d9132
timeCreated: 1623144877

View File

@ -0,0 +1,7 @@
namespace VRMShaders.VRM10.MToon10.Editor
{
public static class NormalMapKeyword
{
public const string On = "_NORMALMAP";
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 78ea3fe03cac402083bd53882d186b95
timeCreated: 1623144639

View File

@ -0,0 +1,9 @@
namespace VRMShaders.VRM10.MToon10.Editor
{
public enum OutlineMode
{
None = 0,
World = 1,
Screen = 2,
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8aece52be2cb42de9bfde4a072e5a6a0
timeCreated: 1623149007

View File

@ -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";
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 94313b3f0f4943d681f40e4cfbd5b600
timeCreated: 1623144868

View File

@ -0,0 +1,7 @@
namespace VRMShaders.VRM10.MToon10.Editor
{
public static class ParameterMapKeyword
{
public const string On = "_MTOON_PARAMETERMAP";
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4cf6251408b74e228660a1a43f4de9c9
timeCreated: 1623144871

View File

@ -0,0 +1,7 @@
namespace VRMShaders.VRM10.MToon10.Editor
{
public static class RimMapKeyword
{
public const string On = "_MTOON_RIMMAP";
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f22a9af9be334674ad2638be0af0c818
timeCreated: 1623144874

View File

@ -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<AlphaMode>("Alpha Mode", props[Prop.AlphaMode], materialEditor))
PopupEnum<AlphaMode>("Alpha Mode", props[Prop.AlphaMode], materialEditor);
var alphaMode = (AlphaMode) (int) props[Prop.AlphaMode].floatValue;
if (alphaMode == AlphaMode.Transparent)
{
Validate(materials);
PopupEnum<TransparentWithZWriteMode>(
"Transparent With ZWrite Mode",
props[Prop.TransparentWithZWrite],
materialEditor
);
}
if (PopupEnum<TransparentWithZWriteMode>("Transparent With ZWrite Mode", props[Prop.TransparentWithZWrite], materialEditor))
if (alphaMode == AlphaMode.Cutout)
{
Validate(materials);
materialEditor.ShaderProperty(props[Prop.AlphaCutoff], "Cutoff");
}
PopupEnum<DoubleSidedMode>("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<OutlineMode>("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)

View File

@ -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
);
}
}
}

View File

@ -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());
}
}
}

View File

@ -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,

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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
{