Im trying to build a rendertarget alpha mask for a fog of war example.. I tell it that I want to clear the rendertarget with solid white (Alpha 255)
Then I draw my image with a transparent circle, onto the alpha channel, from there I would expect to have an image in the rendertarget, with holes in it. This however is not the case.. I'm very familiar with alpha masking and have done so successfully when drawing a single image to the alpha mask, but when drawing a bunch like we have here, it fails entirely to give me proper alpha values.
if (mFogOfWarRT == null)
{
mFogOfWarRT = new RenderTarget2D(pGraphics.GraphicsDevice, MapSize, MapSize);
pGraphics.GraphicsDevice.SetRenderTarget(mFogOfWarRT);
//pGraphicsDevice.Clear(Color.Black);
}
else
{
pGraphics.GraphicsDevice.SetRenderTarget(mFogOfWarRT);
}
pGraphicsDevice.Clear(Color.White);
pSpriteBatch.Begin();
BlendState lKeep = new BlendState();
lKeep.AlphaSourceBlend = Blend.One;
lKeep.AlphaDestinationBlend = Blend.Zero;
lKeep.ColorSourceBlend = Blend.Zero;
lKeep.ColorDestinationBlend = Blend.One;
lKeep.ColorBlendFunction = BlendFunction.Subtract;
lKeep.AlphaBlendFunction = BlendFunction.Add;
pGraphicsDevice.BlendState = lKeep;
pGraphicsDevice.BlendState.ColorWriteChannels = ColorWriteChannels.Alpha;
foreach (ClearArea lArea in mDrawQueue)
{
pSpriteBatch.Draw(mAlphaMask, new Rectangle((int)lArea.X, lArea.Y, lArea.Diameter, lArea.Diameter), Color.White);
}
//pSpriteBatch.Draw(mDot, new Rectangle(0, 0, 100, 100), Color.White);
pSpriteBatch.End();
pGraphicsDevice.SetRenderTarget(null);
This is my drawing code for the alpha mask.. when draws to the screen we get a white square, nothing else.
down below I draw my "Map" to the RGB, then set the A, and draw my alphamask texture and it fails miserably
pGraphicsDevice.SetRenderTarget(null);
// Draw minimap texture
pGraphicsDevice.Clear(Color.CornflowerBlue);
pGraphicsDevice.BlendState = lKeep;
pGraphicsDevice.BlendState.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Blue | ColorWriteChannels.Green;
pSpriteBatch.Begin();
pSpriteBatch.Draw(mDot, new Rectangle(0, 0, 400, 400), Color.Blue);
pGraphicsDevice.BlendState.ColorWriteChannels = ColorWriteChannels.Alpha;
pSpriteBatch.Draw(mFogOfWarRT, Vector2.Zero, Color.White);
pSpriteBatch.End();
Any help with this would be much appreciate..
paste bin of full code
screen shot of outcome available if needed.