Jump to content
  • Advertisement
Sign in to follow this  

Applying mask to texture

This topic is 2823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem with applying mask to texture. The steps are as follows:

mask = new RenderTarget2D(GraphicsDevice,
graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight,
false, SurfaceFormat.Color, DepthFormat.None);



spriteBatch.Draw(terrain, Vector2.Zero, Color.White);

BlendState bs = new BlendState();

bs.ColorSourceBlend = Blend.One;
bs.ColorDestinationBlend = Blend.One;
bs.ColorBlendFunction = BlendFunction.Add;

bs.AlphaSourceBlend = Blend.One;
bs.AlphaDestinationBlend = Blend.One;
bs.AlphaBlendFunction = BlendFunction.Add;

spriteBatch.Begin(SpriteSortMode.FrontToBack, bs);
spriteBatch.Draw(tex2, new Vector2(100f, 250f), Color.White);


spriteBatch.Draw((Texture2D)rt, Vector2.Zero, Color.White);

The mask and terrain are PNG textures with alpha channel. I just want to take alpha value of each pixel from mask and "put" them into render target (strictly, multilply alpha values of source and destination). BlendState class has (almost) no documentation but I don't want to use shaders. Do you happen to know how to configure this object?

Thank you for not responding. smile.png This motivated myself to investigate the problem thoroughly.
My configuration is:

bs.ColorSourceBlend = Blend.Zero;
bs.ColorDestinationBlend = Blend.SourceAlpha;
bs.ColorBlendFunction = BlendFunction.Add;

bs.AlphaSourceBlend = Blend.Zero;
bs.AlphaDestinationBlend = Blend.SourceAlpha;
bs.AlphaBlendFunction = BlendFunction.Add;

Now, it works perfectly.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!