UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.44k stars 181 forks source link

Text always on top of objects with alpha blend/sort #119

Closed elmeunick9 closed 8 years ago

elmeunick9 commented 8 years ago

Text objects always appear on top of objects that have alpha blend enabled. Using alpha clip is not a good enough alternative.

Example .blend: http://s000.tinyupload.com/index.php?file_id=76131152442303363793

im

youle31 commented 8 years ago

Hi! This is a know issue: I paste the 2 related bug reports:

In upbge I remarked that only 2 alpha blend modes were working (alpha clip and alpha anti aliasing)

I quickly tested GPU_set_material_alpha_blend options in DisableForText() but without success for the moment.

We have to take care about performances if we want to fix that because some alpha blend mode seems to slow down the bge and this makes debugging performances issues harder (we use render 2D text and DisableForText() also for debugging messages.)

(It comes from that the font objects are not rendered as normal objects, but in a function, RenderFonts that is called afeter rendering the scene, so we have to play with alpha settings of fonts to handle the transparency correctly)

@panzergame : I've just seems that in RenderMeshSlot, IndexPrimitives_3DText is called before IndexPrimitives. Is this normal?

Thanks for report!

panzergame commented 8 years ago

Currently text are rendered in KX_FontObject::DrawFontText called by KX_Scene::RenderFonts.

Which means that for the moment the text are not sorted by depth (contrary to meshes objects) between they and also with the others objects. Indeed it's a wrong way here.

Then the supposed function IndexPrimitives_3DText for text is not called, it should be the case, but here the text parsing form DrawFontText should be moved in IndexPrimitives.

panzergame commented 8 years ago

first plan:

For texts objects:

RAS_MaterialBucket:
    --> RAS_DisplayArrayBucket []:
        --> m_displayArray = NULL
        --> RAS_MeshSlot []:
            --> RAS_TextUser(RAS_MeshUser): // Hineritance from RAS_MeshUser but for text objects.
                --> m_texts[] // the texts lignes.
                --> m_fontId // the BFL text number.
                --> m_size
                --> m_dpi
                --> m_aspect

For the render:

RAS_BucketMaterial::RenderMeshSlot:
    if material->GetDrawingMode() & RAS_RENDER_3DPOLYGON_TEXT:
        --> RenderText3D(GetFontId(), GetTexts(), GetSize(), GetDpi(),  GetColor(), GetMatrix(), GetAspect()) // getter from RAS_TextUser and RAS_MeshUser
panzergame commented 8 years ago

Fixed in 7038db28fa6715915235df06a075d1a8f5282dd8.