Unity to Babylon.js color conversions [HDR] tag

Hi there! I’m trying to color match the results I’m getting from Unity in Babylon.js.

In Unity I have a main color for the object and I’m lerping to a second colour that is tagged [HDR] which has an intensity of 3.416924 (Thanks for changing my nice rounded number Unity). While this HDR tag is used, HDR in the Unity project is not enabled at a scene or camera level.

The important parts of the Unity shader contents look like this:

float4 _Color; // 0 , 144 , 255, 255
float4 _ColorB; // 0 , 108 , 191, 255. [HDR] label, intensity 3.416924

            fixed4 frag (v2f i) : SV_Target
                float transition = (sin(_Time.y) * 0.5 + 0.5);

                float4 col = tex2D(_MainTex, i.uv);
                float4 finalCol = lerp((_Color * col), (_ColorB * col), transition);

                return finalCol;

The texture used in _MainTex is using the sRGB color space. Alpha as transparency, enabled.

Below is the playground where you can see the results and the shader used:

Lerp’ing values:

Output _Color * Texture:

Output _ColorB * 3.4169 * Texture:

The texture in the shader is set to “Convert to linear space”, as in the top color4.
The color4 below that is using “Convert to gamma space” because it more closely matched what I was seeing in Unity. I’ve not seen anything that directly mentions what happenes to a colour in Unity when you use the [HDR] tag.

In either case in this simple example I can’t get the same results. Either in the level of saturtation or brightness of the results. Any tips on what is at play here and how I can align the visuals?

It’s going to be hard to tell… Are you able to setup a live link by converting the unity project to webgl and hosting it somewhere?

We would at least need to see what are the values for _Color and _ColorB when they reach the shader.

In any case, there’s no gamma to linear conversion for the texture in your shader, so you should not have it in the node material either, except if the texture in Unity is stored in a sRGB buffer, in which case col is a linear color… But that would mean the final color is in linear space too, which would be strange, except if there is some post processing that gamma correct the color.