top of page
  • Writer's pictureStephen Brown

Font Chaos!

Since the start of the engine, fonts have always been rendered offline into a texture sheet and then had effects applied to them. This is great for simplicity but when you start to add simplified Chinese and traditional Chinese, and then also allow those language to input text into the game, you end up with about 30-40 font textures which end up taking up 70+ mb when compressed for the game. Not only that they don't look that pretty when rendered and cannot be scaled that well.

Up until now I was happy with this approach, but I've always been keen to keep memory down. The current APK is about 108Mb and also when these fonts are loaded in game, you end up losing double the memory to the game, so on low end devices the fonts end up stealing 70*2 = 140Mb of RAM before you've even started loading cars and other things in!

I've also had to add alot more characters to the font pages, and so the memory has grown even more, so I decided to go for a different approach.

Enter Signed Distance Field rendering, which basically yields super high resolution rendering of fonts, whilst keeping texture memory down. It also enables pixel shaders to do some cool effects to save pre-rendering shadows/outlines on fonts with photoshop. Instead of each character being about 64x64 pixels in the texture, it only needs to be about 20x20, and because we can add effects in the pixel shader, it only needs to use a single channel in a texture sheet (instead of full colour), meaning I can put each character on an each individual channel (red/green/blue and alpha), thus getting 4x as many characters into a single texture sheet. The only down side is that I cannot compress these textures, but the memory saved just by implementing the steps above is that I now have an uncompressed set of textures that are only 18Mb, which is alot less than 70Mb when compressed :)

Hopefully this will enable those with super low end devices to have a much more stable build to play with. You can see looking at the progress of the following 3 screenshots how the font space is dramatically reduced, but not only this in game the fonts look super crisp at any resolution, so scaling up the text is now super easy!

Textures no SDF as they were (just using red channel to show it easier 43x1024x1024 textures!):

Textures as SDF: (14x1024x1024 textures!)

Textures as SDF/MSDF in individual channels (5x1024x1024 textures!)

321 views0 comments

Related Posts


bottom of page