From 8f710a24c8a3f9653a89ba4bedf9a2f0f641c1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sat, 23 Apr 2022 10:50:53 +0200 Subject: [PATCH] Added proper conversion from sRGB to linear space and added a temporary fix for Blender bug with vertex colors in sRGB --- src/graphics/model/model_gltf.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/graphics/model/model_gltf.cpp b/src/graphics/model/model_gltf.cpp index 72cb859d..817a3dfb 100644 --- a/src/graphics/model/model_gltf.cpp +++ b/src/graphics/model/model_gltf.cpp @@ -247,6 +247,8 @@ void GLTFLoader::ReadMaterials() color[2].get(), 0.0 }; + + mat.emissiveColor = Gfx::ToLinear(mat.emissiveColor); } else { @@ -283,6 +285,8 @@ void GLTFLoader::ReadMaterials() color[2].get(), color[3].get() }; + + mat.albedoColor = Gfx::ToLinear(mat.albedoColor); } else { @@ -680,6 +684,16 @@ std::vector GLTFLoader::ReadColors(int index) GetLogger()->Error("Invalid color type: %d\n", accessor.componentType); } + // Fix for bug in Blender where it exports vertex colors in sRGB instead of linear space + for (size_t i = 0; i < colors.size(); i++) + { + auto color = Gfx::IntColorToColor(Gfx::IntColor(colors[i])); + + color = Gfx::ToLinear(color); + + colors[i] = Gfx::ColorToIntColor(color); + } + return colors; }