OSGText Issues

From FlightGear wiki
Revision as of 11:33, 11 November 2020 by Hooray (talk | contribs) (→‎Investigation: https://sourceforge.net/p/flightgear/mailman/message/36113197/)
Jump to navigation Jump to search
This article is a stub. You can help the wiki by expanding it.

we need to do some Real Work (TM) to support Canvas with osgText 3.6 and upwards, unfortunately.[1]

currently osgText doesn't work under the ALS pipeline. That's a big issue for someone willing to fly an airliner that uses osgText (to the point of being practically unflyable). It's not a breaking change for other developers, but it is for someone willing to actually use the simulator. In my opinion that should be the most important criteria when judging if something oes on next.[2]

OSGText doesn't play nice with shaders.[3]

some developers have switched to canvas /because/ of the always white OSGText problem[4]

The OSGText issue is more that the world is moving forwards, and our text-animation element has not. (Shaders required, can’t rely on OpenGL 1.1 built-in lighting)[5]

It’s caused by OSG using a shader to render text now, but this bypasses the built-in emissive/diffuse/ambient material properties, which is what our <text> animation uses to set colours of text.

It should happen ‘everywhere’ that a shader is used to render text - Canvas doesn’t care about it since it sets the text color directly.[6]

The breaking change was introduced with OSG 3.6.5, and was also recently merged into OSG 3.7.[7]

Background

With OSG 3.6, Aircraft <text> animations will be broken [8] however: that’s the blocking issue stopping us moving to 3.6 everywhere. [9] OSG 3.6 has the text display issue [10], currently osgText doesn't work under the ALS pipeline. [11] one issue that seems to occur in a few places is missing text elements on cockpit devices ... There are issues with osgText not working in OSG > 3.4.2. We need to find a migration solution for osgText that works with Compositor and newer OSG versions [12] ... another option was creating a Canvas for each text animation, but creating a FBO for every small piece of text doesn't sound very performance-friendly. [13] We need to find some way to approximate with the old OSG text did[14]


For the time being, we don’t (often) use OSG 3.6 - looking at the code on master (which became 3.6), there isn’t a single commit we can revert - Robert evidently did a lot of incremental improvements to the text code, adding support for other features and improving the shader support. Then at some point he collected a subset of those changes and back-ported them to 3.4 branch, which is what we revert in the commit on my fork on GitHub.

This means for OSG 3.6 we need to find a solution on our side, which likely means updating aircraft or making some guesses based on the <text> animation element in our XML files, because the set of colouring options supported by the new osgText implementation is more restrictive than what worked before.

(The text animation assumes that setting all of emissive/ambient/diffuse/specular works on an osgText, and it no longer does - for some cases we could map the emissive color to the text color, but this would break some other cases…. and text still won’t receive normal lighting in that case)[15]


Investigation

Note  As a workaround, using a canvas for this is actually not that bad - it eats some memory equal to the size of the canvas (so make it as small as possible) but in terms of performance, it will end up about the same. [16] To be clear it’s 100% a bug that can be fixed, just that given the effort to fix it, I’d recommend going with the canvas solution instead.[17]

The osgText is probably (or at least, possibly, there’s a few other options besides) being ignored by the effect system, this is fixable but fairly unpleasant work. [18]

Back in 2017, the issue seemed that we now set a shader program on the font state-set, which is tripping up something (the effects system or otherwise), but we need to investigate further to fix anything. [19]

James tested current OSG (3.7.x) and we still have the same issue to fix on our side.

The issue is using a <material> animation to set the colour of the text no longer works, because osgText no longer uses the OpenGL materials, and hence ignores the material properties in the StateSet. The only control we have over the colour of the text is the osgText::Text::setColor method - which is what Canvas uses of course.[20]

The issue seems many aircraft could be changed to do something simpler (use decal text with no lighting), or use Canvas, but masking a fully generic replacement for what <text> used to do is quite difficult - for correctness it should use the full lighting model / ALS / etc so that painted text on a panel / tail / etc is lit correctly.

That’s completely doable but means hooking an effect into the <text> element, which is certainly some work to get correct, since the shader also needs to interact correctly with the osgText source texture (containing the glyphs and offsets)[21]


Fernando has been investigating this for a while now and it has proven to be a lot less trivial that he initially thought. His first approach was to ust transform the osgTexts into EffectGeodes, but this isn't so elegant as the general rules of effects don't apply to animations (we can't use <inherits-from>, model-default doesn't get applied automatically as it isn't considered a model, etc).

Richard said on Discord that another option was creating a Canvas for each text animation, but creating a FBO for every small piece of text doesn't sound very performance-friendly. This is also worsened by the fact that canvas cameras are scene-graph level cameras and are being rendered multiple times (once per viewer slave camera).[22]

Ideas

Mapping to Canvas

For some purposes (pre-canvas HUDs or displays) text animations would have to be emissive, likewise for panel backlighting.

For other purposes - basically panel legends etc. they would be ambient/diffuse.

Since osgText animations also don't play nice with our whole effect framework, might there a way to internally map the animation to an equivalent canvas solution? We might be better off in a number of ways with that.[23]

Of course, emissive for panel legends would be totally wrong.

The problem is supporting emissive would be doable as a few-lines tweak and quite safe. Supporting ambient/diffuse will require the same solution as ‘making the text work with effects’, i.e a custom text shader I thin, and I don’t know if we could do that (or integrate it with the effects framework)

As for mapping to Canvas, James also is not sure how that would work - Canvas Text is also ‘just osgText’ but it seems works for Canvas because the output texture is applied to the cockpit and then effects are applied on top? Doing a safe transformation of osgText-animation to Canvas would mean working out the required canvas extent and somehow mapping it to the correct panel location (and UVs), which he’d be nervous about both the reliability and complexity of.

James wondered if we could do a hack in <animation> XML parsing to at least support emissive use - then we have an easy update route for those people, people doing panel legends would need to use canvas text manually?[24]

References

References
  1. https://sourceforge.net/p/flightgear/mailman/message/36730965/
  2. https://sourceforge.net/p/flightgear/mailman/message/37042335/
  3. https://forum.flightgear.org/viewtopic.php?f=87&t=37429&p=376110#p376110
  4. https://sourceforge.net/p/flightgear/mailman/message/36731025/
  5. https://sourceforge.net/p/flightgear/mailman/message/36731031/
  6. https://sourceforge.net/p/flightgear/mailman/message/36731732/
  7. https://sourceforge.net/p/flightgear/mailman/message/36732917/
  8. https://sourceforge.net/p/flightgear/mailman/message/36240313/
  9. https://sourceforge.net/p/flightgear/mailman/message/37147614/
  10. https://sourceforge.net/p/flightgear/mailman/message/37126793/
  11. https://sourceforge.net/p/flightgear/mailman/message/37042335/
  12. https://sourceforge.net/p/flightgear/mailman/message/37047567/
  13. https://sourceforge.net/p/flightgear/mailman/message/37042457/
  14. https://sourceforge.net/p/flightgear/mailman/message/37042476/
  15. https://sourceforge.net/p/flightgear/mailman/message/36703340/
  16. https://sourceforge.net/p/flightgear/mailman/message/36113197/
  17. https://sourceforge.net/p/flightgear/mailman/message/36113508/
  18. https://sourceforge.net/p/flightgear/mailman/message/36113197/
  19. https://sourceforge.net/p/flightgear/mailman/message/36141064/
  20. https://sourceforge.net/p/flightgear/mailman/message/36624316/
  21. https://sourceforge.net/p/flightgear/mailman/message/36740020/
  22. https://sourceforge.net/p/flightgear/mailman/message/37042457/
  23. https://sourceforge.net/p/flightgear/mailman/message/36624574/
  24. https://sourceforge.net/p/flightgear/mailman/message/36627559/