Applying effects to an existing program that uses BasicEffect

Posted by Fibericon on Game Development See other posts from Game Development or by Fibericon
Published on 2012-03-22T07:12:09Z Indexed on 2012/03/23 11:41 UTC
Read the original article Hit count: 346

Filed under:
|
|

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.

© Game Development or respective owner

Related posts about XNA

Related posts about effects