Filtered fonts in the game engine #29882

Closed
opened 2012-01-14 00:00:52 +01:00 by Alex Fraser · 30 comments
Member

%%%This patch makes anti-aliasing of fonts in the game engine better. It does this by generating mipmaps for the glyphs, and enabling linear filtering. This is important for games because a single rendering of text can be viewed at different resolutions and even with perspective.

This patch also fixes a z-order bug with overlapping text; see screenshots.%%%

%%%This patch makes anti-aliasing of fonts in the game engine better. It does this by generating mipmaps for the glyphs, and enabling linear filtering. This is important for games because a single rendering of text can be viewed at different resolutions and even with perspective. This patch also fixes a z-order bug with overlapping text; see screenshots.%%%
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

%%%Attaching a (hopefully) Tortoise-friendly version of the patch.%%%

%%%Attaching a (hopefully) Tortoise-friendly version of the patch.%%%
Author
Member

%%%Trying the svn conversion thing again.%%%

%%%Trying the svn conversion thing again.%%%

%%%I like the aliasing, it's looking great here.

Now for the z-order bug:
I still have some glitches in some tilted texts (extreme ones, no real production examples yet). See alias_problem.png.
But I believe your twist code solves the most common case of texts parallel to the camera overlapping each other.

assigning to Diego (and deleting the git/wrong svn fils)%%%

%%%I like the aliasing, it's looking great here. Now for the z-order bug: I still have some glitches in some tilted texts (extreme ones, no real production examples yet). See alias_problem.png. But I believe your twist code solves the most common case of texts parallel to the camera overlapping each other. assigning to Diego (and deleting the git/wrong svn fils)%%%

%%%Hello!

The next three or four days are really busy for me, but as soon I have a little of time I will check the patch (I think for the next tuesday), sorry but a lot of work :(%%%

%%%Hello! The next three or four days are really busy for me, but as soon I have a little of time I will check the patch (I think for the next tuesday), sorry but a lot of work :(%%%
Author
Member

%%%Hi Dalai,

Actually I think what you're seeing is not a z-order issue. There are two separate problems:

  1. The way I understand it, the glyph textures map into a larger image. The white artefacts you see on the edge of the glyphs in "AntiAlias" are because the higher mipmap levels are bleeding in characters from other parts of the base image. There's a .pad member of GlyphCache; maybe if we increase that there will be greater spacing between the glyphs and it could solve this issue.

  2. The remaining aliased edges of the glyphs, e.g. the top edge of the T, are due to the texture being drawn right to the edge of the quad. In that case, mipmapping and filtering won't help. Enabling FSAA should fix it. Alternatively we could adjust the UV mapping to give a bit of spacing around the glyph in its quad. But we would also need to adjust the spacing between glyphs to compensate for that.

As you say, the second issue doesn't show up when the text is aligned to the camera.%%%

%%%Hi Dalai, Actually I think what you're seeing is not a z-order issue. There are two separate problems: 1. The way I understand it, the glyph textures map into a larger image. The white artefacts you see on the edge of the glyphs in "AntiAlias" are because the higher mipmap levels are bleeding in characters from other parts of the base image. There's a .pad member of GlyphCache; maybe if we increase that there will be greater spacing between the glyphs and it could solve this issue. 2. The remaining aliased edges of the glyphs, e.g. the top edge of the T, are due to the texture being drawn right to the edge of the quad. In that case, mipmapping and filtering won't help. Enabling FSAA should fix it. Alternatively we could adjust the UV mapping to give a bit of spacing around the glyph in its quad. But we would also need to adjust the spacing between glyphs to compensate for that. As you say, the second issue doesn't show up when the text is aligned to the camera.%%%
Author
Member

%%%Attaching a new version of the patch (blf_aa_2_svn.patch) that fixes issue 1 in the previous comment. In the new version, the padding around glyphs is increased when mipmapping is in use.%%%

%%%Attaching a new version of the patch (blf_aa_2_svn.patch) that fixes issue 1 in the previous comment. In the new version, the padding around glyphs is increased when mipmapping is in use.%%%
Author
Member

%%%Added files to demonstrate the difference padding has on the artefacts:

  • ge_text_nopadding.png - made with the original patch.
  • ge_text_padding.png - made with the new patch (blf_aa_2_svn.patch)
  • text.blend - the test file.%%%
%%%Added files to demonstrate the difference padding has on the artefacts: - ge_text_nopadding.png - made with the original patch. - ge_text_padding.png - made with the new patch (blf_aa_2_svn.patch) - text.blend - the test file.%%%
Author
Member

%%%blf_aa_3_svn.patch: only "twist" the leading edge of each glyph. This prevents the trailing edge from disappearing when the text is coplanar with a face.%%%

%%%blf_aa_3_svn.patch: only "twist" the leading edge of each glyph. This prevents the trailing edge from disappearing when the text is coplanar with a face.%%%
Author
Member

%%%Hi Diego, Dalai showed me the conversation you two had in IRC the other day. You are right about the padding, and the twist:

  • Extra padding is required for mipmaps, because otherwise the letters bleed into neighbouring glyphs.
  • The twist stops z-fighting when two glyphs overlap.

I tried making the twist optional, but I think it makes the code more complicated than it's worth - especially if Z is compressed in the normal GUI matrix. The twist code should be pretty fast. So it's still not optional in this patch, but I can add the option back if you want.%%%

%%%Hi Diego, Dalai showed me the conversation you two had in IRC the other day. You are right about the padding, and the twist: - Extra padding is required for mipmaps, because otherwise the letters bleed into neighbouring glyphs. - The twist stops z-fighting when two glyphs overlap. I tried making the twist optional, but I think it makes the code more complicated than it's worth - especially if Z is compressed in the normal GUI matrix. The twist code should be pretty fast. So it's still not optional in this patch, but I can add the option back if you want.%%%

%%%Hi Alex,

As I say to Dalai, the twist is ok, the Z is always clip when the UI is drawing in 2D, there is no problem there!.
I will talk with Dalai today, I think the patch is ready for trunk, sorry that take so long time!! and thank for the hard work!! :)
%%%

%%%Hi Alex, As I say to Dalai, the twist is ok, the Z is always clip when the UI is drawing in 2D, there is no problem there!. I will talk with Dalai today, I think the patch is ready for trunk, sorry that take so long time!! and thank for the hard work!! :) %%%
Author
Member

%%%Hi Diego,

Thanks for that! ... I'd like to commit this myself, if that's ok :)%%%

%%%Hi Diego, Thanks for that! ... I'd like to commit this myself, if that's ok :)%%%

%%%Hi Alex,

Sure! go ahead! :)%%%

%%%Hi Alex, Sure! go ahead! :)%%%
Author
Member

%%%Patch committed, r43876 (version 3 of the patch, see above for details).%%%

%%%Patch committed, r43876 (version 3 of the patch, see above for details).%%%

%%%There is something still strange with this patch (the committed one).
The problem for me happens when the text object is parented by an object that is parented to another, ...

Check this out: http://www.pasteall.org/pic/25805 (it's not a typo, the j can't be seen).
Looking at the KX_FontObject.cpp code I tried to fix this with this patch:
http://www.pasteall.org/28797/diff

This fix it, but all the texts seem over blurred (http:*www.pasteall.org/pic/25806) AND the text is missing as well: http:*www.pasteall.org/pic/25807

For my test (real file actually) I'm using a orthographic camera%%%

%%%There is something still strange with this patch (the committed one). The problem for me happens when the text object is parented by an object that is parented to another, ... Check this out: http://www.pasteall.org/pic/25805 (it's not a typo, the j can't be seen). Looking at the KX_FontObject.cpp code I tried to fix this with this patch: http://www.pasteall.org/28797/diff This fix it, but all the texts seem over blurred (http:*www.pasteall.org/pic/25806) AND the text is missing as well: http:*www.pasteall.org/pic/25807 For my test (real file actually) I'm using a orthographic camera%%%
Author
Member

%%%Hmm, didn't we figure out that was something slightly different? I'm not sure how this commit would affect that. Text that sits exactly on a plane will probably show issues like this, even with twisting, depending on the scene setup. Suggestions:

  • Try moving the near clipping plane of the camera closer to the text.
  • Move the text a bit towards the camera.

Actually, we had the same problem with non-text objects in the game we made at the game jam. The solution was to bring the objects closer to the camera.

Can you post a test file?%%%

%%%Hmm, didn't we figure out that was something slightly different? I'm not sure how this commit would affect that. Text that sits exactly on a plane will probably show issues like this, even with twisting, depending on the scene setup. Suggestions: - Try moving the near clipping plane of the camera closer to the text. - Move the text a bit towards the camera. Actually, we had the same problem with non-text objects in the game we made at the game jam. The solution was to bring the objects closer to the camera. Can you post a test file?%%%

%%%Alex please see attached file (packed font Papyrus included) - blf_bug.blend
(If you need I can send some screenshots)

With my patch (to use Nodal global Scaling instead of m_size- [x]) makes both lines to display all letters and are the same size. They are blurry though so there is yet something else wrong.%%%

%%%Alex please see attached file (packed font Papyrus included) - blf_bug.blend (If you need I can send some screenshots) With my patch (to use Nodal global Scaling instead of m_size- [x]) makes both lines to display all letters and are the same size. They are blurry though so there is yet something else wrong.%%%
Author
Member

%%%As discussed in IRC, I can't reproduce the missing J in blf_bug.blend with an nVidia card. But the bug is present when using my ATI card. Attaching a screenshot (missing-j.png) - the left image is with this patch disabled; the right shows the patch enabled: the text is blurry and the J is missing.

Note that the blurriness is expected in this case. The text simply has the wrong resolution, as shown in the image on the left: without the patch, it's blocky. If that is a bug, then it's unrelated to this patch. The missing J, however, is a concern. And the fact that it only shows up on ATI cards makes me think this will be difficult to fix.%%%

%%%As discussed in IRC, I can't reproduce the missing J in blf_bug.blend with an nVidia card. But the bug *is* present when using my ATI card. Attaching a screenshot (missing-j.png) - the left image is with this patch disabled; the right shows the patch enabled: the text is blurry and the J is missing. Note that the blurriness is expected in this case. The text simply has the wrong resolution, as shown in the image on the left: without the patch, it's blocky. If that is a bug, then it's unrelated to this patch. The missing J, however, is a concern. And the fact that it only shows up on ATI cards makes me think this will be difficult to fix.%%%

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

%%%patch reverted on rev. 44011. Let's have it bright and shinning after 2.62 is out.
%%%

%%%patch reverted on rev. 44011. Let's have it bright and shinning after 2.62 is out. %%%
Member

%%%I uploaded my modified version of this patch (blf_aa_3_HG1.patch).

This patch should fix flowing problems:

  1. Missing J on ATI cards.
  2. Increase the letter twist to reduce the clipping problem.
  3. Fix mipmap crash on non GLSL cards.
    %%%
%%%I uploaded my modified version of this patch (blf_aa_3_HG1.patch). This patch should fix flowing problems: 1. Missing J on ATI cards. 2. Increase the letter twist to reduce the clipping problem. 3. Fix mipmap crash on non GLSL cards. %%%
Member

%%%New patch (blf_aa_4_HG1.patch).
Fixed implicit type conversion.%%%

%%%New patch (blf_aa_4_HG1.patch). Fixed implicit type conversion.%%%
Author
Member

@hg1, how does your new version of the patch fix the issue with the J? I can't see what the difference is in the code. Was it fixed by another commit?

@hg1, how does your new version of the patch fix the issue with the J? I can't see what the difference is in the code. Was it fixed by another commit?
Member

I think the J was clipped by the ATI card. So the increased twist (0.0002 to 0.0004) has fixed the problem.

I think the J was clipped by the ATI card. So the increased twist (0.0002 to 0.0004) has fixed the problem.

Hello!! there!

I have a machine with an ATI card here, so tomorrow I'm going to update my git repo and try the patch!!

Hello!! there! I have a machine with an ATI card here, so tomorrow I'm going to update my git repo and try the patch!!
Author
Member

Added subscriber: @ideasman42

Added subscriber: @ideasman42
Author
Member

Cool, here's a new version that applies against HEAD. Note that this reverts commit 7c6d52e which stopped initialisation of the font image; initialisation is actually required for glyph padding when using mipmapping. Thanks to @ideasman42 for assistance with this update.

blf_aa_5.patch

Cool, here's a new version that applies against HEAD. Note that this reverts commit 7c6d52e which stopped initialisation of the font image; initialisation is actually required for glyph padding when using mipmapping. Thanks to @ideasman42 for assistance with this update. [blf_aa_5.patch](https://archive.blender.org/developer/F70432/blf_aa_5.patch)
Author
Member

And this version adds alpha clipping, reducing artefacts for kerned (overlapping) letters.

blf_aa_6_alphaclip.patch

And this version adds alpha clipping, reducing artefacts for kerned (overlapping) letters. [blf_aa_6_alphaclip.patch](https://archive.blender.org/developer/F70433/blf_aa_6_alphaclip.patch)
Member

In the new patches there is a printf left.

In the new patches there is a printf left.
Author
Member

Oops, you're right - but it's only printed when creating a cache (very infrequently). It will be removed before committing, but you can test with the patch as-is.

Oops, you're right - but it's only printed when creating a cache (very infrequently). It will be removed before committing, but you can test with the patch as-is.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#29882
No description provided.