Jump to content

  • Log In with Google      Sign In   
  • Create Account

Blending Render Targets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Orangeatang   Members   -  Reputation: 1499

Like
0Likes
Like

Posted 20 April 2013 - 05:44 AM

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, 20 April 2013 - 05:46 AM.


Sponsor:

#2 BornToCode   Members   -  Reputation: 925

Like
1Likes
Like

Posted 20 April 2013 - 10:41 AM

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.

#3 kauna   Crossbones+   -  Reputation: 2507

Like
2Likes
Like

Posted 20 April 2013 - 11:52 AM

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, 21 April 2013 - 07:21 PM.


#4 phil_t   Crossbones+   -  Reputation: 3904

Like
2Likes
Like

Posted 20 April 2013 - 12:02 PM

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



#5 Orangeatang   Members   -  Reputation: 1499

Like
0Likes
Like

Posted 20 April 2013 - 02:47 PM

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, 20 April 2013 - 02:49 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS