Is there anyway to have the TextMesh so it's not blocky or fuzzy?
Here is an example: http://simpson3d.com/forum/HelloWorld.png
Thanks!
Is there anyway to have the TextMesh so it's not blocky or fuzzy?
Here is an example: http://simpson3d.com/forum/HelloWorld.png
Thanks!
I am putting it late, But maybe someone can get help from this because what I did to make it look awesome (even with inbuilt fonts) is set the CHARACTER SIZE of text mesh as minimum (I keep it 0.03) , and increased the FONT SIZE to 355. So I think by reducing the CHARACTER SIZE and increasing FONT SIZE, it won’t look fuzzy. See the image
Import the font at a larger size.
Try to reduce the scale of your GameObject and increase the font size instead.
Sedesikus’ solution didn’t work well for me because of varying screen resolutions (e.g. running in different platforms and screen sizes). Here’s a more generic solution that changes characterSize
and fontSize
according to the current window resolution so you can always have sharp text regardless of the size of the window or text. I could not find anything like this online, so hopefully it’ll work as future reference for someone else:
using System;
using UnityEngine;
public class TextMeshSharpener:MonoBehaviour {
/*
Makes TextMesh look sharp regardless of camera size/resolution
Do NOT change character size or font size; use scale only
*/
// Properties
private float lastPixelHeight = -1;
private TextMesh textMesh;
void Start() {
textMesh = GetComponent<TextMesh>();
resize();
}
void Update() {
// Always resize in the editor, or when playing the game, only when the resolution changes
if (Camera.main.pixelHeight != lastPixelHeight || (Application.isEditor && !Application.isPlaying)) resize();
}
private void resize() {
float ph = Camera.main.pixelHeight;
float ch = Camera.main.orthographicSize;
float pixelRatio = (ch * 2.0f) / ph;
float targetRes = 128f;
textMesh.characterSize = pixelRatio * Camera.main.orthographicSize / Math.Max(transform.localScale.x, transform.localScale.y);
textMesh.fontSize = (int)Math.Round(targetRes / textMesh.characterSize);
lastPixelHeight = ph;
}
}
Save this as TextMeshSharpener.cs
, add this as a script to a TextMesh and it’ll automagically work.
The catch with this solution, as stated in the comments, is that you don’t change the characterSize
or fontSize
yourself: you let the script handle it. Instead you change the TextMesh
’s scale to whatever you want.
targetRes
is a magic number that declares the target resolution of the text texture. You normally won’t need to change this ever. It can be tweaked to create even sharper text (not recommended, 128
is already pretty good) or to create textures with less resolution that use less memory (at the cost of being a little blurrier).
One other caveat is that this doesn’t re-calculate the resolution when animating the object. Doing so would make the animation a bit jaggy since it’d be changing the texture resolution. So it’ll resize the texture “as-is”, as it would with a normal TextMesh. That feature can easily be added by also checking the scale on Update
though.
Old, but I want to leave the info for everybody for placing textmesh in ortho view. Import text and set it’s size to whatever you like. For example font size 12. Then set its size to
var pixelRatio : float = (camera.orthographicSize * 2) / cam.pixelHeight;
characterSize = 1;
transform.localScale = Vector3(pixelRatio*10,pixelRatio*10 ,pixelRatio * 0.1);
go.transform.localPosition.x += 0.001f;
go.transform.localPosition.y += 0.001f;
It’s a hack, but it works for me. If anyone will happen to know a better solution, let me know.
Here’s a “remix” of Sedesikus’ solution, and this should handle multiple screen resolutions well:
float pixelRatio = (Camera.main.orthographicSize * 2.0f) / Camera.main.pixelHeight;
float fuzziness = 32.0f; // lower number is better, 32 seemed to work for me
int previousFontSize = textMesh.fontSize;
textMesh.fontSize = Mathf.RoundToInt(textMesh.fontSize / (pixelRatio * fuzziness));
float ratio = previousFontSize / ((float) textMesh.fontSize);
transform.localScale *= ratio;
This preserves the size of the TextMesh as you see in the editor mode, in other words, it doesn’t change the size of the textmesh, just improves the fidelity.