mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-06-02 22:14:30 -05:00
Migrate UnlitTranpsarentZWrite
This commit is contained in:
parent
f73a8233b2
commit
45565eb61d
|
|
@ -6,6 +6,7 @@ namespace UniVRM10
|
|||
{
|
||||
/// <summary>
|
||||
/// 過去の UniVRM において、KHR_materials_unlit 拡張を使わず、VRM 拡張を用いて Unlit を表現していた Material をマイグレーションする。
|
||||
/// KHR_materials_unlit を用いてマイグレーションする.
|
||||
/// </summary>
|
||||
public static class MigrationLegacyUnlitMaterial
|
||||
{
|
||||
|
|
@ -59,6 +60,9 @@ namespace UniVRM10
|
|||
unlitMaterial.alphaMode = "MASK";
|
||||
unlitMaterial.alphaCutoff = MigrationMaterialUtil.GetCutoff(vrm0XMaterial);
|
||||
return unlitMaterial;
|
||||
case "VRM/UnlitTransparentZWrite":
|
||||
// NOTE: ZWrite マテリアルのみ、MToon にマイグレーションするため、別処理.
|
||||
return MigrationUnlitTransparentZWriteMaterial.Migrate(vrm0XMaterial, materialName);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using UniGLTF;
|
||||
using UniGLTF.Extensions.VRMC_materials_mtoon;
|
||||
using UniJSON;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
/// <summary>
|
||||
/// 過去の UniVRM の "VRM/UnlitTransparentZWrite" シェーダをマイグレーションする.
|
||||
/// 他の Unlit シェーダと違い、VRMC_materials_mtoon を用いてマイグレーションする.
|
||||
/// </summary>
|
||||
public static class MigrationUnlitTransparentZWriteMaterial
|
||||
{
|
||||
private const string MigrationMToon10SpecVersion = "1.0-draft";
|
||||
|
||||
public static glTFMaterial Migrate(JsonNode vrm0XMaterial, string materialName)
|
||||
{
|
||||
var baseColorFactor = MigrationMaterialUtil.GetBaseColorFactor(vrm0XMaterial);
|
||||
var baseColorTexture = MigrationMaterialUtil.GetBaseColorTexture(vrm0XMaterial);
|
||||
var emissiveTexture = new glTFMaterialEmissiveTextureInfo
|
||||
{
|
||||
index = baseColorTexture.index,
|
||||
extensions = baseColorTexture.extensions,
|
||||
};
|
||||
|
||||
var mtoonMaterial = new glTFMaterial
|
||||
{
|
||||
name = materialName,
|
||||
extensions = new glTFExtensionExport().Add(
|
||||
glTF_KHR_materials_unlit.ExtensionName,
|
||||
new ArraySegment<byte>(glTF_KHR_materials_unlit.Raw)
|
||||
),
|
||||
pbrMetallicRoughness = new glTFPbrMetallicRoughness
|
||||
{
|
||||
baseColorFactor = new [] {0f, 0f, 0f, baseColorFactor[3]}, // black + _Color.a
|
||||
baseColorTexture = baseColorTexture, // _MainTex
|
||||
metallicFactor = 0f,
|
||||
roughnessFactor = 1f,
|
||||
},
|
||||
alphaMode = "BLEND",
|
||||
alphaCutoff = 0.5f,
|
||||
doubleSided = false,
|
||||
emissiveFactor = new [] {baseColorFactor[0], baseColorFactor[1], baseColorFactor[2]}, // _Color.rgb
|
||||
emissiveTexture = emissiveTexture,
|
||||
};
|
||||
|
||||
var mtoon10 = new VRMC_materials_mtoon
|
||||
{
|
||||
SpecVersion = MigrationMToon10SpecVersion,
|
||||
TransparentWithZWrite = true, // transparent with zWrite
|
||||
RenderQueueOffsetNumber = 0,
|
||||
ShadeColorFactor = new [] {0f, 0f, 0f}, // black
|
||||
OutlineWidthMode = OutlineWidthMode.none // disable outline
|
||||
};
|
||||
UniGLTF.Extensions.VRMC_materials_mtoon.GltfSerializer.SerializeTo(ref mtoonMaterial.extensions, mtoon10);
|
||||
|
||||
return mtoonMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 281c0ecbae8e489db4c86a553636ae44
|
||||
timeCreated: 1635426676
|
||||
Loading…
Reference in New Issue
Block a user