convert gamma to linear before division.

This commit is contained in:
Masataka SUMI 2022-11-07 21:00:01 +09:00
parent f63d03475a
commit ac880243d3
2 changed files with 11 additions and 8 deletions

View File

@ -183,14 +183,15 @@ namespace UniGLTF
if (src.HasProperty("_EmissionColor"))
{
var color = src.GetColor("_EmissionColor");
if (color.maxColorComponent > 1)
{
var maxColorComponent = color.maxColorComponent;
color /= maxColorComponent;
UniGLTF.glTF_KHR_materials_emissive_strength.Serialize(ref dst.extensions, maxColorComponent);
}
// NOTE: Built-in RP Standard shader's emission color is in gamma color space.
dst.emissiveFactor = color.ToFloat3(ColorSpace.sRGB, ColorSpace.Linear);
var linearFactor = color.ToFloat3(ColorSpace.sRGB, ColorSpace.Linear);
var maxComponent = linearFactor.Max();
if (maxComponent > 1)
{
linearFactor = linearFactor.Select(x => x / maxComponent).ToArray();
UniGLTF.glTF_KHR_materials_emissive_strength.Serialize(ref dst.extensions, maxComponent);
}
dst.emissiveFactor = linearFactor;
}
if (src.HasProperty(EmissionTexturePropertyName))

View File

@ -261,7 +261,9 @@ namespace UniGLTF
var textureExporter = new TextureExporter(new EditorTextureSerializer());
var gltfMaterial = materialExporter.ExportMaterial(material, textureExporter, new GltfExportSettings());
Assert.AreEqual(gltfMaterial.emissiveFactor, new float[] { 0, 0.5f, 1 });
var maxComponent = Mathf.GammaToLinearSpace(2f);
Assert.That(gltfMaterial.emissiveFactor, Is.EqualTo(new float[] { 0f, 1f / maxComponent, 1f }).Within(0.5f / 255f));
}
}
}