diff --git a/Assets/VRM/UniGLTF/Editor/MaterialTests.cs b/Assets/VRM/UniGLTF/Editor/MaterialTests.cs index 015e362cab..8109ecdfd3 100644 --- a/Assets/VRM/UniGLTF/Editor/MaterialTests.cs +++ b/Assets/VRM/UniGLTF/Editor/MaterialTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using UnityEngine; namespace UniGLTF @@ -176,5 +177,17 @@ public void MaterialImportTest() Assert.AreEqual("Standard", material.shader.name); } } + + [Test] + public void MaterialExportTest() + { + var material = new Material(Shader.Find("Standard")); + material.SetColor("_EmissionColor", new Color(0, 1, 2, 1)); + var materialExporter = new MaterialExporter(); + var textureExportManager = new TextureExportManager(new Texture[] { }); + var gltfMaterial = materialExporter.ExportMaterial(material, textureExportManager); + + Assert.AreEqual(gltfMaterial.emissiveFactor, new float[] { 0, 0.5f, 1 }); + } } } diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs b/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs index 3d2df3235d..613971d76f 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs @@ -135,6 +135,10 @@ static void Export_Emission(Material m, TextureExportManager textureManager, glT if (m.HasProperty("_EmissionColor")) { var color = m.GetColor("_EmissionColor"); + if (color.maxColorComponent > 1) + { + color /= color.maxColorComponent; + } material.emissiveFactor = new float[] { color.r, color.g, color.b }; }