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:
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?
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?
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”.
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.
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):
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?!
Thank you for the time and effort. I hope you understand my point.
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.
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.