Vertex color exported by gltf/glb is darker

The vertex color I exported to gltf/glb is always darker then what I specified in the editor

Steps to reproduce:

  1. blank project with a cube
  2. setup vertex color, apply rgb(0.5, 0.5, 0.5) to the whole cube
  3. export to gltf/glb
  4. parse the file, the vertex color becomes rgb(0.21, 0.21, 0.21)

I suspect it has something to do with stuff in Color Management, but I tweaked around and didn’t solve anything. Also when setting View Transform to Raw seem to approximate the exported color I got.

However when importing the exported .glb to blender again, the color is correct, so I’m assuming this is not a bug and blender is doing some color conversion here.

Using Blender 2.81a

Blender treats vertex color as if the numbers you enter are intended as sRGB data. Apparently, on your export, it converts them to linear data. And also apparently, your rendering engine is not reading them as linear data. You need to either figure out how to tell your engine that they’re intended to be read as linear color, or you need to process them to undo that correction. How? Probably by baking to texture, processing that texture with an image editing app (possibly Blender compositing) and baking them back to vertex color (which I believe is possible with an add-on, but I don’t do enough with vertex color to keep up with everything regarding it.)

I managed to get the correct color by converting linear color to sRGB in the renderer. So is true that every rendering engine should convert every gltf from linear to sRGB on their side or it’s just blender exported gltfs?

There’s no moral imperative for any renderers or exporters to handle color in any particular way.

I’m not familiar with gltf, but since it sounds like it’s a file format, not a particular shader, there’s no assumption of color space inherent to it.

It’s like, “Should all .pngs be in sRGB because Blender assumes they are?” No. They are what they are. If Blender does something you don’t want, fix it.

The glTF format does specify that vertex colors must be stored in linear color space. For Blender, that means they must be converted to linear during export and back to sRGB during import.

For physically-based rendering engines, all lighting calculations must be done in linear space. Unlike images/textures, there is no hardware acceleration for converting vertex attributes — like vertex colors — between color spaces. This is why glTF stores linear vertex colors: engines can render the file more efficiently. When the engine is finished with its lighting calculations, the final render output (incorporating vertex colors, material colors, lighting etc.) is typically converted back to sRGB for display.

If your engine is not showing the colors correctly when you import the glTF file, consider reporting a bug to the engine (or its glTF loader) and referencing this spec note. If your file does not appear in other viewers (like threejs or babylonjs) please report an issue on the Blender glTF addon.

5 Likes