1
votes

I'm working on a 2D project in C# using XNA where I need to render a number of grayscale sprites onto a Texture2D - I'm switching render states and using a sprite batch and getting results mainly thanks to other stackoverflow posts. What I haven't been able to find is how to blend using something other than Alpha or Multiply.

The result I'm looking for would be equivalent to the Lighten blending mode in Photoshop - between the contents of the texture and the sprite I'm drawing, I only really want pixels lighter than the texture drawn to the texture. My naive approach would be to loop through the pixel data in the source and the destination. Is there a good solution?

1

1 Answers

2
votes

If you're using XNA 4.0 you can pass in a BlendState object to SpriteBatch.Begin.

You want to set the BlendState.ColorBlendFunction to BlendFunction.Max. The documentation lists what the actual blend functions are.

To achieve your effect, I think you will also want to set ColorSourceBlend and ColorDestinationBlend both equal to Blend.One.

The same thing is possible in earlier versions of XNA, but you have to use SpriteBatch with SpriteSortMode.Immediate and modify the appropriate members of GraphicsDevice.RenderState after calling Begin and before the first call to Draw.

Read this blog post for more details.