diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X.meta b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X.meta new file mode 100644 index 000000000..1ad464f3b --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 877449241d1d463dae7623e78e27a772 +timeCreated: 1716647773 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XDefinition.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XDefinition.cs new file mode 100644 index 000000000..aebe2de99 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XDefinition.cs @@ -0,0 +1,109 @@ +using UnityEngine; + +namespace VRMShaders.VRM10.MToon10.Runtime.MToon0X +{ + public class MToon0XDefinition + { + public MToon0XMetaDefinition Meta; + public MToon0XRenderingDefinition Rendering; + public MToon0XColorDefinition Color; + public MToon0XLightingDefinition Lighting; + public MToon0XEmissionDefinition Emission; + public MToon0XMatCapDefinition MatCap; + public MToon0XRimDefinition Rim; + public MToon0XOutlineDefinition Outline; + public MToon0XTextureUvCoordsDefinition TextureOption; + } + + public class MToon0XMetaDefinition + { + public string Implementation; + public int VersionNumber; + } + + public class MToon0XRenderingDefinition + { + public MToon0XRenderMode RenderMode; + public MToon0XCullMode CullMode; + public int RenderQueueOffsetNumber; + } + + public class MToon0XColorDefinition + { + public Color LitColor; + public Texture2D LitMultiplyTexture; + public Color ShadeColor; + public Texture2D ShadeMultiplyTexture; + public float CutoutThresholdValue; + } + + public class MToon0XLightingDefinition + { + public MToon0XLitAndShadeMixingDefinition LitAndShadeMixing; + public MToon0XLightingInfluenceDefinition LightingInfluence; + public MToon0XNormalDefinition Normal; + } + + public class MToon0XLitAndShadeMixingDefinition + { + public float ShadingShiftValue; + public float ShadingToonyValue; + public float ShadowReceiveMultiplierValue; + public Texture2D ShadowReceiveMultiplierMultiplyTexture; + public float LitAndShadeMixingMultiplierValue; + public Texture2D LitAndShadeMixingMultiplierMultiplyTexture; + } + + public class MToon0XLightingInfluenceDefinition + { + public float LightColorAttenuationValue; + public float GiIntensityValue; + } + + public class MToon0XEmissionDefinition + { + public Color EmissionColor; + public Texture2D EmissionMultiplyTexture; + } + + public class MToon0XMatCapDefinition + { + public Texture2D AdditiveTexture; + } + + public class MToon0XRimDefinition + { + public Color RimColor; + public Texture2D RimMultiplyTexture; + public float RimLightingMixValue; + public float RimFresnelPowerValue; + public float RimLiftValue; + } + + public class MToon0XNormalDefinition + { + public Texture2D NormalTexture; + public float NormalScaleValue; + } + + public class MToon0XOutlineDefinition + { + public MToon0XOutlineWidthMode OutlineWidthMode; + public float OutlineWidthValue; + public Texture2D OutlineWidthMultiplyTexture; + public float OutlineScaledMaxDistanceValue; + public MToon0XOutlineColorMode OutlineColorMode; + public Color OutlineColor; + public float OutlineLightingMixValue; + } + + public class MToon0XTextureUvCoordsDefinition + { + public Vector2 MainTextureLeftBottomOriginScale; + public Vector2 MainTextureLeftBottomOriginOffset; + public Texture2D UvAnimationMaskTexture; + public float UvAnimationScrollXSpeedValue; + public float UvAnimationScrollYSpeedValue; + public float UvAnimationRotationSpeedValue; + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XDefinition.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XDefinition.cs.meta new file mode 100644 index 000000000..b9ce31a66 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XDefinition.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 21bea29fcd9a4f15981b4c6c33ac9d87 +timeCreated: 1716647784 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XEnums.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XEnums.cs new file mode 100644 index 000000000..babee5172 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XEnums.cs @@ -0,0 +1,44 @@ +namespace VRMShaders.VRM10.MToon10.Runtime.MToon0X +{ + public enum MToon0XDebugMode + { + None = 0, + Normal = 1, + LitShadeRate = 2, + } + + public enum MToon0XOutlineColorMode + { + FixedColor = 0, + MixedLighting = 1, + } + + public enum MToon0XOutlineWidthMode + { + None = 0, + WorldCoordinates = 1, + ScreenCoordinates = 2, + } + + public enum MToon0XRenderMode + { + Opaque = 0, + Cutout = 1, + Transparent = 2, + TransparentWithZWrite = 3, + } + + public enum MToon0XCullMode + { + Off = 0, + Front = 1, + Back = 2, + } + + public struct MToon0XRenderQueueRequirement + { + public int DefaultValue; + public int MinValue; + public int MaxValue; + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XEnums.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XEnums.cs.meta new file mode 100644 index 000000000..21d72e8f8 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XEnums.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1214b566b5cd4dc390d11b3bed7f2a50 +timeCreated: 1716647818 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtils.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtils.cs new file mode 100644 index 000000000..485bdc875 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtils.cs @@ -0,0 +1,116 @@ +using System; +using UnityEngine; +using UnityEngine.Rendering; + +namespace VRMShaders.VRM10.MToon10.Runtime.MToon0X +{ + public static partial class MToon0XUtils + { + public const string ShaderName = "VRM/MToon"; + + public const string PropVersion = "_MToonVersion"; + public const string PropDebugMode = "_DebugMode"; + public const string PropOutlineWidthMode = "_OutlineWidthMode"; + public const string PropOutlineColorMode = "_OutlineColorMode"; + public const string PropBlendMode = "_BlendMode"; + public const string PropCullMode = "_CullMode"; + public const string PropOutlineCullMode = "_OutlineCullMode"; + public const string PropCutoff = "_Cutoff"; + public const string PropColor = "_Color"; + public const string PropShadeColor = "_ShadeColor"; + public const string PropMainTex = "_MainTex"; + public const string PropShadeTexture = "_ShadeTexture"; + public const string PropBumpScale = "_BumpScale"; + public const string PropBumpMap = "_BumpMap"; + public const string PropReceiveShadowRate = "_ReceiveShadowRate"; + public const string PropReceiveShadowTexture = "_ReceiveShadowTexture"; + public const string PropShadingGradeRate = "_ShadingGradeRate"; + public const string PropShadingGradeTexture = "_ShadingGradeTexture"; + public const string PropShadeShift = "_ShadeShift"; + public const string PropShadeToony = "_ShadeToony"; + public const string PropLightColorAttenuation = "_LightColorAttenuation"; + public const string PropIndirectLightIntensity = "_IndirectLightIntensity"; + public const string PropRimColor = "_RimColor"; + public const string PropRimTexture = "_RimTexture"; + public const string PropRimLightingMix = "_RimLightingMix"; + public const string PropRimFresnelPower = "_RimFresnelPower"; + public const string PropRimLift = "_RimLift"; + public const string PropSphereAdd = "_SphereAdd"; + public const string PropEmissionColor = "_EmissionColor"; + public const string PropEmissionMap = "_EmissionMap"; + public const string PropOutlineWidthTexture = "_OutlineWidthTexture"; + public const string PropOutlineWidth = "_OutlineWidth"; + public const string PropOutlineScaledMaxDistance = "_OutlineScaledMaxDistance"; + public const string PropOutlineColor = "_OutlineColor"; + public const string PropOutlineLightingMix = "_OutlineLightingMix"; + public const string PropUvAnimMaskTexture = "_UvAnimMaskTexture"; + public const string PropUvAnimScrollX = "_UvAnimScrollX"; + public const string PropUvAnimScrollY = "_UvAnimScrollY"; + public const string PropUvAnimRotation = "_UvAnimRotation"; + public const string PropSrcBlend = "_SrcBlend"; + public const string PropDstBlend = "_DstBlend"; + public const string PropZWrite = "_ZWrite"; + public const string PropAlphaToMask = "_AlphaToMask"; + + public const string KeyNormalMap = "_NORMALMAP"; + public const string KeyAlphaTestOn = "_ALPHATEST_ON"; + public const string KeyAlphaBlendOn = "_ALPHABLEND_ON"; + public const string KeyAlphaPremultiplyOn = "_ALPHAPREMULTIPLY_ON"; + public const string KeyOutlineWidthWorld = "MTOON_OUTLINE_WIDTH_WORLD"; + public const string KeyOutlineWidthScreen = "MTOON_OUTLINE_WIDTH_SCREEN"; + public const string KeyOutlineColorFixed = "MTOON_OUTLINE_COLOR_FIXED"; + public const string KeyOutlineColorMixed = "MTOON_OUTLINE_COLOR_MIXED"; + public const string KeyDebugNormal = "MTOON_DEBUG_NORMAL"; + public const string KeyDebugLitShadeRate = "MTOON_DEBUG_LITSHADERATE"; + + public const string TagRenderTypeKey = "RenderType"; + public const string TagRenderTypeValueOpaque = "Opaque"; + public const string TagRenderTypeValueTransparentCutout = "TransparentCutout"; + public const string TagRenderTypeValueTransparent = "Transparent"; + + public const int DisabledIntValue = 0; + public const int EnabledIntValue = 1; + + public static MToon0XRenderQueueRequirement GetRenderQueueRequirement(MToon0XRenderMode renderMode) + { + const int shaderDefaultQueue = -1; + const int firstTransparentQueue = 2501; + const int spanOfQueue = 50; + + switch (renderMode) + { + case MToon0XRenderMode.Opaque: + return new MToon0XRenderQueueRequirement() + { + DefaultValue = shaderDefaultQueue, + MinValue = shaderDefaultQueue, + MaxValue = shaderDefaultQueue, + }; + case MToon0XRenderMode.Cutout: + return new MToon0XRenderQueueRequirement() + { + DefaultValue = (int) RenderQueue.AlphaTest, + MinValue = (int) RenderQueue.AlphaTest, + MaxValue = (int) RenderQueue.AlphaTest, + }; + case MToon0XRenderMode.Transparent: + return new MToon0XRenderQueueRequirement() + { + DefaultValue = (int) RenderQueue.Transparent, + MinValue = (int) RenderQueue.Transparent - spanOfQueue + 1, + MaxValue = (int) RenderQueue.Transparent, + }; + case MToon0XRenderMode.TransparentWithZWrite: + return new MToon0XRenderQueueRequirement() + { + DefaultValue = firstTransparentQueue, + MinValue = firstTransparentQueue, + MaxValue = firstTransparentQueue + spanOfQueue - 1, + }; + default: + throw new ArgumentOutOfRangeException("renderMode", renderMode, null); + } + } + + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtils.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtils.cs.meta new file mode 100644 index 000000000..bad073d10 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 19cbe2ec05fb49daa74a8728583dcdf6 +timeCreated: 1716647798 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsGetter.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsGetter.cs new file mode 100644 index 000000000..795ee2f8e --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsGetter.cs @@ -0,0 +1,180 @@ +using System; +using UnityEngine; + +namespace VRMShaders.VRM10.MToon10.Runtime.MToon0X +{ + public static partial class MToon0XUtils + { + public static MToon0XDefinition GetMToonParametersFromMaterial(Material material) + { + return new MToon0XDefinition + { + Meta = new MToon0XMetaDefinition + { + Implementation = Implementation, + VersionNumber = material.GetInt(PropVersion), + }, + Rendering = new MToon0XRenderingDefinition + { + RenderMode = GetBlendMode(material), + CullMode = GetCullMode(material), + RenderQueueOffsetNumber = GetRenderQueueOffset(material, GetRenderQueueOriginMode(material)), + }, + Color = new MToon0XColorDefinition + { + LitColor = GetColor(material, PropColor), + LitMultiplyTexture = GetTexture(material, PropMainTex), + ShadeColor = GetColor(material, PropShadeColor), + ShadeMultiplyTexture = GetTexture(material, PropShadeTexture), + CutoutThresholdValue = GetValue(material, PropCutoff), + }, + Lighting = new MToon0XLightingDefinition + { + LitAndShadeMixing = new MToon0XLitAndShadeMixingDefinition + { + ShadingShiftValue = GetValue(material, PropShadeShift), + ShadingToonyValue = GetValue(material, PropShadeToony), + ShadowReceiveMultiplierValue = GetValue(material, PropReceiveShadowRate), + ShadowReceiveMultiplierMultiplyTexture = GetTexture(material, PropReceiveShadowTexture), + LitAndShadeMixingMultiplierValue = GetValue(material, PropShadingGradeRate), + LitAndShadeMixingMultiplierMultiplyTexture = GetTexture(material, PropShadingGradeTexture), + }, + LightingInfluence = new MToon0XLightingInfluenceDefinition + { + LightColorAttenuationValue = GetValue(material, PropLightColorAttenuation), + GiIntensityValue = GetValue(material, PropIndirectLightIntensity), + }, + Normal = new MToon0XNormalDefinition + { + NormalTexture = GetTexture(material, PropBumpMap), + NormalScaleValue = GetValue(material, PropBumpScale), + }, + }, + Emission = new MToon0XEmissionDefinition + { + EmissionColor = GetColor(material, PropEmissionColor), + EmissionMultiplyTexture = GetTexture(material, PropEmissionMap), + }, + MatCap = new MToon0XMatCapDefinition + { + AdditiveTexture = GetTexture(material, PropSphereAdd), + }, + Rim = new MToon0XRimDefinition + { + RimColor = GetColor(material, PropRimColor), + RimMultiplyTexture = GetTexture(material, PropRimTexture), + RimLightingMixValue = GetValue(material, PropRimLightingMix), + RimFresnelPowerValue = GetValue(material, PropRimFresnelPower), + RimLiftValue = GetValue(material, PropRimLift), + }, + Outline = new MToon0XOutlineDefinition + { + OutlineWidthMode = GetOutlineWidthMode(material), + OutlineWidthValue = GetValue(material, PropOutlineWidth), + OutlineWidthMultiplyTexture = GetTexture(material, PropOutlineWidthTexture), + OutlineScaledMaxDistanceValue = GetValue(material, PropOutlineScaledMaxDistance), + OutlineColorMode = GetOutlineColorMode(material), + OutlineColor = GetColor(material, PropOutlineColor), + OutlineLightingMixValue = GetValue(material, PropOutlineLightingMix), + }, + TextureOption = new MToon0XTextureUvCoordsDefinition + { + MainTextureLeftBottomOriginScale = material.GetTextureScale(PropMainTex), + MainTextureLeftBottomOriginOffset = material.GetTextureOffset(PropMainTex), + UvAnimationMaskTexture = GetTexture(material, PropUvAnimMaskTexture), + UvAnimationScrollXSpeedValue = GetValue(material, PropUvAnimScrollX), + UvAnimationScrollYSpeedValue = GetValue(material, PropUvAnimScrollY), + UvAnimationRotationSpeedValue = GetValue(material, PropUvAnimRotation), + }, + }; + } + + private static float GetValue(Material material, string propertyName) + { + return material.GetFloat(propertyName); + } + + private static Color GetColor(Material material, string propertyName) + { + return material.GetColor(propertyName); + } + + private static Texture2D GetTexture(Material material, string propertyName) + { + return (Texture2D) material.GetTexture(propertyName); + } + + private static MToon0XRenderMode GetBlendMode(Material material) + { + if (material.IsKeywordEnabled(KeyAlphaTestOn)) + { + return MToon0XRenderMode.Cutout; + } + else if (material.IsKeywordEnabled(KeyAlphaBlendOn)) + { + switch (material.GetInt(PropZWrite)) + { + case EnabledIntValue: + return MToon0XRenderMode.TransparentWithZWrite; + case DisabledIntValue: + return MToon0XRenderMode.Transparent; + default: + Debug.LogWarning("Invalid ZWrite Int Value."); + return MToon0XRenderMode.Transparent; + } + } + else + { + return MToon0XRenderMode.Opaque; + } + } + + private static MToon0XCullMode GetCullMode(Material material) + { + switch ((MToon0XCullMode) material.GetInt(PropCullMode)) + { + case MToon0XCullMode.Off: + return MToon0XCullMode.Off; + case MToon0XCullMode.Front: + return MToon0XCullMode.Front; + case MToon0XCullMode.Back: + return MToon0XCullMode.Back; + default: + Debug.LogWarning("Invalid CullMode."); + return MToon0XCullMode.Back; + } + } + + private static MToon0XOutlineWidthMode GetOutlineWidthMode(Material material) + { + if (material.IsKeywordEnabled(KeyOutlineWidthWorld)) return MToon0XOutlineWidthMode.WorldCoordinates; + if (material.IsKeywordEnabled(KeyOutlineWidthScreen)) return MToon0XOutlineWidthMode.ScreenCoordinates; + + return MToon0XOutlineWidthMode.None; + } + + private static MToon0XOutlineColorMode GetOutlineColorMode(Material material) + { + if (material.IsKeywordEnabled(KeyOutlineColorFixed)) return MToon0XOutlineColorMode.FixedColor; + if (material.IsKeywordEnabled(KeyOutlineColorMixed)) return MToon0XOutlineColorMode.MixedLighting; + + return MToon0XOutlineColorMode.FixedColor; + } + + private static MToon0XRenderMode GetRenderQueueOriginMode(Material material) + { + return GetBlendMode(material); + } + + private static int GetRenderQueueOffset(Material material, MToon0XRenderMode originMode) + { + var rawValue = material.renderQueue; + var requirement = GetRenderQueueRequirement(originMode); + if (rawValue < requirement.MinValue || rawValue > requirement.MaxValue) + { + return 0; + } + return rawValue - requirement.DefaultValue; + } + } +} \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsGetter.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsGetter.cs.meta new file mode 100644 index 000000000..159daf07f --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsGetter.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: efe45d6033e1413d8273a411c9fab601 +timeCreated: 1716647798 \ No newline at end of file diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsVersion.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsVersion.cs new file mode 100644 index 000000000..bd8bb40aa --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsVersion.cs @@ -0,0 +1,8 @@ +namespace VRMShaders.VRM10.MToon10.Runtime.MToon0X +{ + public static partial class MToon0XUtils + { + public const string Implementation = "Santarh/MToon"; + public const int VersionNumber = 39; + } +} diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsVersion.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsVersion.cs.meta new file mode 100644 index 000000000..537ad4128 --- /dev/null +++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/MToon0X/MToon0XUtilsVersion.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 48606eb94ede4ce88f49a8abf19b8b26 +timeCreated: 1716647836 \ No newline at end of file