Pixel-Perfect Dynamic Text for Unity.
LINK TO ASSET WEBSITE: Pixel-Perfect Dynamic Text website.
Also a “Lorem Ipsum”-demo version is available if you want to try the asset in Unity.
This asset has its own niche:
• it is meant for displaying pixel-perfect text (“crisp anti-aliasing”),
• camera-facing text (even when camera has free orientation in 3D),
• with size & position defined in world units (not in some “custom UI scale” or so).
When comparing Pixel-Perfect Dynamic Text (PPDT) to Unity’s built-in text components:
• “PPDT” is sharp with crisp anti-aliasing like the really old legacy built-in GUIText. (GUIText is from early days of Unity, many of you probably don’t even know what that is or was, but the text it rendered was nice and crisp).
• “PPDT” text is part of the 3D scene, in similar way as classic Text Mesh (which is also known as “3D Text”). But “PPDT” looks better than Text Mesh.
• No Canvas or Canvas Renderer is needed. “PPDT” is not part of the Unity’s UI system. The text is rendered by the regular Mesh Renderer component instead.
What features does Pixel-Perfect Dynamic Text have?
Most of the listed features are demonstrated in the interactive demo which also comes with the package as an example scene.
Text size is proportional to world units, and not dependent on screen size in pixels or dpi resolution.
- For example, if you use an orthogonal camera in Unity with Size=5, it means the total height of window is 10 units. Pixel-Perfect Dynamic Text with unit size of 2.0 will mean one row takes vertically 20% of screen so that there will be space for 5 rows of text.
For maximum sharpness, pixel size for text font rendering is dynamically selected to be the nearest matching size for text world unit size.
- For example, suppose your window height is 512 pixels and you have a camera like in the previous example. If you make a text with size 1.0, the row height will be 1 unit, corresponding to 51.2 pixels. The font will be rendered sharp with pixel size of 51.
Pixel-Perfect Dynamic Text component also works with both orthogonal and perspective cameras.
- For perspective cameras, it measures distance from text object to the camera plane. With the power of trigonometry it figures out what is the correct pixel size for the text (with its current position and size, measured in world units).
- This is done separately for each different piece of text with varying distances.
You can choose if text is pixel snapped to keep it sharp when it moves on screen.
- With pixel snapping enabled, sub-pixel position of transform.position will be snapped to nearest pixel (of currently used screen resolution).
The Pixel-Perfect Dynamic Text component uses Unity’s internal font renderer and atlasing.
- So you can use same fonts what you can use with the built-in Text Mesh or GUI Text — use custom truetype fonts.
- Regular Font Styles are supported: normal, bold, italic, bold and italic.
- Change color dynamically.
- Standard built-in font material shader is used. No need for custom heavy-weight shaders.
- Note: There’s no support for Rich Text with html-like syntax (for now, at least).
Text can be aligned and anchored, similar to how Unity’s built-in Text Mesh (3D Text) works.
- Text can be left-, center- or right-aligned.
- Horizontally text can be left-, center- or right-anchored.
- Vertically text can be upper-, middle-, lower- or baseline-anchored. Pixel-Perfect Dynamic Text defaults to baseline anchoring for easier working with text (baseline anchor is not featured by built-in Text Mesh).
You can ask for font metrics and use tabs for alignment.
- The component has baseline, ascent and descent properties.
- You can also get size of the whole text (bounds of the generated mesh).
- Tab size is defined in world units and tab char in text moves to the next tab stop.
The component contains many small tweaks to make it better.
- Mesh is regenerated/reallocated only when necessary. E.g. when there’s longer text than previous frame, or if text properties change (size, style, anchor, alignment, …). Previous mesh arrays are reused when possible.
- Pixel-Perfect Dynamic Text is compatible with dynamic batching. It can even combine with built-in text meshes as same font material and texture can be used with both.
- You can update text dynamically, even every frame. See the last screen (10/10) of interactive demo. It has a “text mode” effect consisting of over 2000 characters updated every frame.
- Aware of different texel sampling between graphics APIs, and adjusts as needed to keep your text sharp.
- Automatically converts replaces existing Text Mesh objects if you add a new Pixel-Perfect Dynamic Text component to them.
No native code & small footprint.
- Works with Desktop, Mobile and Web platforms.
(probably with consoles as well, but we haven’t tried) - Supplied as a small DLL with the component and with bit of C# source for editor extension.
- Works with Unity 6, 2023, 2022, 2021, 2020, 2019, 2018, 2017!
Pixel-Perfect Dynamic Text works also with Unity 2D.
- NOTE: Default font material shader seems to render using the Default Sorting Layer with Order 0. To render sprites behind text, you can make a new Sorting Layer and drag it to be before Default. Or you can use Default Layer for your sprite but set the Order in Layer to negative value. And, of course, in similar way to force sprites render front of text.
NOTE: Tight integration with Unity GUI or other 3rd GUI libraries is not officially supported! As stated above, this asset has its own niche and is not meant to be a replacement for GUI libraries.
Check out more info and interactive demo in the Pixel-Perfect Dynamic Text website.
In addition to featuring the interactive demo, the website shows you a few examples what can often go wrong when you work with UI and text layouts between different screens. Also a few trade-offs and caveats are listed, and there’s a separate section for Questions and Answers.