Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round glTF2.0 materials[].emissiveFactor value to its maximum limit #102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Assets/VRM/UniGLTF/Editor/MaterialTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using UnityEngine;


namespace UniGLTF
Expand Down Expand Up @@ -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 });
}
}
}
4 changes: 4 additions & 0 deletions Assets/VRM/UniGLTF/Scripts/IO/MaterialExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand Down