MaskRendering and Compositors

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
nickw
Gnoblar
Posts: 6
Joined: Sat Sep 09, 2006 11:54 pm

MaskRendering and Compositors

Post by nickw » Sun Sep 10, 2006 12:31 am

I have an idea for an extension of the Compositor system that I would like to call RenderMask. A RenderMask is basically rendering a subset of the objects on screen (or viewport) to create a mask for post-rendering effects.

The extension would affect two areas of the current scripting setup:

First, you should be able to (optionally) set a different material process for each mask. For example:

Code: Select all

material CharacterTexture
{
	mask "Bloom"
	{
		technique GLSL
		{
			...
		}

		technique DX9
		{
			...
		}
	}

	mask "EdgeWiden"
	{
		...
	}

	mask "Default"
	{
		...
	}
}
The "Default" mask would be the normal texture that is used for rendering to the main target. This, again, could be optional.

Secondly, in compositor scripts, you could specify that a mask the source for a render target, as well as optionally copying the depth/stencil buffer from the viewport. For example:

Code: Select all

compositor CrazyCompositor
{
	technique
	{
		texture rt0 target_width target_height PF_A8R8G8B8
		texture rt1 128 128 PF_A8R8G8B8
		texture rt2 128 128 PF_A8R8G8B8

		target rt0
		{
			input previous
		}

		texture rt1
		{
			input_mask "Bloom"
			depth_copy previous
		}

		texture rt2
		{
			input_mask "EdgeWiden"
		}

		target_output
		{

			input none

			pass render_quad
			{
				material Ogre/Compositor/Crazy
				input 0 rt0
				input 1 rt1
				input 2 rt2
			}
		}
	}
}
It would be possible to determine which scene nodes should be rendered for any particular RenderMask by flagging which masks are defined in each material, and propogating that information to the entities and scene nodes when they become attached. This would mean that in addition to SceneManager culling, only a few objects could be rendered for each mask, making it quite fast. Additionally, copying the depth buffer from the viewport to the render target would allow things like occulsion queries and such to speed up rendering even more.

Is this idea possible/feasible/useful?
0 x

User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US

Post by xavier » Sun Sep 10, 2006 12:40 am

Everything you mentioned is already in place and working in the Compositor framework -- does your suggestion just coalesce these various features under a single name?

Look in the manual for the part on Compositor passes:

http://www.ogre3d.org/docs/manual/manual_24.html#SEC123

Specifically, the "stencil" pass which is the "mask" you are talking about, the "render_scene" pass which allows you to render all or a subset of your scene, as well as the "identifier", "first_render_queue", and "last_render_queue" which work in tandem with "render_scene" to let you determine what to render in "render_scene" passes.
0 x

nickw
Gnoblar
Posts: 6
Joined: Sat Sep 09, 2006 11:54 pm

Post by nickw » Sun Sep 10, 2006 1:04 am

Yes, it is similar, but there are a few key differences:

1. The idea is to render to a mask, not neccessarily mask what we're rendering. That is to say, instead of simply rendering to the stencil buffer, we're selectively rendering to a texture (this could be done as you say using the material_scheme, which I didn't know about).
2. Rerendering the entire scene, when all you really care about are a few objects on the screen could be inefficient. It might be better to just copy the depth buffer from one render target to another (since it's already there) for visibility testing.
0 x

User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US

Post by xavier » Sun Sep 10, 2006 1:21 am

You don't have to re-render the whole scene; that's what the render_queue and identifer bits are for: you register a listener for the compositor passes and enable/disable the bits you need to tweak in the scene.
0 x

nickw
Gnoblar
Posts: 6
Joined: Sat Sep 09, 2006 11:54 pm

Post by nickw » Sun Sep 10, 2006 1:43 am

Ah, ok. I was having some trouble understanding the docs I guess. Thanks xavier. Chalk this post up as a big "nevermind."
0 x

Post Reply