diff --git a/Assets/VRM10/Runtime/Migration/MigrationMToon.cs b/Assets/VRM10/Runtime/Migration/MigrationMToon.cs
index 206a81799..514499b14 100644
--- a/Assets/VRM10/Runtime/Migration/MigrationMToon.cs
+++ b/Assets/VRM10/Runtime/Migration/MigrationMToon.cs
@@ -5,6 +5,7 @@ using UniGLTF;
using UniGLTF.Extensions.VRMC_materials_mtoon;
using UniJSON;
using UnityEngine;
+using VRMShaders.VRM10.MToon10.Runtime;
using ColorSpace = VRMShaders.ColorSpace;
using RenderMode = MToon.RenderMode;
@@ -419,9 +420,15 @@ namespace UniVRM10
}
// Light
- dst.GiIntensityFactor = mtoon.Definition.Lighting.LightingInfluence.GiIntensityValue;
- dst.ShadingShiftFactor = mtoon.Definition.Lighting.LitAndShadeMixing.ShadingShiftValue;
- dst.ShadingToonyFactor = mtoon.Definition.Lighting.LitAndShadeMixing.ShadingToonyValue;
+ dst.GiIntensityFactor = MToonMigrator.MigrateToGiEqualization(mtoon.Definition.Lighting.LightingInfluence.GiIntensityValue);
+ dst.ShadingToonyFactor = MToonMigrator.MigrateToShadingToony(
+ mtoon.Definition.Lighting.LitAndShadeMixing.ShadingToonyValue,
+ mtoon.Definition.Lighting.LitAndShadeMixing.ShadingShiftValue
+ );
+ dst.ShadingShiftFactor = MToonMigrator.MigrateToShadingShift(
+ mtoon.Definition.Lighting.LitAndShadeMixing.ShadingToonyValue,
+ mtoon.Definition.Lighting.LitAndShadeMixing.ShadingShiftValue
+ );
if (mtoon.TextureIndexMap.BumpMap.HasValue)
{
gltfMaterial.normalTexture = new glTFMaterialNormalTextureInfo
diff --git a/Assets/VRM10/Runtime/VRM10.asmdef b/Assets/VRM10/Runtime/VRM10.asmdef
index 845518186..2edebf50b 100644
--- a/Assets/VRM10/Runtime/VRM10.asmdef
+++ b/Assets/VRM10/Runtime/VRM10.asmdef
@@ -6,6 +6,7 @@
"UniGLTF",
"VRMShaders.GLTF.IO.Runtime",
"VRMShaders.VRM10.Format.Runtime",
+ "VRMShaders.VRM10.MToon10.Runtime",
"UniHumanoid"
],
"optionalUnityReferences": [],
diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/Migrator.cs b/Assets/VRMShaders/VRM10/MToon10/Runtime/Migrator.cs
new file mode 100644
index 000000000..eda2462bc
--- /dev/null
+++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/Migrator.cs
@@ -0,0 +1,48 @@
+using UnityEngine;
+
+namespace VRMShaders.VRM10.MToon10.Runtime
+{
+ ///
+ /// Migrate from VRM 0.x MToon to VRM 1.0 vrmc_materials_mtoon
+ ///
+ public sealed class MToonMigrator
+ {
+ ///
+ /// mtoon.shadingToonyFactor
+ ///
+ public static float MigrateToShadingToony(float shadingToony0X, float shadingShift0X)
+ {
+ var (rangeMin, rangeMax) = GetShadingRange0X(shadingToony0X, shadingShift0X);
+
+ // new shadingToony is the margin of range.
+ return Mathf.Clamp((2.0f - (rangeMax - rangeMin)) * 0.5f, 0, 1);
+ }
+
+ ///
+ /// mtoon.shadingShiftFactor
+ ///
+ public static float MigrateToShadingShift(float shadingToony0X, float shadingShift0X)
+ {
+ var (rangeMin, rangeMax) = GetShadingRange0X(shadingToony0X, shadingShift0X);
+
+ // new shadingShift is the center of range.
+ return Mathf.Clamp((rangeMax - rangeMin) * 0.5f, -1, +1);
+ }
+
+ ///
+ /// mtoon.giEqualizationFactor
+ ///
+ public static float MigrateToGiEqualization(float giIntensity0X)
+ {
+ return Mathf.Clamp01(1 - giIntensity0X);
+ }
+
+ private static (float min, float max) GetShadingRange0X(float shadingToony0X, float shadingShift0X)
+ {
+ var rangeMin = shadingShift0X;
+ var rangeMax = Mathf.Lerp(1, shadingShift0X, shadingToony0X);
+
+ return (rangeMin, rangeMax);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/VRMShaders/VRM10/MToon10/Runtime/Migrator.cs.meta b/Assets/VRMShaders/VRM10/MToon10/Runtime/Migrator.cs.meta
new file mode 100644
index 000000000..d9150d358
--- /dev/null
+++ b/Assets/VRMShaders/VRM10/MToon10/Runtime/Migrator.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 920db45663454ba8b8debaf2aeb7f5c9
+timeCreated: 1623217316
\ No newline at end of file