CompositeViewer support

From FlightGear wiki
Jump to navigation Jump to search
IMPORTANT: Some, and possibly most, of the features/ideas discussed below are likely to be affected, and possibly even deprecated, by the ongoing work on providing a property tree-configurable rendering pipeline accessible via XML using the new Compositor system available since FlightGear 2020.3 (11/2020): The main rendering pipeline (on next at least) is now the Compositor using ALS. The "classical renderer" and "Project Rembrandt" have been superseded. From the perspective of creating regional material definitions, you can just develop against ALS and you will be fine.[1]

Please see: Post FlightGear 2020.2 LTS changes for further information You are advised not to start working on anything directly related to this without first discussing/coordinating your ideas with other FlightGear contributors using the FlightGear developers mailing list or the Effects & Shaders subforum This is a link to the FlightGear forum.. talk page.

Compositor logo.png


CompositeViewer Support
Started in 07/2020 (early experiments)
Description Support for multiple independent views
Contributor(s) Julian Smith
Status experimental (building but not yet working [2][3])
10}% completed
Changelog https://sourceforge.net/u/cgdae/profile/feed.rss
Topic branches:
$FG_SRC https://sourceforge.net/u/cgdae/flightgear/ci/7ae9a72e656df8c7166bad53638b2f3efdb4e140/


For the time being, FlightGear only supports one view position at a time. Multiple independent view positions (e.g. one screen for the tower view and a second screen for the plane) would complicate a "locked to cache" flag quite a lot...[4].

A number of contributors [5] have been pointing out that the way we do the tile cache [with a single viewer] is not optimal. Apparently we cache all scenery up to twice the visibility range, and not doing so would save us half the memory at the expense of more hard disk operations when back-tracking on the course and not having tower view available when the plane is far from the tower. Old tiles being cached are a problem when terrain becomes a main memory occupant. The advantage of the tile cache for back-tracking is minimal, very few flights to that regularly, and tower view from large distance is useless, the plane is a dot, and basically unsupported by many features[6]

Ideally we would throw out the tile-cache and let the OSG DB-Pager handle all this - Mathias has even done some work towards that solution, and the osgEarth renderer does something similar [7]

Aircraft can define their own views and so on. But only one view can be active at a time. So no matter how many windows and cameras you define in Defaults.xml, they all are relative to the current view in FG (i.e. cockpit, tower...). [8]

Back in 2008, Tim Moore provided a patch (mailing lists search for CameraGroup FlightGear Mailing Lists) to use the osgViewer class to set up windows, manage the main camera, etc. [9]

However, these windows have to use the same camera group as the main window so can only show the view from the same eye position, though typically at a different angle/offset so that one can emulate things like side windows of a cockpit displayed in a different window or monitor.[10]

There is some tight coupling between the Renderer.cxx and CameraGroup files (now to be found in SimGear[11]) The camera-infos can be configured from XML, eg to additional post-processing stages, but within each CameraInfo the actual osg::Cameras (each of which is really a rendering pass/stage) is determined by one of the buildXXXXX methods.[12]

Mathias Fröhlich used the slave camera feature of osgViewer to provide a "video wall" style of multiple displays that was demonstrated at LinuxTag for years. Later on, Tim generalized this to support general monitor arrangements (like a panoramic arc) and general combinations of screens and graphics cards. [13]

The default OSG model is that slave cameras are different views offset from a common viewpoint. This is easy to understand when considering a camera's view matrix, but not necessarily intuitive when thinking about the projection matrix. Because FG has its own view system we mostly treat the slaves as independent. It seems that most other uses of cameras during rendering -- for example, render to texture cameras for effects -- are best handled by slave cameras with independent views as well.[14]

People requiring multiple independent views on the same scenery, e.g. cockpit and tower view [...] these each need their own camera groups and so require OSG's CompositeViewer.[15]

And that's not really supported by the current architecture, neither by the tile cache nor by osgViewer::Viewer. We would need to move to a CompositeViewer model, which supports several scene graphs, and rely completely on the osg database paging machinery.[16]

That would require a change in current fg architecture to use a CompositeViewer instead of a single Viewer, but we're contemplating that anyway.[17]

The cameras in a camera group don't need to render directly to the screen. They can render to a texture which can be used either in the scene, like in a video screen in the instrument panel, or for distortion correction in a projected or dome environment. [18]

Open Scene Graph supports a CompositeViewer object that supports rendering from several widely separated viewpoints, complete with support for multiple terrain pager threads. We could move to CompositeViewer and support simultaneous views from e.g., the tower, AI models, drones, etc.[19]

Neither of these are supported at the present time, but it would be a good project. We would have to start using a different OSG class, CompositeViewer, to support multiple views from independent view points. Our terrain pager would need a complete overhaul to use the PagedLOD scheme of OSG, and the Flightgear View manager would need to be aware multiple active views.[20]

Status

Note  There is a related patch available at https://sourceforge.net/u/cgdae/flightgear/ci/7ae9a72e656df8c7166bad53638b2f3efdb4e140/

In 07/2020, Julian Smith reported mixed success by crudely changing flightgear's FGRenderer's osgViewer::Viewer to an osgViewer::CompositeViewer with a single osgViewer::View, and patching up all the calling code so it compiles.

It all builds ok, but at runtime it appears to stop making progress at 'loading scenery' - the splash screen stays in place with the scrolling blue line at the bottom.

Feature Status Notes
Scenery/Terrain missing -
Aircraft seems ok -
Skydome seems ok -
PUI GUI seems ok -


Scenery/Terrain broken

Julian's first step was simply to try to change fgfs's use of a Viewer to a CompositeViewer with a single View; in theory this should result in no change to the existing behaviour (as per [1]), and would give us something on which we could add new view windows etc. Unfortunately it seems to mess up scenery loading.[21]

Presumably there's some messaging or synchronisation broken? Or maybe something more fundamental.

All threads are blocked apart from the main thread which appears to be running the loop in fgOSMainLoop().[22]

Caution  Be aware that some VPB (WS3.0) rendering code was added at the end of June 2020 to 'next' (see [23]).

Scott saw the same behavior with the splash screen. He assumed some critical logic was being bypassed when the new VPB code was enabled. He hasn't been able to troubleshoot this more, so his workaround was to launch FG with VPB disabled (via /scenery/use-vpb) and then enable it once beyond the splash page.[24]

Fernando reported it looks like the property /sim/sceneryloaded isn't being set to true, that's why the splash screen doesn't go away. If you force it to true through Phi, everything except the terrain shows properly (aircraft, skydome, GUI,etc.)

There are probably some hard-coded assumptions in the terrain loading part of either SG or FG.[25]

For now, it seems we 'Cant Use' CompositeViewer because of $reasons in the Effects code[26]. Maybe the reason is simply that it needs some work to move away from the single CameraGroup, however.[27]

Also, a number of senior contributors have previously pointed out how our existing tile manager/paging infrastructure may not yet be in shape for a CompositeViewer port, poweroftwo's osgEarth port however is using OSG's PagedLOD exclusively, and osgEarth itself is known to support CompositeViewer[28], too: https://gitlab.com/poweroftwo

So, to troubleshoot this further, it'd make sense to exclude the usual suspects one by one:

  • disable multi-threading
  • disable scenery/terrain
  • use Draw masks
  • disable effects

At that point, we should be able to nail down where the culprit is, i.e. what needs changing.

Jules shared the patches so that people more familiar with OSG can hopefully make some progress here.[29]

He also added lots of diagnostics trying to figure out why scenery isn't being loaded: https://sourceforge.net/u/cgdae/flightgear/ci/eea77c18e29a7a8660a0e4b61fa687d937d0997e/

when loading, we call SceneryPager::PagerRequest::doRequest(SceneryPager* pager) which calls pager->requestNodeFile() which is an alias for osgDB::DatabasePager::requestNodeFile().

With vanilla fgfs, this eventually results in a call to: simgear/simgear/scene/tgdb/ReaderWriterSTG.cxx:700:ReaderWriterSTG::readNode()

But with the CompositeViewer changes, this never seems to happen.

Presumably osgDB::DatabasePager::requestNodeFile() is making some sort of callback after it has (while running in a separate thread) loaded the requested file.[30]

Use Cases

Cquote1.png I have to create two master cameras to controls the two different views in two different scene rendering dynamically.


but flightgear only using viewer class . This is createing one master camera no.of slave cameras. but i need CompositeViewer class. how to use CompositeViewer class in flightgear and how to render through CompositeViewer class.


Cquote2.png


Cquote1.png What i want to achieve: Multiple views of the same scene . Lets call them View1 and View2(they may be on 2 separate screens). There should be only one instance of flightgear running. I should be able to have "View1 = Cockpit View & View2 = Chase View" or "View1 = Helicopter View & View2 = Cockpit View" or any other such combination of views. I am using FlightGear 2.0.0 I should be able to switch the view in each viewport without affecting the view in the other view port. i.e i should be able to double right click and change the view on each display with the mouse without affecting the view in the other display. README.multiscreen in the FlightGear documentation says its possible to create a master camera and a slave camera that is offset from the master camera. BUT I want 2 master cameras that can switch to any view at any time.[31]
Cquote2.png
Cquote1.png I have just been trying out the multiple screen feature in FG. I found that the GUI camera (including the menu bar, hud and 2D panel) appears in only

one of the windows. Is there any way I can make the GUI to appear in all the windows? Actually I want to be able to view the hud and 2D panel in all the windows.

Also when I change the view in any one of the windows, the view changes in the other windows as well. Is it possible to make the windows independent of each other. I want to display the cockpit in one window at all times, in the second window I want to be able to shuttle between helicopter / chase or model views.

Also I have observed that in the second screen where I'm displaying lets say the Helicopter view the aircraft remains static while the environment moves. This is because the cockpit view in my Master screen is defined as 'lookfrom'. Can I define 'lookfrom' for one screen and 'lookat' for the

other screen.[32]
— Kavya Meyyappan
Cquote2.png

Known Limitations

There are a few limitations of the FlightGear multi-camera/view/display system. Tim Moore is the person who developed this feature (nothing existed before his efforts) and maybe he can offer more insight.


1rightarrow.png See FlightGear and OpenGL ES for the main article about this subject.

For example, in the case of:

there would need to be some significant code restructuring to allow these to be displayed on other windows.[33]

There's a limitation in Plib that forces the GUI to be drawn on one window.[34]

Implementation

Most of the required PagedLOD work (involving the tile manager in SimGear) has been recently completed - so there isn't too much missing in terms of refactoring on the SG side - primarily, you'll want to look at the "view manager" in $FG_SRC/Viewer and identify "singleton" use-cases there.


Note  There is a related patch available at https://forum.flightgear.org/viewtopic.php?f=71&t=23929#p317448


  • First of all, you'll have to replace the existing viewer with a single CompositeViewer - FlightGear's view manager is property-controlled, and there's currently the hard-coded assumption that there's only ever a single active MAIN view (other supported views are SLAVE views, i.e. slaved to the main view).
  • You'll find dozens of references to something like globals->get_view_mgr() in quite a few places demonstrating the underlying assumption.
  • So just change the function's signature and add an optional index, defaulting it to 0 - that way, you won't have to touch all the places wanting to have the single main view.
Note  For starters, it would also make sense to disable the splash screen, multi-threading, and scenery/terrain loading entirely, just to have something really basic working and then take it from there (i.e. use --disable-scenery, or refer to the Minimal Startup Profile).

Once that is working, it comes down to trial & error, i.e. testing multiple independent viewers, each having their own instance/access to the tile manager - the work itself is well understood and pretty straightforward, and pretty much all core developers agree that this is a worthwhile thing to aim for - it's just not currently being prioritized or being worked on by anybody else as far as I am aware.

If you're interested in seriously pursuing this, you'll want to look at the CompositeViewer example in the OSG source tree, and read up on discussions about CompositeViewer coding on the OSG list.

For the SG/FG side of things, the aforementioned wiki articles should be pretty comprehensive already - and then you'll probably want to get in touch with fellow FG developers using the FG developers mailing list.

Depending on your degree of familiarity with OpenGL/OSG coding, you could have a basic version of this running within 3-4 weekends - but I guess it might take at least another 4-6 weeks of spare time coding to actually tease out all the hard-coded assumptions about having a single main view only.

The other issue is getting your work reviewed, i.e. committed upstream, which is known to be a particularly long, tedious and painful process - especially for anything non-trivial that may possibly break critical parts of the simulator - which is why it's a good idea to start networking early on, i.e. by discussing this work way ahead of time and getting people involved to provide feedback - which may involve working through a gitorious topic branch.

The underlying PagedLOD work in SimGear work is generally understood to be vital for other parts of the simulator (especially better multi-threading and LOD support), so anything related to this should also be appreciated.

Related

Docs

Discussions

Search

References

References
  1. https://sourceforge.net/p/flightgear/mailman/message/37758886/
  2. https://sourceforge.net/p/flightgear/mailman/message/37057525/
  3. https://sourceforge.net/p/flightgear/mailman/message/37058200/
  4. http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg28864.html
  5. https://sourceforge.net/p/flightgear/mailman/message/30235494/
  6. https://sourceforge.net/p/flightgear/mailman/message/31981615/
  7. https://sourceforge.net/p/flightgear/mailman/message/31981671/
  8. http://forum.flightgear.org/viewtopic.php?p=146136#p146136
  9. https://sourceforge.net/p/flightgear/mailman/message/19718339/
  10. https://sourceforge.net/p/flightgear/mailman/message/37059117/
  11. v
  12. https://sourceforge.net/p/flightgear/mailman/message/35828189/
  13. https://sourceforge.net/p/flightgear/mailman/message/24811861/
  14. https://sourceforge.net/p/flightgear/mailman/message/36295606/
  15. https://sourceforge.net/p/flightgear/mailman/message/37059117/
  16. http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg28869.html
  17. http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg17263.html
  18. http://sourceforge.net/p/flightgear/mailman/message/19718339/
  19. http://sourceforge.net/p/flightgear/mailman/message/19718339/
  20. =http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg27134.html
  21. https://sourceforge.net/p/flightgear/mailman/message/37059932/
  22. https://sourceforge.net/p/flightgear/mailman/message/37057525/
  23. https://sourceforge.net/p/flightgear/flightgear/ci/034c9f4c86df1ed9355aa3501c617d1226578023/
  24. https://sourceforge.net/p/flightgear/mailman/message/37058961/
  25. https://sourceforge.net/p/flightgear/mailman/message/37058200/
  26. https://sourceforge.net/p/flightgear/mailman/message/26189393/
  27. https://sourceforge.net/p/flightgear/mailman/message/37059939/
  28. https://github.com/gwaldron/osgearth/issues/1300#issuecomment-565734550
  29. https://sourceforge.net/p/flightgear/mailman/message/37058676/
  30. https://sourceforge.net/p/flightgear/mailman/message/37059972/
  31.  (). Multiple views without slaving to master camera.
  32. Kavya Meyyappan (Fri, 19 Mar 2010 03:31:50 -0700). [Flightgear-devel] Help needed with multi-screen.
  33. http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg27114.html
  34. http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg27134.html