From 2e659da9dad9822a156c0b63011b067a1452780f Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Jun 2021 20:34:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8F=A4=E3=81=84=E3=82=B7=E3=82=A7?= =?UTF-8?q?=E3=83=BC=E3=83=80=E3=83=BC=E5=90=8D=E3=82=92=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=90=E3=83=83=E3=82=AF=20#1004?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GLTF/IO/Runtime/MaterialFactory.cs | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs index 39c9877c0..4fa5d62da 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs @@ -18,6 +18,16 @@ namespace VRMShaders m_externalMap = externalMaterialMap; } + static Dictionary s_fallbackShaders = new Dictionary + { + {"VRM/UnlitTexture", "Unlit/Texture"}, + {"VRM/UnlitTransparent", "Unlit/Transparent"}, + {"VRM/UnlitCutout", "Unlit/Transparent Cutout"}, + // 互換性は無いがとりあえず、 + {"VRM/UnlitTransparentZWrite", "VRM/Mtoon"}, + {"UniGLTF/StandardVColor", "UniGLTF/UniUnlit"}, + }; + public struct MaterialLoadInfo { public readonly Material Asset; @@ -109,29 +119,47 @@ namespace VRMShaders getTexture = (_) => Task.FromResult(null); } - material = new Material(Shader.Find(matDesc.ShaderName)); + var shaderName = matDesc.ShaderName; + if (String.IsNullOrEmpty(shaderName)) + { + throw new Exception("no shader name"); + } + if (s_fallbackShaders.TryGetValue(shaderName, out string fallback)) + { + Debug.LogWarning($"fallback: {shaderName} => {fallback}"); + shaderName = fallback; + } + + var shader = Shader.Find(shaderName); + if (shader == null) + { + throw new Exception($"shader: {shaderName} not found"); + } + + material = new Material(shader); material.name = matDesc.SubAssetKey.Name; - foreach(var kv in matDesc.TextureSlots) + foreach (var kv in matDesc.TextureSlots) { var texture = await getTexture(kv.Value); - if(texture!=null){ + if (texture != null) + { material.SetTexture(kv.Key, texture); SetTextureOffsetAndScale(material, kv.Key, kv.Value.Offset, kv.Value.Scale); } } - foreach(var kv in matDesc.Colors) + foreach (var kv in matDesc.Colors) { material.SetColor(kv.Key, kv.Value); } - foreach(var kv in matDesc.Vectors) + foreach (var kv in matDesc.Vectors) { material.SetVector(kv.Key, kv.Value); } - foreach(var kv in matDesc.FloatValues) + foreach (var kv in matDesc.FloatValues) { material.SetFloat(kv.Key, kv.Value); } @@ -141,7 +169,7 @@ namespace VRMShaders material.renderQueue = matDesc.RenderQueue.Value; } - foreach(var action in matDesc.Actions) + foreach (var action in matDesc.Actions) { action(material); } From dc2c8c57036c960cfb18c1df16f5355d6d2afbd7 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 7 Jun 2021 20:47:23 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=A7=E6=96=87=E5=AD=97=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E3=80=82const=20=E4=BD=BF=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs | 4 ++-- .../GLTF/IO/Runtime/VRMShaders.GLTF.IO.Runtime.asmdef | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs b/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs index 4fa5d62da..d30f029bc 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs +++ b/Assets/VRMShaders/GLTF/IO/Runtime/MaterialFactory.cs @@ -24,8 +24,8 @@ namespace VRMShaders {"VRM/UnlitTransparent", "Unlit/Transparent"}, {"VRM/UnlitCutout", "Unlit/Transparent Cutout"}, // 互換性は無いがとりあえず、 - {"VRM/UnlitTransparentZWrite", "VRM/Mtoon"}, - {"UniGLTF/StandardVColor", "UniGLTF/UniUnlit"}, + {"VRM/UnlitTransparentZWrite", "VRM/MToon"}, + {"UniGLTF/StandardVColor", UniGLTF.UniUnlit.Utils.ShaderName}, }; public struct MaterialLoadInfo diff --git a/Assets/VRMShaders/GLTF/IO/Runtime/VRMShaders.GLTF.IO.Runtime.asmdef b/Assets/VRMShaders/GLTF/IO/Runtime/VRMShaders.GLTF.IO.Runtime.asmdef index a0e6a1dc5..ae4551ebf 100644 --- a/Assets/VRMShaders/GLTF/IO/Runtime/VRMShaders.GLTF.IO.Runtime.asmdef +++ b/Assets/VRMShaders/GLTF/IO/Runtime/VRMShaders.GLTF.IO.Runtime.asmdef @@ -1,13 +1,14 @@ { "name": "VRMShaders.GLTF.IO.Runtime", - "references": [], + "references": [ + "VRMShaders.GLTF.UniUnlit.Runtime" + ], + "optionalUnityReferences": [], "includePlatforms": [], "excludePlatforms": [], "allowUnsafeCode": false, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": false, - "defineConstraints": [], - "versionDefines": [], - "noEngineReferences": false + "defineConstraints": [] } \ No newline at end of file