Windows Phone 7 / XNA 4 - Texture Blur effect
-
28-09-2019 - |
Question
Hey all, I'm just beginning to use XNA 4.0 for Windows Phone 7 and was looking for some information on how to achieve a blur effect on a Texture2D? From what I've gathered we can't use shaders on the WP7 platform and I'm finding information on this topic pretty hard to come by.
Many thanks in advance, anton.
Solution
In theory, yes. However it's a CPU intensive task. If you take the pixel data, stick it in a bitmap, and iterate over the pixels in C# how a shader would, then you can achieve the same effect. All you'd then do is take the colour data from the bitmap, whack it back in the texture, and then redraw it. But given you'd have to do this for every draw call, it'll be a massive kick-in-the-teeth for the phones processor. I don't have my code to hand, but I've used this approach for a number of "pseudoshaders". It's not efficient, but it's effective when used sparingly.
OTHER TIPS
Another fairly cheap method of "directional blurring" of sprites is to keep a short FIFO queue of where the sprite has been (its position) over the last few Updates. This is a location "history trail". Then, draw the sprite at these positions in reverse chronological order (oldest one first), with a color mask that starts off at nearly transparent (for the oldest member of the history trail), becomes less transparent for each later position in the history trail, and is White for the current position of the sprite. This method gets more expensive (time consuming) with larger history trails. It may also not produce a good blur when the object is moving too fast - because there will be too much space in between the current position and the previous one. In this case, you can interpolate positions that are closer to the current position to get a better blur effect. The end result would probably be considered ghosting than blurring, but if that's all you need, this is fairly easy to implement.