Blending Render Targets

Started by
3 comments, last by Capoeirista 10 years, 12 months ago

Hi there!

I'm building a 2D editor at the moment (using Monogame) and was wondering about the best way to blend render targets.

Each scene in the engine is composed of three layers, background, central and foreground... that way I can add objects to a particular layer, apply the effects and lighting I want on said layer without affecting objects in other layers.

Until recently I've been using a single render target to draw the scene (and a light map render target, blending the two together using a simple shader), but since I want lights to take affect in their assigned layer (not across the entire scene) I'm going to have to use separate render targets for each layer, and do a lighting pass for each one.

So at the end of this I'm going to be left with three render targets (lighting + objects in the layer) that I need to apply any post processing effects to, and then blend in to the final scene... and was wondering about the best way to go about this. I assume the only way to really do this is using a pixel shader (to sample each render target and blend the result), but wanted to get suggestions before I go ahead with this.

Also, is this complete overkill? I've not really built a 2D rendering system before, so I'm kind of winging it. I intend to add dynamic shadows on a per-layer basis as well.

Thanks for the help!

Advertisement
You can used two render target and ping pong between them when you creating multiple layer. For example you write to one render target in the first pass. Then in the second to n passes you bind that target to a sampler. Then you can just do a simple additive blending of the layer which is bind with the incoming pixel of the current layer. At the end you will end up with a render target that has all the layers combined.

Are you sure that you can't make it simpler?

Maybe one render target and a stencil buffer would be enough? You can render your scene front to back (or back to front if you need alpha transparency) and set the stencil buffer value to some desired value for each layer.

In the lighting part you may use stencil test to skip pixels not in the lights layer.

Cheers!

[edit] after a little consideration, alpha blending of course will be a problem (if it is required) ... hard transparency will work of course.

Can you describe your lighting a bit more? Is this some sort of deferred lighting or something? (I'm trying to figure out why you need the render targets at all, and can't just draw your objects to the scene directly).

Hey folks, thanks for the responses.

I think I'm making this much more complicated than it needs to be smile.png No there's no deferred lighting going on... It's just your stock standard light maps, and maybe some dynamic shadows a bit later on.

I think I should be able to draw my objects to a single render target and feed the active lights in to shader that's rendering all of the objects. I was thinking that I'd need multiple render targets (one for each layer) so I could blend with the lights in the current layer being rendered... but after sitting on it for a couple of hours I've been making a mountain out of a mole hill smile.png

This topic is closed to new replies.

Advertisement