Jump to content

  • Log In with Google      Sign In   
  • Create Account


Applying mask to texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Alaryn   Members   -  Reputation: 120

Like
0Likes
Like

Posted 26 February 2012 - 05:21 AM

Hi,
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);

...

			GraphicsDevice.SetRenderTarget(mask);
			GraphicsDevice.Clear(Color.Transparent);

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

			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.End();

			GraphicsDevice.SetRenderTarget(null);
			GraphicsDevice.Clear(Color.CornflowerBlue);

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

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?

EDIT:
Thank you for not responding. Posted Image 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.

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS