Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Basically, what I'm trying to do is apply a shader to my background image and only the background image. The problem is: the background is actually made up of tiles that are picked out of a list of images. The background code loads and draws the tiles according to a map (an int[,].) I've been reading up on using RenderTarget2d, but I haven't found anything that suggests I'd be able to use specific images (let alone images set up according to a map.) So here's my question: is there a way to render my backgrounds to a texture so I can apply a shader or is there another way for me to apply a shader that I might want to try?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You seem to have already figured out how to do this. Here's the process:

GraphicsDevice.SetRenderTarget(myRenderTarget);
RenderMyBackground();
GraphicsDevice.SetRenderTarget(null);
spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, myShaderEffect);
spriteBatch.Draw(myRenderTarget, Vector2.Zero, Color.White);
spriteBatch.End();
RenderEverythingElse();

You may want to have a look at the Bloom Postprocess sample. There's no reason you have to apply a post-process effect to your entire scene. You can apply it to just your background and then draw the rest of your scene over the top.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.