mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-04-25 15:47:26 -05:00
convert gamma to linear before division.
This commit is contained in:
parent
f63d03475a
commit
ac880243d3
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user