Add migration mtoon10

This commit is contained in:
Masataka SUMI
2021-06-10 15:20:13 +09:00
parent bff1fd17b9
commit 45b7b3e7de
4 changed files with 62 additions and 3 deletions

View File

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

View File

@@ -6,6 +6,7 @@
"UniGLTF",
"VRMShaders.GLTF.IO.Runtime",
"VRMShaders.VRM10.Format.Runtime",
"VRMShaders.VRM10.MToon10.Runtime",
"UniHumanoid"
],
"optionalUnityReferences": [],

View File

@@ -0,0 +1,48 @@
using UnityEngine;
namespace VRMShaders.VRM10.MToon10.Runtime
{
/// <summary>
/// Migrate from VRM 0.x MToon to VRM 1.0 vrmc_materials_mtoon
/// </summary>
public sealed class MToonMigrator
{
/// <summary>
/// mtoon.shadingToonyFactor
/// </summary>
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);
}
/// <summary>
/// mtoon.shadingShiftFactor
/// </summary>
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);
}
/// <summary>
/// mtoon.giEqualizationFactor
/// </summary>
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);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 920db45663454ba8b8debaf2aeb7f5c9
timeCreated: 1623217316