Shared render targets and viewports in compositor passes Topic is solved

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


User avatar
bishopnator
Gnome
Posts: 388
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 18

Shared render targets and viewports in compositor passes

Post by bishopnator »

Hi, I would like to reuse a render targets between the compositors between different windows. The render targets are passed as inputs to the workspaces during creation and I want to only enlarge them instead of adapting the size to match the final RT size to avoid useless resizing when a window is resized. The problem is how to setup the viewports in the CompositorPassSceneDef as the values are relative to the current render target.

Imagine that I have a rendering technique which needs to render scene in intermediate texture and then use the rendered content in another pass. I have 2 windows - 600x400 pixels and 300x200 pixels. Both windows can use the same intermediate texture, but the viewports will be different, but both are adapted to the final RT size. Is there support like this? Is it possible to achieve this with a single instance of the CompositorPassSceneDef used by both windows?

Also it would be great to setup the definition to match the final RT size exactly 1:1 instead of using doubles as the windows can have arbitrary sizes and there could be +/-1 pixels differences if the relative sizes are used.

User avatar
bishopnator
Gnome
Posts: 388
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 18

Re: Shared render targets and viewports in compositor passes

Post by bishopnator »

It is possible to achieve the desired results with a combination of CompositorPassDef::mViewportModifierMask and CompositorWorkspace::setViewportModifier/setViewportModifierMask. It is little bit awkward that as soon as I start using it, I have to manually set the mViewportModifierMask to 0 to all passes whether the resizing should be done to the whole render target (default value is 0xff so my workspace's modifier is then automatically applied everywhere :-( .. this seems little bit strange).

The 1-pixel problem remains there as the modifier is always relative. Probably I have to deal with it using +0.5pixel size when calculating the scale factors to about rounding problems when resulting value is converted from float to int (e.g instead of "pFinalRT->getWidth() / pTexture->getWidth()" one has to use "(pFinalRT->getWidth() + 0.5f) / pTexture->getWidth()". I am still evaluating the possibilities which ogre offers me.

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

Re: Shared render targets and viewports in compositor passes

Post by dark_sylinc »

bishopnator wrote: Mon Jul 27, 2026 10:04 am

Imagine that I have a rendering technique which needs to render scene in intermediate texture and then use the rendered content in another pass. I have 2 windows - 600x400 pixels and 300x200 pixels. Both windows can use the same intermediate texture, but the viewports will be different, but both are adapted to the final RT size. Is there support like this? Is it possible to achieve this with a single instance of the CompositorPassSceneDef used by both windows?

I don't understand your example. In OgreNext the viewports are in range [0; 1] so I don't get how is that a problem.
But more importantly, if you pass a RenderTexture under your control, there is one big way to get it on screen on both windows (600x400 and 300x200) and that is through a render quad pass.

Thus your texture would get scaled/stretched. I'm guessing that's not what you want. But I don't understand what you want to do. You said 2 resolutions, but your render texture is a 3rd resolution.

What would be the 3rd render texture's resolution be?

Let's say they are:

  1. RT = 600x400
  2. Window0 = 600x400
  3. Window1 = 300x200

I assume you want to copy RT -> Window0 1:1, but what about Window1? You want to copy the first quarter of RT? Stretch it?

And in both cases the viewport isn't involved, but rather the input parameters to material in the quad pass so you can control what portion of the RT gets copied.

Thus I would need more details on what you're trying to achieve.

User avatar
bishopnator
Gnome
Posts: 388
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 18

Re: Shared render targets and viewports in compositor passes

Post by bishopnator »

For simplicity assume, that I need to render planes of the triangles storing in RGB32_FLOAT texture (so cofficients a,b,c,d), which I then use in next pass - let's say here directly to the window (as final RT). The texture containing the rendered planes can be reused for both windows - so the window 600x400 and 300x200 uses same texture. To avoid too many resizing, I am resizing the planes texture to power of 2 - so it will have size 1024x512 (next power of 2 for the bigger window).

The my rendering technique has more passes with multiple color buffers bound:

  1. render triangle planes + my object IDs + triangle facing + .. (2 textures of RGB32_FLOAT)
  2. render just lines using textures from the previous pass (2 textures RGB8_UNORM - visible and hidden lines)
  3. compose the 2 textures from the previous pass using fullscreen quad.

Here is the result of rendering same scene in 2 windows using slightly different rendering settings for the hidden lines.

Image

Last edited by bishopnator on Thu Jul 30, 2026 6:53 pm, edited 1 time in total.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5576
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1411

Re: Shared render targets and viewports in compositor passes

Post by dark_sylinc »

AHHH. Now I get it.

You have a bigger RT that you reuse and recycle, and it may be bigger than the Window, but excess is simply treated as padding.

The use of modifier masks sounds like the best approach in OgreNext as far as I can see.

And yes, you have to double check that floating point -> uint conversion results in the right value. Basically:

Code: Select all

assert( uint32( ((Real(pFinalRT->getWidth()) + epsilon) / Real(pTexture->getWidth())) * pTexture->getWidth() == pTexture->getWidth() );
User avatar
bishopnator
Gnome
Posts: 388
Joined: Thu Apr 26, 2007 11:43 am
Location: Slovakia / Switzerland
x 18

Re: Shared render targets and viewports in compositor passes

Post by bishopnator »

Yes, that's a good idea with the assert.