Font Material - Uniform UV across text block size

We’re trying to create a font material effect and it would be very useful if we had access to a normalized UV that had a uniform range across the size of the text block, rather than the glyphs.

From what I can see we only have UV0 which is [0, 1] across the list of glyphs and UV1 which is [0, 1] per glyph. UV0 is almost what we want, but each glyph is given an equal portion of the U axis regardless of the glyph size. You can see this very obviously in the attached images. Using a step node you can see how when the glyphs are uniform in size (“WWW”) we get the desired pattern, but when the glyphs are nonuniform (“WlW”) the pattern is warped.

Is there any input data we can use to get a normalized UV across the textbox size rather than the glyph list?

Hi Chad,

There is a simple way to achieve what you want, but first let me address the behavior you are observing.

Unfortunately, when rendering a text widget with a font material, there is no input data available that corresponds to a normalized UV across the widget size. All data available as UVs in the material can be accessed by using the “GetUserInterfaceUV” node, which returns texcoords from 0 to 4 with more meaningful names. Here are some example results when applying a simple texture material to a Border or Image widget:

TexCoord 4 - Normalized UV

[Image Removed]

TexCoord 1 - 9-Slice UV (No Tiling)

[Image Removed]

TexCoord 0 - 9-Slice UV (Tiling)

[Image Removed]

As you noted, when rendering a Text widget, only TexCoords 0 and 1 contain useful data. TexCoord 1 maps UV range [0..1] to the bounding box of each character. The horizontal coordinate on TexCoord 0 is divided by the number of characters, and the resulting fixed ranges are mapped to the bounding box of each character. The vertical coordinate on TexCoord 0 has the range [0..1] mapped from the bottomline to the topline of the font, ignoring the actual character bounding box dimensions. Here are some examples:

TexCoord 1 - [0..1] on each character

[Image Removed]

TexCoord 0 - U distributed equally per-character, V spanning font height

[Image Removed]

Note that each character is rendered as a single quad, with no knowledge about the other characters or about the text widget dimensions as a whole (which might not even be respected). Also note that settings such as character spacing do not affect the rendering of each individual character. These are some of the reasons why there is no TexCoord available containing the data you want.

Now, to achieve the effect you want, it is possible to wrap your text widget in a Retainer Box widget. The Retainer Box renders its contents to an internal texture with a configurable frequency or only when certain events occur, which is normally associated with performance optimization. However, it also allows you to apply an Effect Material to its internal texture contents, similarly to a post-process effect. On that material, TexCoord 0 is mapped across the widget size, which is what you are probably looking for. Here’s my result:

[Image Removed]

To use the Retainer Box, create a new Material and set it on its “Effect Material” property. Also set the “Texture Parameter” property to match the name of the texture object parameter that your material will sample. This will contain the retained contents of the box (i.e. the contents of the internal rendertarget). Note that, if you intend to sample color textures inside the effect material, they will need to be have sRGB disabled and be sampled as linear color.

[Image Removed]

I hope this is helpful. Please let me know if this solution works for you.

Best regards,

Vitor