Page 1 of 1

[2.1] Show overlays only in specific Scene / Renderwindow

Posted: Wed Dec 12, 2018 2:37 pm
by gabbsson
Hello! Sorry for another big post!

I have a setup of Qt and Ogre working with multiple viewports (basically when I say viewport I mean a QWidget with a RenderWindow, so it is basically safe to think renderwindow). Also when I write overlay I just mean something that is drawn on top of the 3D viewport, not necessarily an Ogre object. Each viewport is connected to a SceneManager, so there can be one SceneManager per viewport or they can all show the same scene (or anything in between).

The first time I ran into problems was when implementing a combination of MovableObject and OverlayElement to show text which followed the projected position of a SceneNode. Basically text which has a position in the scene but does not scale with camera etc. By default all overlays show in every viewport (if the overlaysystem is added as a listener to the scenemanager). Since these overlays exist in a specific scene I solved it by creating a custom RenderqueueListener which shows/hides OverlayElements based on which Overlay (I have assigned one per SceneManager) they belong to. Please let me know if there is a better solution!

Now my latest issue is similar, I want to add overlays which "belong" to a specific viewport. For example I might want to show a "Colorbar Overlay", like the ones found in plots, in one viewport but none of the others.

I went back to my old solution to see if it could be extended but I can't find a way to replicate what I did previously with scenemanagers.
Next I started digging in the source for OverlaySystem and OverlayManager but I'm not confident I see a way to solve this still.
There seems to be support for turning all overlays on and off per Ogre::Viewport but not showing/hiding specific ones.

I want to be able to define overlays which exist on SceneManager level and viewport level.
Meaning overlays drawn in a viewport are drawn only if it "belongs" to the scene or the viewport itself.

Is there a way to make overlays only show on specific Camera/Renderwindow?
Also; is my way of filtering based on scene manager a good solution or is there a more efficient way?



To give some context I have a bunch of overlays made in Qt which draw using a QPaintDevice. Now after updating to use Ogre I have "ported" them to draw onto an Ogre Texture which is applied onto a OverlayElement (panel). This was required because I never could manage to get Qt to draw widgets on top of the viewport with transparency. So I have one OverlayElement per viewport which I would like to show for only the specific viewport.

Re: [2.1] Show overlays only in specific Scene / Viewport

Posted: Wed Dec 12, 2018 6:17 pm
by dark_sylinc

Starting Ogre 2.0; the Viewport class is internal i.e. you should not be manipulating them directly. Doing so can cause rendering artifacts or obscure bugs.
The role of Viewport is replaced by CompositorPass (or CompositorWorkspace depending on what you're doing).

As such, overlays are toggled in pass_scene passes:

Code: Select all

target rt_renderwindow
	pass render_scene
		overlays	on
either via Compositor scripts or via code (See CompositorPassSceneDef, be careful that you shouldn't modify the definition while there are active instances).

See the Compositor section in the manual.


Re: [2.1] Show overlays only in specific Scene / Viewport

Posted: Thu Dec 13, 2018 9:52 am
by gabbsson
I regret using the word viewport, I never meant Ogre::Viewport, I never use that. And when I did mention it in reference to reading the source I never meant I wanted to access or change it. When I wrote viewport I meant a Qt object which shows ogre (by sending window id to a renderwindow). Sorry for the confusion!

But back to my problem:

The example you posted says "overlays on", so either all overlays are shown or none right? Are there any other options?
Some way to group overlays by Scenemanager or Renderwindow/Camera?

I have tried to create a diagram to show what I am after:

My thinking is that by following an arrow from an overlay you see in which renderwindow they are shown.
Thats the type of filtering/grouping of overlays I want to acheive.

Is that possible?

Edit: I will read up on compositor passes! Replied the above to hopefully clear up any confusion.

Re: [2.1] Show overlays only in specific Scene / Renderwindow

Posted: Thu Dec 13, 2018 2:39 pm
by dark_sylinc
Ahhh I see.

Selectively choosing which Overlays are displayed.

As far as I know that is not possible (the Overlay system is oooold).

However it may be possible to use a CompositorWorkspaceListener, overload passPreExecute function; and toggle the visibility of the overlays you want for that particular pass.

I don't know if toggling the Overlays visibility like that has a performance cost or not.

Re: [2.1] Show overlays only in specific Scene / Renderwindow

Posted: Thu Dec 13, 2018 3:25 pm
by gabbsson
Thanks I'll check it out!

Since I handle my Qt overlays (per renderwindow) with a single Ogre::TexturePtr put into a datablock and then an overlay maybe I can find a way just render the textures that belong to each respective renderwindow (dawned on me when you brought up compositors and so on), that should also be sufficient and then I'll just keep doing what I am doing in the renderqueuelistener for scenemanagers.

Whichever has the best performance.

Re: [2.1] Show overlays only in specific Scene / Renderwindow

Posted: Thu Dec 13, 2018 4:44 pm
by gabbsson
Seems to work just fine!

For anyone trying to replicate this:

When I create my Ogre::CompositorWorkspace I also create a new overlay that "belongs" to the renderwindow (and workspace) which I pass to a customized CompositorWorkspaceListener.

In pre and post execute I toggle the elements inside the overlay on and off. I'm guessing its not optimal with a ton of elements, but I will always have one per renderwindow. The scenemanager however is a different story, but this is analogous to what I did now but with renderqueue, so I'm guessing thats the proper solution there too.

Thanks again!