MRTs in compositor scripts

· by Steve · Read in about 2 min · (394 Words)

Although I’m more mobile than I was last week, it’s still too painful to be on my feet very much right now (and you should see the colour of my toes - ugh; doctor says it’s because my partially torn tendons have been bleeding internally leaving nice black / purple appendages), so I pottered about on the computer for a few hours instead of getting out at the weekend. Today’s result is, for anyone who might be interested, support for defining Multiple Render Targets (MRTs) in compositor scripts. It’s one of those things that’s been missing for a little while and you had to set them up manually in code (as demonstrated in the Deferred Shading demo). People had mentioned this deficiency in the forum but I hadn’t had time to deal with it before, but it came up again recently whilst working for a client. We didn’t address it then, but I decided to come back to it today. Now you can do this when you’re defining your RTTs at the start of the technique:

That would set up a MRT with 4 32-bit surfaces, 2 RGBA and 2 single-channel floating point. Ogre will internally create that as 4 render textures and a surrounding MultiRenderTarget to handle rendering to all 4 at once (remember, you have to have shaders capable of doing this - don’t try to mix fixed-function or single-output shaders in here, plenty of hardware hates that and behaves weirdly if you do it). Of note here is that most cards (pre 8800) cannot handle mixing bit depths here, so make sure the formats you use are the same bit depth. If you try to run this on a card which can’t handle 4 MRTs then it will mark the technique as unsupported and try the next one.

Later on in your script when you’re hooking up the RTTs to your full-screen quad shader, you can bind the subsurfaces of the MRT just like regular textures - you just have to qualify the name of the texture with a MRT surface index, like this:

That binds sampler 0 to use the second surface of mrt0, sampler 1 to use the third surface, and sampler 2 to the first MRT surface (I’ve jumbled them up just to illustrate what the indexes mean).

So there you go, it’s in CVS now - enjoy.