Compositor and manual texture

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
hohohmm
Gnoblar
Posts: 22
Joined: Mon Oct 24, 2011 6:17 am

Compositor and manual texture

Post by hohohmm » Tue Nov 15, 2011 10:53 am

I've implemented a global bloom shader as well as the glow shader detailed on the wiki. The glow shader renders scene twice and it's causing slowdown on ipad. I have a background image which I don't want bloom. So if I use the bloom shader directly, everything in the background image seems overexposed. All I need to do is render the background to a texture, then render everything else with bloom. I've read the compositor manual but I don't see a way to allow only a subset of nodes to be rendered(the background is attached to a scene node). Alternatively I could manually render the background to a texture, but how do I reference that texture in my compositor script? Thanks!
0 x

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4293
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: Compositor and manual texture

Post by spacegaier » Tue Nov 15, 2011 11:18 am

The way I did it was, to add a render listener (don't know the exact name right now) that gets called each frame and will set the color for all materials that do not have a specific "schema" to black or invisible (not sure right now which one it was). So in the texture for the compositor you see only the objects that should be glowing. Then the compositor shader does it magic and afterwards the result texture is added to the normal render scene.

I might try to dig the stuff out later at home. Perhaps even put it in the wiki...
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

hohohmm
Gnoblar
Posts: 22
Joined: Mon Oct 24, 2011 6:17 am

Re: Compositor and manual texture

Post by hohohmm » Tue Nov 15, 2011 11:28 am

Thanks for the quick reply. That's what I'm doing already, add a material listener and set a black material on everything that doesn't glow. But it requires rendering my entire scene twice, only to avoid bloom on the background.

I want a way to say (either in code, or in compositor),
render background geometry to texture texBG
render everything else to texFG
bloom texFG
composite texFG & texBG.

This only renders scene once, and provides better quality bloom since texFG is now full resolution, otherwise I have to scale second render down to increase speed(it's ipad 2).
0 x

hohohmm
Gnoblar
Posts: 22
Joined: Mon Oct 24, 2011 6:17 am

Re: Compositor and manual texture

Post by hohohmm » Sat Nov 19, 2011 7:02 am

Could moderator move this thread to help forum? It's probably more fitting there and may get the attention from the right people. Thanks.
0 x

User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
Contact:

Re: Compositor and manual texture

Post by duststorm » Tue Nov 22, 2011 11:52 am

I don't see how you can render two different scenes to two different textures and only do one render.

A solution could be, if you want to render a scene mostly without bloom, and then render some objects in the foreground with bloom:
- render background scene to texture, with the foreground geometry set to invisible.
- now hide the background geometry and only set the foreground geometry to visible (make sure the viewport color is black or something that it allows compositing)
- composite those two textures together

This way you don't re-render all geometry but only that in the foreground. No idea how much time this will save you, as I can imagine most time is spent in pixel shaders instead of vertex shaders (the vertex count of the foreground scene would be seriously reduced).
Because bloom is a compositing effect that is applied on the rendered image you can't just set materials with different shaders to objects to enable or disable the effect. You could work with occluders or masks (a pixel shader that just returns a single color for a mesh that acts as a mask in your compositor). But you will never get around doing at least two render passes.
Maybe you can optimize it if you create a custom bloom shader, that not only takes the rendered image, but also a mask texture. For certain color values on the mask texture it will not apply bloom on the final image. Creating the mask image would still involve rendering a second time, but you could either do this as explained above with only the foreground geometry enabled and a very simple pixel shader (that only returns a solid color).

For swapping materials on objects you could create a custom material listener that acts on materialSchemeNotFound events.

In an attempt to clarify a bit more why you would need at least two passes:
Compare a compositor shader to a photoshop (or gimp) filter, for example a blur or overexpose filter. You can only apply the filter to a full layer (let's ignore selections here for a second). If you want to apply a bloom filter to the background but not to some foreground objects you need to cut out those foreground objects and put them on another layer, that is put on top of the background. In order to create those two separate layers, or create a mask to determine where they should be cut, you really need to do a second render pass because you need a way to determine which pixels on the screen should not be affected by the bloom effect.
In fact compositors really do work like photoshop filters.
0 x
Developer @ MakeHuman.org

Post Reply