Suggested approach for Photoshop-like blending modes in XNA

馋奶兔 提交于 2019-12-11 09:27:57

问题


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:


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.



来源:https://stackoverflow.com/questions/4151420/suggested-approach-for-photoshop-like-blending-modes-in-xna

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!