# Applying effects to an existing program that uses BasicEffect

Using the finished product from the tutorial here.

Is it possible to apply the grayscale effect from here:

Making entire scene fade to grayscale

Or would you basically have to rewrite everything?

EDIT: It's doing something now, but the whole grayscale seems extremely blue. It's like I'm looking at it through dark blue sunglasses. Here's my draw function:

protected override void Draw(GameTime gameTime)
{
device.SetRenderTarget(renderTarget);
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

//Drawing models, bullets, etc.

device.SetRenderTarget(null);
spriteBatch.Begin(0, BlendState.Additive, SamplerState.PointWrap, DepthStencilState.Default, RasterizerState.CullNone, grayScale);
Texture2D temp = (Texture2D)renderTarget;
grayScale.Parameters["coloredTexture"].SetValue(temp);
grayScale.CurrentTechnique = grayScale.Techniques["Grayscale"];
foreach (EffectPass pass in grayScale.CurrentTechnique.Passes)
{
pass.Apply();
}
spriteBatch.Draw(temp,
new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth/2, GraphicsDevice.PresentationParameters.BackBufferHeight/2),
null, Color.White, 0f, new Vector2(renderTarget.Width/2, renderTarget.Height/2), 1.0f,
SpriteEffects.None, 0f);

spriteBatch.End();

base.Draw(gameTime);
}


Another edit: figured out what I was doing wrong. I have Blendstate.Additive in the spriteBatch.Draw() call. It should be Blendstate.Opaque, or it literally tries to add the blank blue image to the grayscale image.

## 1 Answer

Since grayscale is a post-process effect it is very easy to integrate. You just have to make sure that before drawing the scene you set a rendertarget. This means that everything is being drawn to someplace in the videocard memory and not directly to the screen. After that you save the texture you get from the rendertarget and draw that as a full screen quad with the gray-scale effect applied.

So the steps:

- Set rendertarget
- Draw scene
- Unset rendertarget
- Get texture from rendertarget
- Set grayscale effect
- Draw texture as full screen quad


This pdf should help you on your way: http://users.ece.gatech.edu/~lanterma/mpg/ece4893lec_postprocessing.pdf .

• I've managed to get it doing something, but now it's a grayscale that seems to have a dark blue translucent overlay. See my edit for the code I'm using in the Draw() function - I probably biffed it somewhere. – Fibericon Mar 23 '12 at 3:01
• Scratch that, fixed it in the second edit. Works great now! – Fibericon Mar 23 '12 at 4:02