how to replace a viewport

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
rrl
Halfling
Posts: 73
Joined: Sun Jun 04, 2017 12:33 am

how to replace a viewport

Post by rrl »

I'm trying to understand how viewports work in 2.3 and have been reading over some very early posts about the change to compositors but I haven't been able to wrap my head around them.

I think what I'm trying to do should be quite simple. I have an item (axes.mesh) attached to a sceneNode which rotates at the center of the screen but I would like to place it in a corner of my window which I *think* requires the use of a viewport positioned in the corner with a fixed camera. So when my model rotates, the axes rotate, but no transition.

Can anyone break this down into laymans terms using 2.3?

In my code I have the following in a setupCompositor() function. Is it just a matter of setting up another workspace with a new name, seperate camera, seperate Ogre::Window, and it's own sceneManager?

Code: Select all

        return compositorManager->addWorkspace(sceneManager,
            renderWindow->getTexture(), camera, workspaceName, true);

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

Re: how to replace a viewport

Post by dark_sylinc »

Because the compositor now manages viewports, the answer is often the compositor replaces a viewport!

There are various ways, the most basic one:

Code: Select all

render_pass
{
    rq_first 0
    rq_last 240
}

render_pass
{
    viewport top left width height
    camera "MyCustomCamera"
    rq_first 240
    rq_last 241
}
In this example I assume:
  • The 1st pass is the regular pass. All your objects are somewhere between render queues 0 and 239
  • The 2nd pass is your axis object and are living in render queue 240
  • You will create a camera with name "MyCustomCamera"
  • viewport 'top left width height' must be actual floating point numbers
You can alter this example:
  • You can use visibility_mask keyword instead of render queue IDs to control visibility. However please take note that splitting by render queues is a performance optimization: we can skip all objects living in render queues we want to ignore. But with visibility masks we still have to process all objects to see which ones match and which ones don't
  • If you don't want to hardcode the camera name, you can place the 2nd compositor pass in it own workspace alone and send the camera in addWorkspace. Conceptually the idea is not too different from what StereoRendering sample does (StereoRendering renders the same scene twice, once to the left half, then to the right half, using two different cameras. However in StereoRendering we reuse the same workspace while you would need two different ones)
  • If you want to control the viewport size dynamically at runtime, use viewport modifier masks (see StereoRendering sample)
Cheers
Matias

rrl
Halfling
Posts: 73
Joined: Sun Jun 04, 2017 12:33 am

Re: how to replace a viewport

Post by rrl »

I'm trying to place the 2nd compositor pass in it's own workspace and send the same camera I'm using for the main rendering to the axes workspace as well. So I have two workspaces. I've changed setupCompositor() in my GraphicsSystem to the following.

Code: Select all

void GraphicsSystem::setupCompositor(void)
    {
        Ogre::CompositorManager2 *compositorManager =
            root->getCompositorManager2();

	// first workspace, has black background.
        const Ogre::String mainWorkspaceName("MyRenderingWorkspace");

        if (!compositorManager->hasWorkspaceDefinition(mainWorkspaceName)) {
            compositorManager->createBasicWorkspaceDef(mainWorkspaceName,
                backgroundColor, Ogre::IdString());
        }

        workspaces->push_back(compositorManager->addWorkspace(sceneManager,
            renderWindow->getTexture(), camera, mainWorkspaceName, true));

	// second workspace for axes, has blue background
        const Ogre::String axesWorkspaceName("Axes Workspace");

        if (!compositorManager->hasWorkspaceDefinition(axesWorkspaceName)) {
            compositorManager->createBasicWorkspaceDef(axesWorkspaceName,
                axesBackgroundColor, Ogre::IdString());
        }

        workspaces->push_back(compositorManager->addWorkspace(sceneManager,
            renderWindow->getTexture(), camera, axesWorkspaceName, true));

        return;
    }
I've not used scripts before, but here was my first go. I made this script by looking over StereoRendering.compositor.

Code: Select all

compositor_node MyRenderingNode
{
    render_pass
    {
        rq_first 0
        rq_last 240
    }

    render_pass
    {
        viewport 0.0 0.0 40.0 40.0

        rq_first 240
        rq_last 241
    }
}

workspace MyRenderingWorkspace
{
    connect MyRenderingNode 0
}
What I don't get is that my entire screen is blue, so it would appear the size I have in viewport is not correct. I was expecting to see a small blue background in the top left corner of my screen. And I don't get how the 2nd workspace would be referenced in that compositor script. I'm sure I probably don't have the workspace part of this script correct.

Ideas?

Also, any links to references on how to do scripting like this?

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

Re: how to replace a viewport

Post by dark_sylinc »

Hi!

The size is in range [0; 1] as described in the manual.

rrl
Halfling
Posts: 73
Joined: Sun Jun 04, 2017 12:33 am

Re: how to replace a viewport

Post by rrl »

I've been reading through the compositor link, but don't quite understand how to connect nodes in the way that I need to use them. Since I'm using workspaces, I figured that each workspace only has to care about it's own node and that no outputs from one pass/workspace lead to inputs to another pass/workspace.

So far I've managed to piece together what I have below, but I'm still not seeing a "viewport" that shows anything (or even just the blue background color for it).

Code: Select all

compositor_node MyRenderingNode
{
    in 0 rt_renderwindow

    target rt_renderwindow
    {
        pass render_scene
        {
            rq_first 0
            rq_last 240
        }
    }
}

compositor_node AxesRenderingNode
{
    in 0 rt_renderwindow

    target rt_renderwindow
    {
        pass render_scene
        {
            viewport 0.0 0.0 0.2 0.2

            rq_first 240
            rq_last 241
        }
    }
}

workspace AxesRenderingWorkspace
{
    connect_output AxesRenderingNode 0
}

workspace MyRenderingWorkspace
{
    connect_output  MyRenderingNode 0
}
Anyone have ideas where I'm going wrong?

Post Reply