Sign in to follow this  
Capoeirista

Blending Render Targets

Recommended Posts

Capoeirista    3266

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! 

Edited by Orangeatang

Share this post


Link to post
Share on other sites
BornToCode    1185
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.

Share this post


Link to post
Share on other sites
kauna    2922

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.

Edited by kauna

Share this post


Link to post
Share on other sites
phil_t    8084

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).

Share this post


Link to post
Share on other sites
Capoeirista    3266

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

Edited by Orangeatang

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this