3D text

Introduction

In a project, there may be times when text needs to be created as part of a 3Dscene and not just in the HUD. Godot provides 2 methods to do this: theLabel3D node and the TextMeshresource for a MeshInstance3D node.

Additionally, Godot makes it possible to position Control nodes according to a3D point's position on the camera. This can be used as an alternative to "true"3D text in situations where Label3D and TextMesh aren't flexible enough.

See also

You can see 3D text in action using the3D Labels and Texts demo project.

This page doesnot cover how to display a GUI scene within a 3Denvironment. For information on how to achieve that, see theGUI in 3Ddemo project.

Label3D

../../_images/label_3d.png

Label3D behaves like a Label node, but in 3D space. Unlike the Label node, thisLabel3D node doesnot inherit properties of a GUI theme. However, its lookremains customizable and uses the same font subresource as Control nodes(including support forMSDF fontrendering).

Advantages

See also

SeeUsing Fonts for guidelines on configuring font imports.

Limitations

By default, Label3D has limited interaction with a 3D environment. It can beoccluded by geometry and lit by light sources if theShaded flag is enabled.However, it will not cast shadows even ifCast Shadow is set toOn inthe Label3D's GeometryInstance3D properties. This is because the node internallygenerates a quad mesh (one glyph per quad) with transparent textures and has thesame limitations as Sprite3D. Transparency sorting issues can also become apparentwhen several Label3Ds overlap, especially if they have outlines.

This can be mitigated by setting the Label3D's transparency mode toAlphaCut, at the cost of less smooth text rendering. TheOpaque Pre-Passtransparency mode can preserve text smoothness while allowing the Label3D tocast shadows, but some transparency sorting issues will remain.

SeeTransparency sortingsection in the 3D rendering limitations page for more information.

Text rendering quality can also suffer when the Label3D is viewed at a distance. To improvetext rendering quality,enable mipmaps on the font orswitch the font to use MSDF rendering.

TextMesh

../../_images/text_mesh.png

The TextMesh resource has similarities to Label3D. They both display text in a3D scene, and will use the same font subresource. However, instead of generatingtransparent quads, TextMesh generates 3D geometry that represents the glyphs'contours and has the properties of a mesh. As a result, a TextMesh is shaded bydefault and automatically casts shadows onto the environment. A TextMesh canalso have a material applied to it (including custom shaders).

Here is an example of a texture and how it's applied to the mesh. You can usethe texture below as a reference for the generated mesh's UV map:

../../_images/text_mesh_texture.png../../_images/text_mesh_textured.png

Advantages

TextMesh has a few advantages over Label3D:

  • TextMesh can use a texture to modify text color on a per-side basis.

  • TextMesh geometry can have actual depth to it, giving glyphs a 3D look.

  • TextMesh can use custom shaders, unlike Label3D.

Limitations

There are some limitations to TextMesh:

  • No built-in outline support, unlike Label3D. This can be simulated using customshaders though.

  • Only dynamic fonts are supported (.ttf,.otf,.woff,.woff2).Bitmap fonts in the.fnt or.font formats arenot supported.

  • Fonts with self-intersecting outlines will not render correctly.If you notice rendering issues on fonts downloaded from websites such asGoogle Fonts, try downloading the font from the font author's officialwebsite instead.

  • Antialiasing the text rendering requires a full-scene antialiasing method tobe enabled such as MSAA, FXAA and temporal antialiasing (TAA). If noantialiasing method is enabled, text will appear grainy, especially at adistance. See3D antialiasing for more information.

Projected Label node (or any other Control)

There is a last solution that is more complex to set up, but provides the mostflexibility: projecting a 2D node onto 3D space. This can be achieved using thereturn value ofunproject_positionmethod on a Camera3D node in a script's_process() function. This return valueshould then be used to set theposition property of a Control node.

See the3D waypointsdemo for an example of this.

Advantages

  • Any Control node can be used, including Label, RichTextLabel or even nodes suchas Button. This allows for powerful formatting and GUI interaction.

  • The script-based approach allows for complete freedom in positioning.For example, this makes it considerably easier to pin Controls to the screen'sedges when they go off-screen (for in-game 3D markers).

  • Control theming is obeyed. This allows for easier customization that globallyapplies to the project.

Limitations

  • Projected Controls cannot be occluded by 3D geometry in any way. You can use aRayCast to fully hide the control if its target position is occluded by acollider, but this doesn't allow for partially hiding the control behind awall.

  • Changing text size depending on distance by adjusting the Control'sscaleproperty is possible, but it needs to be done manually. Label3D and TextMeshautomatically take care of this, at the cost of less flexibility (can't set aminimum/maximum text size in pixels).

  • Handling resolution and aspect ratio changes must be taken into account in thescript, which can be challenging.

Should I use Label3D, TextMesh or a projected Control?

In most scenarios, Label3D is recommended as it's easier to set up and provideshigher rendering quality (especially if 3D antialiasing is disabled).

For advanced use cases, TextMesh is more flexible as it allows styling the textwith custom shaders. Custom shaders allow for modifying the final geometry, suchas curving the text along a surface. Since the text is actual 3D geometry, thetext can optionally have depth to it and can also contribute to globalillumination.

If you need features such as BBCode or Control theming support, then using a projectedRichTextLabel node is the only way to go.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.