tris/ verts getting added for every letter written

So yeah, just noticed this and wondered why it is like that:
For every letter added to a guiText etc it seems to create 2 tris / 4 verts. I´d imagine the way it works now is that basically a texture is created for every leter and plotted next to the previous (correct me if i´m wrong) whereas i thought it would make more sense if the one texture plane was kept and a “graphic” of all written letters used as texture which would lead to more performance cost in moment of writing each letter but less constant performance cost while all written letters are just sitting there.
It probably doesnt matter that much unless one writes a lot of letters, i just wondered :slight_smile:

Unity does create a single texture sheet which contains every character in a font (you specify what character set to import in the settings). You can see this texture in the inspector when you click on the font. You still need to make a quad for each letter (2 tris) because how else are you going to UV map the text? Creating a new texture for each text string would be fairly inefficient, since you’d have to 1) calculate the size of the text string so you can figure out how large of a texture to allocate, 2) copy or draw the individual letters into the texture, 3) upload the texture to the graphics card (slow). The advantage is that you could create dynamic effects on the fly like bold, italics, per-character color, etc.

–Eric

Ok, thanks for the explanation :slight_smile:
I´m coming from flash so there i´d have one bitmapData plottedText, one bitmapData fontSpriteSheet and then copyPixels the letter to the plottedText bitmapData, thought maybe this could somehow be done in performance savy way here, too, well, ok if there are other bottlenecks then not :slight_smile:

For what it’s worth, outside of Unity it’s not uncommon to render text into a texture whenever it changes. It’s not useful to do this for text which constantly changes, but it can still be more economical if you draw the text more often than you change it, especially for larger runs of text.

If you wanted to do the same thing in Unity, you could use a GUIText or TextMesh draw the text into a RenderTexture, then reuse the generated texture.

The usual rules about optimisation apply, though… don’t bother going to great lengths to do this unless you really have a performance problem to solve and you’re sure that text rendering is the source of the problem. :wink:

to NCarter: I could try to do it manually myself but i think it would still be not performance savey with the way how i would have to do it (since i´d have to plot the letter as texture, then draw that whole thing into a rendertexture in a seperate step,no?
I think if UT could do it in a way in which one could draw gui stuff directly into something like a blank (render) texture container thing that could be great.

I thought about what you said, too, Eric and i think most of what you noted as downsides of an attempt like this also applies with the setup there is now (and besides that the setup there is now requires lots of textures and drawcalls being needed every ongui call).

well, the more i use gui stuff on the iphone the more i think drawing all 2d gui stuff into a single texture would help massively with performance.
I think it would be heavily benefitial if there was a 2DGUILayer object which would basically be something like a virtual screensize texture and one can draw any gui stuff into it. Then there could be a property called refreshOption and that could have possible values redrawAll and freezeAndAdd.
The names don´t matter really, just to explain the idea:
with the first it would redraw all elements drawn into the texture each frame refresh/ongui call and with freezeAndAdd it wouldn´t redraw the plotted texture but allow to draw more elements onto it (so it would only paint more stuff into a chached picture ).
Not sure if i could explain my thought well, its basically really that one has one texture into which all the 2d gui stuff can be drawn, it only needs one drawcall while it sits there unchanged and then one each time one draws additional stuff to it and once one has drawn everything into it its treated as if it was just one premade raster graphic used as texture. Its basically caching all gui elements in a layer as single screensize raster graphic that is used as texture all the time from then on.

ideally: let´s have a texture layer thing that has all the functionality of bitmapdata objects in flash :slight_smile:
(hey, no problem with talking about one good thing about flash that should be ported over to unity after i talked about all the bad sides of flash where unity excels it by far :slight_smile: )