diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/BuiltInGltfMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/BuiltInGltfMaterialExporter.cs index 26f923b77..fe42f516d 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/BuiltInGltfMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/BuiltInGltfMaterialExporter.cs @@ -40,6 +40,7 @@ namespace UniGLTF break; } + Debug.Log($"Material `{m.name}` fallbacks."); return BuiltInFallbackMaterialExporter.ExportMaterial(m, textureExporter); } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/Materials/BuiltInFallbackMaterialExporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/Materials/BuiltInFallbackMaterialExporter.cs index 2eec9d260..73e093d76 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/Materials/BuiltInFallbackMaterialExporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/BuiltInRP/Export/Materials/BuiltInFallbackMaterialExporter.cs @@ -1,13 +1,18 @@ -using UnityEngine; +using System; +using UnityEngine; using VRMShaders; +using ColorSpace = VRMShaders.ColorSpace; namespace UniGLTF { /// - /// 非対応のシェーダでも空のマテリアルを出力する. + /// 非対応のシェーダでも、baseColor だけ読み取ったマテリアルにする. /// public static class BuiltInFallbackMaterialExporter { + private const string ColorPropertyName = "_Color"; + private const string ColorTexturePropertyName = "_MainTex"; + public static glTFMaterial ExportMaterial(Material src, ITextureExporter textureExporter) { var dst = new glTFMaterial @@ -16,6 +21,20 @@ namespace UniGLTF pbrMetallicRoughness = new glTFPbrMetallicRoughness(), }; + if (src.HasProperty(ColorPropertyName)) + { + dst.pbrMetallicRoughness.baseColorFactor = src.GetColor(ColorPropertyName).ToFloat4(ColorSpace.sRGB, ColorSpace.Linear); + } + + if (src.HasProperty(ColorTexturePropertyName) && src.GetTexture(ColorTexturePropertyName) != null) + { + dst.pbrMetallicRoughness.baseColorTexture = new glTFMaterialBaseColorTextureInfo() + { + index = textureExporter.RegisterExportingAsSRgb(src.GetTexture(ColorTexturePropertyName), false), + }; + GltfMaterialExportUtils.ExportTextureTransform(src, dst.pbrMetallicRoughness.baseColorTexture, ColorTexturePropertyName); + } + return dst; } }