When exporting to glTF, what color space is used for vertex colors?

I have a geometry with vertex colors. I’m using the recommended renderer.outputEncoding = sRGBEncoding and specifying my vertex colors like new THREE.Color('#808080').convertSRGBToLinear(), which I think is the correct way to do things. When I export the scene to glTF, does it make any assumptions about the color space of vertex colors? Does it translate them to linear as glTF requires?

And what about other colors in the scene: material colors, light colors, etc.? What’s the recommendation for those and what does the exporter do about color spaces for them?

I’m using the recommended renderer.outputEncoding = sRGBEncoding and specifying my vertex colors like new THREE.Color('#808080').convertSRGBToLinear() , which I think is the correct way to do things.

Yes, both are correct if you want consistent export to glTF.

GLTFExporter assumes that the vertex colors are already linear. Same for material colors, light colors, and so on. When rendering with .outputEncoding = sRGBEncoding, those assumptions are built into THREE.WebGLRenderer, too. There may be a very few exceptions, perhaps THREE.Fog is assumed to be sRGB (but fog doesn’t export to glTF anyway).

That being the case — if you want for a material color to match some CSS using #808080 on your webpage, you’ll want to use THREE.Color('#808080').convertSRGBToLinear() for material colors too.

A bit more information here:

1 Like

Thanks for that doc! Don’t know how I missed it in my research over the last couple of days. Very helpful.

1 Like