TextMesh Pro Colors highly inaccurate

I'm having an issue where if I'm changing colors via Vertex Color alone from the TMP component in inspector, the color is not accurate. I've noticed that Vertex Color takes into account the material color and does some math on top of it. In order to get the exact color to show up, I have to do either of these two steps.

  1. Only change TMP color via the material itself, which means I have to create a new material preset everytime I have a new color I want to use for text. This gets messy really fast and my project will be overflowed with materials.

  2. I have to edit both Vertex Color and Color Gradient with the same color value to get the exact color to show. Even if I uncheck Color Gradient, TMP still takes the it into account.

Is there a more efficient way of doing this correctly via the inspector? It is a steep learning curve to try and understand this process for new users who are used to design software that lets you edit color in a simple, straightforward manner. Appreciate any advice, thank you.

1 Like

The Material color will always affect the Vertex Color. If the Material Color is 255, 255, 255, 255, then whatever the Vertex Color is set at is what will be used.

The Vertex Color is unique to each text object. The Material color is shared by all text object using this same material.

Please provide more detail on how the Vertex Color is not accurate when leaving the material to the default white?

[quote=“Stephan_B”, post:2, topic: 746794]
The Material color will always affect the Vertex Color. If the Material Color is 255, 255, 255, 255, then whatever the Vertex Color is set at is what will be used.

The Vertex Color is unique to each text object. The Material color is shared by all text object using this same material.

Please provide more detail on how the Vertex Color is not accurate when leaving the material to the default white?
[/quote]

Hi Stephan_B, thanks for the reply. I just realized that if the Player > Other Settings > Color Space is on Linear, what I described will happen. But on Gamma, what you described will happen. Is there a solution if for achieving the same result in Linear?

Hi @Stephan_B , I have the exact issue here.
Are texts rendered with a gamma correction while in Linear mode ?

1 Like

Seems like the HDR color picker is used by default for all material colors in TMP. Replacing a line in DoColor method in TMP_BaseShaderGUI.cs seems to do the trick, but you need to modify the code inside the TMP package.

Set the hdr parameter to false.

Color value = EditorGUI.ColorField(EditorGUILayout.GetControlRect(), s_TempLabel, property.colorValue, false, true, false);

Just noticed the same issue. Same color code on my icon (URP/Unlit shader) and TMP text, different results.
As mentioned above, setting up the color on the material itself does fix the issue but it's obviously far from ideal.

Same issue here, had to turn it off as suggested inside the package to get it to work.

Would be nice to turn off HDR colors entirely for the project/package

1 Like

[quote=“dshook”, post:7, topic: 746794]
Same issue here, had to turn it off as suggested inside the package to get it to work.

Would be nice to turn off HDR colors entirely for the project/package
[/quote]

Please see if removing the [HDR] attribute in the SDF shader that you happen to use resolves the issue.

Since these shaders are contained in the TMP Essential Resources which were imported in your project, this would make it easier to handle until I can figure out what is going exactly with this.

TMP_SDF-Mobile shader

7045726--835486--upload_2021-4-16_0-25-35.png

1 Like

Had the same issue. Changing on shader did not work for me, changing directly on package like unity_FGs7Rwoa9O-xNQ said, did work.

Before:
7070935--840586--upload_2021-4-23_15-46-22.png

After:
7070935--840589--upload_2021-4-23_15-46-40.png

[quote=“AlliBee”, post:9, topic: 746794]
Had the same issue. Changing on shader did not work for me, changing directly on package like unity_FGs7Rwoa9O-xNQ said, did work.

Before:

After:

[/quote]

Thank you for the feedback. I will have to test both these things then.

1 Like

We are facing same kind of problem when creating an animation clip that set the face color of the material, when creating an animation that set the exactly same color as base, the color result appear wrong.
We need to deactivate HDR in the shader and edit the code in the package as unity_FGs7Rwoa9O-xNQ said to have the desired color.
It could be great if we have the choice to switch on or off the HDR support

1 Like

[quote=“SBods9A”, post:11, topic: 746794]
We are facing same kind of problem when creating an animation clip that set the face color of the material, when creating an animation that set the exactly same color as base, the color result appear wrong.
We need to deactivate HDR in the shader and edit the code in the package as unity_FGs7Rwoa9O-xNQ said to have the desired color.
It could be great if we have the choice to switch on or off the HDR support
[/quote]

I need to look into this to figure out what is going on. Most likely this is something the graphic team will need to address as having this HDR attribute should not be affecting colors.

Could one of you please submit a bug report on this? If so, please post the case # once you have it and I will make sure to forward this to the graphic team.

P.S. Obviously, I can add / remove these HDR attributes or make the code changes but this seems like something we should not have to do.

1 Like

Hi Stephan,
Thanks for your quick answer, here is the bug report we submit https://issuetracker.unity3d.com/product/unity/issues/guid/1334247

Hi Stephan, do you have any updates about this ?

I'd love to have some news too

2 Likes

I encountered the same problem today trying to create a SDF font material entering color values in RGB to match a sprite color. Color picker defaults to use HDR (HDR is also disabled from URP pipeline setting asset file).

The suggested workaround by turning off HDR for the color picker in TMPro package does not work for me, it will revert back to true automatically. But if you close Unity and then edit it and set the file as read only, the workaround does work.

Unity 2020.3.12f1.590.2 and Text Mesh Pro 3.0.6.

I think I found the solution. The problem, as mentioned earlier, is the color returned by the TMP shader does not account for color space being set to linear. It seems like shaders actually need to account for this conversion explicitly.

The fix for me was to edit TMP_SDF.shader (or duplicate it) and scroll down to the end and fine the line:

return faceColor * input.color.a;

Replace it with:

#if UNITY_COLORSPACE_GAMMA
return faceColor * input.color.a;
#else
return fixed4(GammaToLinearSpace(faceColor.rgb), faceColor.a) * input.color.a;
#endif
11 Likes

[quote=“pbhogan”, post:17, topic: 746794]
I think I found the solution. The problem, as mentioned earlier, is the color returned by the TMP shader does not account for color space being set to linear. It seems like shaders actually need to account for this conversion explicitly.

The fix for me was to edit TMP_SDF.shader (or duplicate it) and scroll down to the end and fine the line:

return faceColor * input.color.a;

Replace it with:

#if UNITY_COLORSPACE_GAMMA
return faceColor * input.color.a;
#else
return fixed4(GammaToLinearSpace(faceColor.rgb), faceColor.a) * input.color.a;
#endif

[/quote]

Mostly correct.

The added complication is that the Canvas system does convert the color to linear space when Unity is in Linear Color Space. However, when using a normal component which uses the Mesh Renderer, there is no automatic conversion. Since both components may be using the same material / shader, you would end up with double conversion of the colors when using the component in Linear space as the colors would be converted once by the canvas batcher and then in the shader.

Having said that, I have revised the handling of color for the normal component where it will do the conversion when using Linear Color space. Then for the components using the Canvas, the conversion is handled by the Canvas.

The above mostly resolves these issues but I still have to address potential inspector issues related to the use of the [HDR] attribute in the shader which alters the color in the inspector and being displayed. So right now, I believe those attributes should be removed. I am trying to sort this out and figure out of those [HDR] attributes are working as expected.

2 Likes

[quote=“Stephan_B”, post:18, topic: 746794]
Mostly correct.

The above mostly resolves these issues but I still have to address potential inspector issues related to the use of the [HDR] attribute in the shader which alters the color in the inspector and being displayed. So right now, I believe those attributes should be removed. I am trying to sort this out and figure out of those [HDR] attributes are working as expected.
[/quote]

Good to know—thanks!

Hi, I've bumped into the same issue of the color mismatch and was able to fix it by using Unity Material Property Blocks to override material color for each instance without recreating new material for each new color. Hope that helps!

7447010--913223--upload_2021-8-25_11-0-54.png

1 Like