From 1fa7b70b0cf37d6bccfe89ede3b6bb2abd80a9c6 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Tue, 28 Sep 2021 19:18:53 +0900 Subject: [PATCH] =?UTF-8?q?UnlitTransparentWithZWrite=20=E3=81=AF=20MToon?= =?UTF-8?q?=20=E3=81=AE=20Emissive=20Factor=20=E3=81=AB=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=90=E3=83=83=E3=82=AF=E3=81=95=E3=81=9B?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...MUnlitTransparentZWriteMaterialImporter.cs | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/Assets/VRM/Runtime/IO/VRMUnlitTransparentZWriteMaterialImporter.cs b/Assets/VRM/Runtime/IO/VRMUnlitTransparentZWriteMaterialImporter.cs index f66806ec2..72fdfc727 100644 --- a/Assets/VRM/Runtime/IO/VRMUnlitTransparentZWriteMaterialImporter.cs +++ b/Assets/VRM/Runtime/IO/VRMUnlitTransparentZWriteMaterialImporter.cs @@ -1,6 +1,8 @@ +using MToon; using UniGLTF; using UnityEngine; using VRMShaders; +using RenderMode = MToon.RenderMode; namespace VRM { @@ -37,36 +39,31 @@ namespace VRM // matDesc = new MaterialDescriptor(name, MToon.Utils.ShaderName); - matDesc.RenderQueue = vrmMaterial.renderQueue; + matDesc.RenderQueue = MToon.Utils.GetRenderQueueRequirement(RenderMode.TransparentWithZWrite).DefaultValue; + + // NOTE: Unlit のフォールバックなので、 Lit/Shade 色は黒とし、Emissive Factor に設定する. + // また、元のシェーダのうちユーザが設定できるプロパティは Texture のみ. + matDesc.Colors[MToon.Utils.PropColor] = Color.black; + matDesc.Colors[MToon.Utils.PropShadeColor] = Color.black; + matDesc.Colors[MToon.Utils.PropEmissionColor] = Color.white; if (vrmMaterial.textureProperties.ContainsKey(MToon.Utils.PropMainTex)) { if (VRMMToonTextureImporter.TryGetTextureFromMaterialProperty(data, vrmMaterial, MToon.Utils.PropMainTex, out var texture)) { - matDesc.TextureSlots.Add(MToon.Utils.PropMainTex, texture.Item2); - matDesc.TextureSlots.Add(MToon.Utils.PropShadeTexture, texture.Item2); + matDesc.TextureSlots.Add(MToon.Utils.PropEmissionMap, texture.Item2); } } - matDesc.Colors[MToon.Utils.PropColor] = Color.white; - matDesc.Colors[MToon.Utils.PropShadeColor] = Color.white; - - foreach (var kv in vrmMaterial.keywordMap) + matDesc.Actions.Add(unityMaterial => { - if (kv.Value) - { - matDesc.Actions.Add(material => material.EnableKeyword(kv.Key)); - } - else - { - matDesc.Actions.Add(material => material.DisableKeyword(kv.Key)); - } - } - - foreach (var kv in vrmMaterial.tagMap) - { - matDesc.Actions.Add(material => material.SetOverrideTag(kv.Key, kv.Value)); - } + // NOTE: ZWrite などの属性は util に設定させる. + var parameter = MToon.Utils.GetMToonParametersFromMaterial(unityMaterial); + parameter.Rendering.CullMode = CullMode.Back; + parameter.Rendering.RenderMode = RenderMode.TransparentWithZWrite; + parameter.Rendering.RenderQueueOffsetNumber = 0; + MToon.Utils.SetMToonParametersToMaterial(unityMaterial, parameter); + }); if (vrmMaterial.shader == MToon.Utils.ShaderName) {