GLTF material baseColorFactor rgb values adding up after material is loaded into the scene!

Hello guys,

I have just came to notice a weird behavior(maybe its supposed to be like that, but) with the albedo color of PBR material after loading a GLTF file into the scene.

The rgb color values below are what is defined in the material of GLTF file before being loaded into the scene:
Material file values
And, the below rgb color values are from the created PBR material in the scene after GLTF has been loaded:

Can someone explain to me if this is the right behavior?
Does anyone know why is that(rgb color values being added up) happening and how it can be solved? Or is this just a bug?

Thank you in advance. :slight_smile:

And here you have the GLTF file which you can test by yourself by just dropping the file in the sandbox: (12.4 KB)

You are looking at the values in gamma space but they are defined in linear space for convenience in the gltf file which explains the diff.

@sebavan Thank you for your answer. :slight_smile:

In order for the PBR material color to look correct in the scene I need to set the same linear space value as in GLTF file to the PBR material in the scene.

Is there a way to convert the rgb values from gamma space to linear after the gltf material has been loaded into the scene?

That would solve the issue I am having right now.

Thank you. :slight_smile:

This is the case by default.

the values in the PBR Material like albedoColor are defined in linear space, The inspector only is showing them in Gamma for convenience.

1 Like

Currently we have a warning in the color picker for this:

Maybe we should also display this warning under the numeric r/g/b inputs?

@sebavan Thank you very much for your response.

Beside just showing the albedoColor in Gamma for convenience, I think Babylon is also applying the Gamma value of 0.636 as a Linear value to the albedoColor.

I just tested this by setting the albedoColor of the PBR material after the GLTF has been loaded into the scene:

let linearColor = GLTFMaterial.albedoColor.toLinearSpace();
GLTFMaterial.albedoColor = new Color3(linearColor.r, linearColor.g, linearColor.b);

The result I get is the result I want after converting the color with “toLinearSpace()”, and the Inspector shows the Linear space value after that. Meaning, from Gamma value of “0.636” it shows the Linear value “0.38”.

I am using Babylon v4.2.

Thanks again.

@DarraghBurke Thank you for your response.

In which version of the Babylon is the warning displayed because color picker in Babylon v4.2 doesn’t display that.

Thanks. :slight_smile:

I am not sure to fully get what you see :slight_smile:

The value pbrMaterial.albedoColor is used as a linear defined color in the shader without any conversion whereas the inspector is using toGammaSpace to display the value.

You can try in 5.0 in the playground to be sure

@sebavan Thank you for your response.

If you see the code below:

let linearColor = GLTFMaterial.albedoColor.toLinearSpace();
GLTFMaterial.albedoColor = new Color3(linearColor.r, linearColor.g, linearColor.b);

I am just applying Linear values to the Linear defined color values in the shader right?
If this is the case, the color would not change and the Inspector would display the same values right?

Now, below is the material reference from Unity which is using Linear color space(You can also see the color value from the Unity Inspector):

This is the GLTF material where you can see the defined color value:
GLTF material definition
So, (r, g, b) are basically set to 0.38.

Below you can see the material being loaded and applied to the sphere in Babylon without applying the code I mentioned above:

You can clearly see the values are displayed in Gamma, but you can also see that the material is brighter than the material in unity with the same values and color space…
Below you can see the result of the code applying the same Linear value. This is what happens to the material on the sphere:

My conclusion is that, when the GLTF material gets loaded into the scene, the color values are being converted to Gamma and then applied as Linear. Otherwise, why would I get a different (the correct for me actually) result when applying Linear color value to the same Linear color value?! :thinking:

Thank you for the time and effort. I hope you understand my point.


Nothing is converted when we load the GLTF file. We actually have quite a lot of comparison tests: <model-viewer> - Fidelity Test Results

How are you exporting from Unity ? this might be the reason of the issue. or Unity is showing you the values in gamma in the picker no matter the chosen pipeline which would make sense so you need to convert them before placing them in the gltf file.


@sebavan Thank you for your response.

I don’t actually export GLTF from Unity but from Blender.

Converting the values in gamma from the picker in Unity and passing them in linear in gltf would make total sense. This is what I am actually doing but after the gltf material has been loaded into the scene. :slight_smile: :wink: