3
\$\begingroup\$

I can activate the Glow setting for a Font in Text Mesh Pro by checking the Glow checkbox:

enter image description here

Is there a way I can programmatically do the same thing? I looked in the corresponding shader, and found what I think is the name of the variable: GLOW_ON. But when I tried to set that variable to 1 using Material Set Float and Set Int, neither one worked. Either I have the wrong variable name, or I'm not setting it the proper way.

Any suggestions on how to programmatically activate the Glow option in a Text Mesh Pro font?

\$\endgroup\$
2

1 Answer 1

5
\$\begingroup\$

This is a shader variant using #pragma shader_feature, See SL-MultipleProgramVariants.

"TextMeshPro/Mobile/Distance Field":

#pragma shader_feature __ GLOW_ON
...
#ifdef GLOW_ON
...
#endif

So use Material.EnableKeyword(and DisableKeyword) in C# code:

material.EnableKeyword("GLOW_ON");
material.DisableKeyword("GLOW_ON");

And,

The version of this function that takes a string as a parameter is slower than the version that takes a LocalKeyword. If you call this function more than once, it is best practice to create a LocalKeyword struct, cache it, and use that.

\$\endgroup\$
2
  • 6
    \$\begingroup\$ Instead of typing out the string, you can also get it from TMPro.ShaderUtilities.Keyword_Glow \$\endgroup\$
    – DMGregory
    Aug 10, 2022 at 19:57
  • \$\begingroup\$ Wow this worked perfectly. Thank you!! \$\endgroup\$
    – kanamekun
    Aug 11, 2022 at 1:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .