PBR vertex color - Color space

Hi,
I was wondering how babylon is treating vertex colors for pbr materials?
Am I correct with the assumptions, that it assumes gltf models to have vertex colors in gamma space and converts them to linear? and does the same on export?

If I assign vertex colors in runtime, I would have to convert them to linear space, if I want to use PBR Materials and to gamma, if I want to use Standard Material, I guess. Using a parameter on PBR material to interpret vertex colors in linear or gamma space would not make sense, I assume, since this would be overkill for the material?

maybe @Evgeni_Popov knows this

Kind regards!

Yes, all colors of a PBR material are expected to be in linear space when you set them (like pbr.albedoColor or pbr.emissiveColor).

Depending on a loaded file, some conversions can take place if the colors are in gamma space in this file.

Actually no, vertex colors (and probably all colors like albedo) are linear in a gltf file because they are in fact described as a linear multiplier (generally multiplied with a value read from a texture - the value read from the texture can be in gamma space, it depends on what the spec is saying).

Yes, we don’t want to convert at runtime when it is easy to convert beforehand.

Thanks for the clarification!
It also seems like babylon considers the material when exporting to gltf. A mesh with standard material is converted to gamma space and pbr material stays as is. This means, I can write my vertex colors in linear space to a mesh with pbr material without worrying about gltf export.

Sounds good :slight_smile:

The following playground shows, what happens, if I write gamma space colors to a mesh. Even though the vertex colors in code are the same for pbr and standard material, the exported version knows about linear and gamma space.

https://playground.babylonjs.com/#ZRZIIZ#55