MSDF How to Draw Order with 2 Texts

@Deltakosh

I was playing with the MSDF Text and I noticed that the draw order gets weird when another text is in front or behind in 3D space.

Playground: https://playground.babylonjs.com/#6RLCWP#100

Is there any way to make these behave like normal meshes part of a 3D scene?
The onAfterDrawPhaseObservable order makes them behave like 2D layers.

This is not supported at the moment but maybe smthg @ryantrem or @AlitarSemiramis could add ?

If not I ll have a look in a week after my break.

I will try to look at it and see if I can figure out :slight_smile:

Still working on this, this is what you would expect to see, right?

Very nice, yes that’s perfect.
:clap:

I’m wondering how to make it work with transparent objects.

Like in this example: https://playground.babylonjs.com/#6RLCWP#101

How does it look on your end?

Text renders as an overlay after the scene renders. For transparent meshes, text ends on top of them. Changing that (sorting text against transparent meshes) would be a much bigger change.

PR to fix the issue just between text: Add writeToDepthBuffer option to MSDF TextRenderer by VicenteCartas · Pull Request #18691 · BabylonJS/Babylon.js

Nice, so I tested the new writeToDepthBuffer, but edges look incorrect?

Playground: https://playground.babylonjs.com/?snapshot=refs/pull/18691/merge#6RLCWP#102

After - edges look incorrect
textRenderer.writeToDepthBuffer = true

Before - edges look correct
textRenderer.writeToDepthBuffer = false

Looking :slight_smile:

Another PR up: [MSDF Text] Preserve antialiased edges when writing depth by VicenteCartas · Pull Request #18696 · BabylonJS/Babylon.js

@AlitarSemiramis

Any ideas how to make the edges look normal?

It looks very buggy and bad especially on mobile phones.

The difference between writeToDepthBuffer = true/false is very jarring…

Playground: https://playground.babylonjs.com/#6RLCWP#104

Got another PR out to address the border, looks better in my tests now (shared screenshots on the PR):

[MSDF Text] Fix alpha-to-coverage edge artifacts by VicenteCartas · Pull Request #18718 · BabylonJS/Babylon.js