3D Text's transparent areas will occlude objects drawn behind it afterwards. #29804

Closed
opened 2012-01-05 20:38:13 +01:00 by kanttori · 6 comments

Category: Rendering

%%%So the issue is following in the file attached:

Texts write depth and have depth test on. This means texts drawn behind another text will be occluded by the transparent part and at certain angles letters in same text to have z-fighting issues where they overlap (should occur between T and e).

One solution would be to disable blending when drawing 3d text in bge and enable opengl's alpha test to only allow alpha == 1.0 or alpha > limit.

  • No nice soft edges, but should always draw correctly.

Another way is to draw texts with other transparents ordered back to front; can be done without depth write so no z-fighting between letters in same text and can use blending on.

  • When z-ordering fails can still cause visual glitches (absolute perfection would require partitioning faces since face A can be partly behind and partly in front of face B.. gets complicated fast).%%%

**Category**: Rendering %%%So the issue is following in the file attached: Texts write depth and have depth test on. This means texts drawn behind another text will be occluded by the transparent part and at certain angles letters in same text to have z-fighting issues where they overlap (should occur between T and e). One solution would be to disable blending when drawing 3d text in bge and enable opengl's alpha test to only allow alpha == 1.0 or alpha > limit. - > No nice soft edges, but should always draw correctly. Another way is to draw texts with other transparents ordered back to front; can be done without depth write so no z-fighting between letters in same text and can use blending on. - > When z-ordering fails can still cause visual glitches (absolute perfection would require partitioning faces since face A can be partly behind and partly in front of face B.. gets complicated fast).%%%
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

%%%Meh, I was probably overthinking this by a mile. True, after alphatest the remaining transparent areas will suffer from blending against wrong colors but in the end it is just the edge pixels and most visible when the text is being magnified. This can be minimized by using a higher alpha to test against which will only leave the texture pixels that influence the resulting color more.

Index: source/gameengine/BlenderRoutines/KX_BlenderGL.cpp


- source/gameengine/BlenderRoutines/KX_BlenderGL.cpp	(revision 43202)

+++ source/gameengine/BlenderRoutines/KX_BlenderGL.cpp (working copy)
@@ -147,8 +147,15 @@

BLF_size(fontid, size, dpi);
BLF_position(fontid, 0, 0, 0);
  • /* Use alphatest to prune transparent areas */

  • glEnable(GL_ALPHA_TEST);

  • glAlphaFunc(GL_GREATER, 0.5f);

  • BLF_draw(fontid, (char *)text, strlen(text));

  • glDisable(GL_ALPHA_TEST);

  • BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
    }

%%%

%%%Meh, I was probably overthinking this by a mile. True, after alphatest the remaining transparent areas will suffer from blending against wrong colors but in the end it is just the edge pixels and most visible when the text is being magnified. This can be minimized by using a higher alpha to test against which will only leave the texture pixels that influence the resulting color more. Index: source/gameengine/BlenderRoutines/KX_BlenderGL.cpp **** - source/gameengine/BlenderRoutines/KX_BlenderGL.cpp (revision 43202) +++ source/gameengine/BlenderRoutines/KX_BlenderGL.cpp (working copy) @@ -147,8 +147,15 @@ BLF_size(fontid, size, dpi); BLF_position(fontid, 0, 0, 0); + + /* Use alphatest to prune transparent areas */ + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.5f); + BLF_draw(fontid, (char *)text, strlen(text)); + glDisable(GL_ALPHA_TEST); + BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT); } %%%

%%%Hi Juha,

GL_ALPHA_TEST is explicitly disabled in the DisableText routine.
This was added in revision 15867. Log here for convenience:


Game Engine: alpha blending and sorting


Alpha blending + sorting was revised, to fix bugs and get it to work more predictable.

  • A new per texture face "Sort" setting defines if the face is alpha sorted or not, instead of abusing the "ZTransp" setting as it did before.
  • Existing files are converted to hopefully match the old behavior as much as possible with a version patch.
  • On new meshes the Sort flag is disabled by the default, to avoid unexpected and hard to find slowdowns.
  • Alpha sorting for faces was incredibly slow. Sorting faces in a mesh with 600 faces lowered the framerate from 200 to 70 fps in my test.. the sorting there case goes about 15x faster now, but it is still advised to use Clip Alpha if possible instead of regular Alpha.
  • There still various limitations in the alpha sorting code, I've added some comments to the code about this.

The regular alpha routine in BGE is handled inside the GPU_set_material_alpha_blend%%%

%%%Hi Juha, GL_ALPHA_TEST is explicitly disabled in the DisableText routine. This was added in revision 15867. Log here for convenience: **** Game Engine: alpha blending and sorting **** Alpha blending + sorting was revised, to fix bugs and get it to work more predictable. * A new per texture face "Sort" setting defines if the face is alpha sorted or not, instead of abusing the "ZTransp" setting as it did before. * Existing files are converted to hopefully match the old behavior as much as possible with a version patch. * On new meshes the Sort flag is disabled by the default, to avoid unexpected and hard to find slowdowns. * Alpha sorting for faces was incredibly slow. Sorting faces in a mesh with 600 faces lowered the framerate from 200 to 70 fps in my test.. the sorting there case goes about 15x faster now, but it is still advised to use Clip Alpha if possible instead of regular Alpha. * There still various limitations in the alpha sorting code, I've added some comments to the code about this. **** The regular alpha routine in BGE is handled inside the GPU_set_material_alpha_blend%%%

%%%That said, it seems safe to set whatever opengl flag we need.
Alpha rendering always make sure the proper flags are set (see gpu_set_alpha_blend in ^/source/blender/gpu/intern/gpu_draw.c).%%%

%%%That said, it seems safe to set whatever opengl flag we need. Alpha rendering always make sure the proper flags are set (see gpu_set_alpha_blend in ^/source/blender/gpu/intern/gpu_draw.c).%%%

Hello,

Yep, KX_BlenderGL.cpp file was remove in the cleanup. I tracked down the commit (point by Dalai) and found the DisableForText function.

So far using GL_ALPHA_TEST and GL_GREATER works fine, but should not this check if GL_ALPHA_TEST is not already enable ?
In the example file, GL_ALPHA_TEST is disable when the text is render, but if that is not the case, the GL_ALPHA_TEST will be disable when the RenderText3D call return.

I'm not sure how much will impact this in the GE (add a glIsEnable(GL_ALPHA_TEST at the start).

The patch looks like:
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
index 1227fe8..caf5186 100644
- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
@@ -1401,10 +1401,15 @@ void RAS_OpenGLRasterizer::applyTransform(double* oglmatrix,int objectdrawmode )

static void DisableForText()
{

  •   GLboolean alpha_test;
    
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
      glDisable(GL_BLEND);
  • glDisable(GL_ALPHA_TEST);
  •   alpha_test= glIsEnabled(GL_ALPHA_TEST);
    
  •   if (alpha_test == GL_FALSE)
    
  •           glEnable(GL_ALPHA_TEST);
    
  •   glAlphaFunc(GL_GREATER, 0.5f);
    
      glDisable(GL_LIGHTING);
      glDisable(GL_COLOR_MATERIAL);

@@ -1427,6 +1432,9 @@ static void DisableForText()

              glDisable(GL_TEXTURE_2D);
      }
  •   if (GL_ALPHA_TEST == GL_FALSE)
    
  •           glDisable(GL_ALPHA_TEST);
    

}

void RAS_OpenGLRasterizer::RenderBox2D(int xco,

@dfelinto any comment ?

Hello, Yep, KX_BlenderGL.cpp file was remove in the cleanup. I tracked down the commit (point by Dalai) and found the DisableForText function. So far using GL_ALPHA_TEST and GL_GREATER works fine, but should not this check if GL_ALPHA_TEST is not already enable ? In the example file, GL_ALPHA_TEST is disable when the text is render, but if that is not the case, the GL_ALPHA_TEST will be disable when the RenderText3D call return. I'm not sure how much will impact this in the GE (add a glIsEnable(GL_ALPHA_TEST at the start). The patch looks like: diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 1227fe8..caf5186 100644 - a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -1401,10 +1401,15 @@ void RAS_OpenGLRasterizer::applyTransform(double* oglmatrix,int objectdrawmode ) static void DisableForText() { + GLboolean alpha_test; + ``` glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */ ``` ``` glDisable(GL_BLEND); ``` - glDisable(GL_ALPHA_TEST); + alpha_test= glIsEnabled(GL_ALPHA_TEST); + if (alpha_test == GL_FALSE) + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.5f); ``` glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); ``` @@ -1427,6 +1432,9 @@ static void DisableForText() ``` glDisable(GL_TEXTURE_2D); } ``` + + if (GL_ALPHA_TEST == GL_FALSE) + glDisable(GL_ALPHA_TEST); } void RAS_OpenGLRasterizer::RenderBox2D(int xco, @dfelinto any comment ?
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
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#29804
No description provided.