RGB and Hex values entered for a color3 result in different color than what was used

This is weird…

The color entered for the material is not the color in the inspector.

    var pbr = new BABYLON.PBRMetallicRoughnessMaterial("pbr", scene);
    sphere.material = pbr;

    pbr.baseColor = BABYLON.Color3.FromInts(130, 213, 47);
    //pbr.baseColor = BABYLON.Color3.FromHexString('#82D52F'); // <--- or use
    
    pbr.metallic = 0;
    pbr.roughness = 1.0;

What is should look like:

What it actually looks like:

You need to convert to linear space as best explained by @Evgeni_Popov here: PBRMaterial Albedo Color RGB in Playground Code Different than RGB Shown in Inspector and on Object - #5 by Evgeni_Popov

3 Likes

Thanks, that’s the problem.


For future readers, in short form:

  1. Colors are made in sRGB space, they need to be converted to linear space
  2. Do this with Color3.toLinearSpace()
  3. Example:
BABYLON.Color3.FromHexString('#82D52F').toLinearSpace();`
1 Like