[2.2+] What's the best way to do mult-viewport rendering

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
rujialiu
Goblin
Posts: 294
Joined: Mon May 09, 2016 8:21 am
x 35

[2.2+] What's the best way to do mult-viewport rendering

Post by rujialiu »

Hi!

We need to do multiple rendering from different cameras into different parts of the screen. There are also parts of the screen only occupied by UI controls. Note that there is only one "native window", and all UIs are drawn in a seprate custom pass. I'm thinking about the following solution:
1. Compositor script: A "single viewport" workspace definition and a "UI only" workspace definition
2. C++ code: create one workspace for each viewport, and one workspace from the "UI only" workspacedef. All these workspace renders to the screen
3. When viewport location/sizes changed, change the viewport workspace's parameter so that they render into desired part of the screen
4. Write some viewport management codes to convert coordinates and inject mouse events and ensure only the focused viewport gets keyboard input. So the logic code can still think it's in "fullscreen" mode.

However, I'm not sure how to render (and clear) only part of the screen. And it looks quite easy to mess things up. Any suggestions or sample codes? Thanks!

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4501
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 936
Contact:

Re: [2.2+] What's the best way to do mult-viewport rendering

Post by dark_sylinc »

rujialiu wrote:
Mon Jun 29, 2020 11:32 am
However, I'm not sure how to render (and clear) only part of the screen. And it looks quite easy to mess things up. Any suggestions or sample codes? Thanks!
The StereoRendering sample (not the InstancedStereo one) shows how to do this (btw I thought you were already familiar with it?):
  1. It clears the whole RenderTarget. Only the first pass does this (via execution_mask) and ignores the viewport settings sent to addWorkspace (via viewport_modifier_mask)
    • Note: APIs do not support clearing regions of the screen. Viewport setting is always ignored
    • You can 'manually' clear a region using a render_quad pass. Preferrably only clear colour, but you can also clear depth setting depth_func to always (why preferrably? because letting the API clear all depth at once allows GPU optimizations at HW level)
  2. Renders the scene. All passes do this, and the region they rendered is controlled via viewport_modifier_mask (which means this pass should be modified by the values you sent to addWorkspace)
  3. Finally render the UI, only the last pass does this (via execution_mask) and ignores the the viewport settings sent to addWorkspace (via viewport_modifier_mask)
Cheers
This is probably not the only way, but it certainly is very similar to what you just described.

rujialiu
Goblin
Posts: 294
Joined: Mon May 09, 2016 8:21 am
x 35

Re: [2.2+] What's the best way to do mult-viewport rendering

Post by rujialiu »

dark_sylinc wrote:
Mon Jun 29, 2020 9:26 pm
The StereoRendering sample (not the InstancedStereo one) shows how to do this (btw I thought you were already familiar with it?):
I know it theoretically but never tried 8-)
I've tried your way and it worked! However, since I'm doing HDR rendering with full-screen postprocessing (SMAA etc), I had to manully disable viewport settings in ALL postprocessing nodes.... and make sure ONLY the last render quad pass that draws the final result to the screen, uses the viewport setting.

it's tedius but not too many, and it just works. Thanks!!!

Post Reply