Bloom Effect On Windows Phone 7


In this post iam going to explain a dirty way to simulate the bloom effect under Windows Phone 7. Unfortunatelly, we dont have custom shaders in this plataform yet, so we need to use some combination of alpha blending to simulate the threshold filter and the Blur filter.

In a simple way, the classic boom post effect consists of:

  • A first pass that exctracts the parts of the image that are more “bright” (we get the pixels with rgb colors bigger than something like 0.7 and discard the others — this is the threshold filter)
  • The second pass apply a gaussian blur (or another blur algorithm) to the previous generated image
  • We make an additive blending between the original image and the previous generate image

For PC and Consoles, we normally use Custom shaders for all the passes, but in WP7 we cant. The alternative is to use Subtrative alpha blending for the threshold pass, draw the images with offset for the blur and use additive blending for the last pass.

The results i got are pretty cool (for a phone =P). Next i will show my implementation of this idea:

 Creating the Blend States

The following piece of code shows the blending states creation:

            ///Additive blending
            BlendState additiveBlend = new BlendState();
            additiveBlend.AlphaBlendFunction = BlendFunction.Add;
            additiveBlend.AlphaSourceBlend = Blend.One;
            additiveBlend.AlphaDestinationBlend = Blend.One;
            additiveBlend.ColorBlendFunction = BlendFunction.Add;
            additiveBlend.ColorSourceBlend = Blend.One;
            additiveBlend.ColorDestinationBlend = Blend.One;

            ///Subtractive blending
            BlendState subBlend = new BlendState();
            subBlend.AlphaBlendFunction = BlendFunction.Subtract;
            subBlend.AlphaSourceBlend = Blend.One;
            subBlend.AlphaDestinationBlend = Blend.One;
            subBlend.ColorBlendFunction = BlendFunction.Subtract;
            subBlend.ColorSourceBlend = Blend.One;
            subBlend.ColorDestinationBlend = Blend.One;

We also need two Render Targets to hold our intermediate images. (letst call SCENERT (used to hold the scene) and BLOOMRT (used to hold the bloom passes) )

Executing the Bloom Pass

The following code shows the complete Bloom Pass. (the Render class is our wrapper to the xna graphic device)

            ///set the scene render target on device
            render.PushRenderTarget(SCENERT);
            ////RENDER THE SCENE HERE !!!! EVERYTHING ..
            ///set the bloom render target on device
            render.PopRenderTarget();
            render.PushRenderTarget(BLOOMRT);
            render.Clear(Color.FromNonPremultiplied(bloomThreshold, bloomThreshold, bloomThreshold, 255));
            ///Render the Scene Texture using the SubBlend (the spritebatch can do it easily =P, i used the render object cause this is part of our engine)
            render.RenderTextureComplete(SCENERT, Color.White, GraphicInfo.FullScreenRectangle, Matrix.Identity, null, true, SpriteSortMode.Deferred, SamplerState.LinearClamp, subBlend);
            ///set the frame buffer render target (now we are going to render to the MONITOR)
            render.PushRenderTarget(null);

            render.Clear(Color.Black);
            ///Render the original texture (without blending)
            render.RenderTextureComplete(SCENERT, Color.White, GraphicInfo.FullScreenRectangle, Matrix.Identity);

            ///FAKE BLUR KKKKK (mais KKKK)
            ///Render the BLOOM render target four times on the top of the original images with offset and Additive blending
            ///We also use a brightNess variable to control how brigh the final image will be. (use something like 60)
            render.RenderTextureComplete(BLOOMRT, Color.FromNonPremultiplied(255, 255, 255, brightNess), GraphicInfo.FullScreenRectangle, Matrix.CreateTranslation(2, 2, 0), null, true, SpriteSortMode.Deferred, SamplerState.AnisotropicClamp, additiveBlend);
            render.RenderTextureComplete(BLOOMRT, Color.FromNonPremultiplied(255, 255, 255, brightNess), GraphicInfo.FullScreenRectangle, Matrix.CreateTranslation(-2, -2, 0), null, true, SpriteSortMode.Deferred, SamplerState.AnisotropicClamp, additiveBlend);
            render.RenderTextureComplete(BLOOMRT, Color.FromNonPremultiplied(255, 255, 255, brightNess), GraphicInfo.FullScreenRectangle, Matrix.CreateTranslation(2, -2, 0), null, true, SpriteSortMode.Deferred, SamplerState.AnisotropicClamp, additiveBlend);
            render.RenderTextureComplete(BLOOMRT, Color.FromNonPremultiplied(255, 255, 255, brightNess), GraphicInfo.FullScreenRectangle, Matrix.CreateTranslation(-2, 2, 0), null, true, SpriteSortMode.Deferred, SamplerState.AnisotropicClamp, additiveBlend);

The helper Code i Used:

public void RenderTextureComplete(Texture2D texture, Color color, Rectangle destination, Matrix transform, Rectangle? source = null, SpriteSortMode SpriteSortMode = SpriteSortMode.Deferred, SamplerState samplerState = null, BlendState blenderState = null, RasterizerState rasterizerState = null, DepthStencilState depthState = null, Effect effect = null)
        {
            spriteBatch.Begin(SpriteSortMode, blenderState, samplerState, depthState, rasterizerState, effect, transform);
            spriteBatch.Draw(texture, destination,source, color);
            spriteBatch.End();
        }

///actually is a bit more than this ... but this is enough for this effect
public void PushRenderTarget(params RenderTarget2D[] renderTarget)
        {
            if (renderTarget == null)
            {
                device.SetRenderTargets(null);
            }
            else
            {
                RenderTargetBinding[] bindings = new RenderTargetBinding[renderTarget.Count()];
                for (int i = 0; i < renderTarget.Count(); i++)
                {
                    bindings[i] = renderTarget[i];
                }

                device.SetRenderTargets(bindings);
            }
        }

public void Clear(Color color, ClearOptions options = ClearOptions.Target | ClearOptions.DepthBuffer, float depth = 1, int stencil = 0)
        {
            device.Clear(options, color, depth, stencil);
        }

You can use this idea to simulate others post effects like Blur.
Enjoy =P

  1. #1 by how to find out if your boyfriend is cheating on 22 de julho de 2017 - 2:19 pm

    Every after inside a when we choose blogs that we study. Listed below are the most recent sites that we decide on

  2. #2 by low income auto insurance dmv Garland TX on 22 de julho de 2017 - 2:23 pm

    I love reading these articles because they’re short but informative.

  3. #3 by adam and eve sex toy on 22 de julho de 2017 - 3:40 pm

    just beneath, are various entirely not associated web sites to ours, however, they are surely really worth going over

  4. #4 by cheapest auto insurance Anchorage AK on 22 de julho de 2017 - 9:13 pm

    Hallelujah! I needed this-you’re my savior.

  5. #5 by average car insurance rates in Chicago IL on 22 de julho de 2017 - 9:32 pm

    You have the monopoly on useful information-aren’t monopolies illegal? 😉

  6. #6 by no down payment auto insurance in Columbus OH on 22 de julho de 2017 - 9:59 pm

    That’s a clever answer to a tricky question

  7. #7 by cara internet gratis on 23 de julho de 2017 - 2:36 am

    Hi there. I found your blog by the use of Google even as searching for a comparable topic, your site got here up. It appears to be great. I have bookmarked it in my google bookmarks to come back then.

  8. #8 by keep reading on 23 de julho de 2017 - 2:42 am

    It truly is really an excellent plus valuable section of details.. سرور مجازی لهستان My business is thankful you provided this handy facts along with us. Please remain us all up to date like this. Appreciate your giving.

  9. #9 by harga cat rumah on 23 de julho de 2017 - 2:58 am

    Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish just about gossip and web stuff and this is actually irritating. A good blog with exciting content, this is what I need. Thank you for making this web-site, and I’ll be visiting again. Do you do newsletters by email?

  10. #10 by wedding photographer nyc on 23 de julho de 2017 - 3:33 am

    With havin so much written content do you ever run into any issues of plagorism or copyright infringement? My blog has a lot of unique content I’ve either created myself or outsourced but it appears a lot of it is popping it up all over the web without my permission. Do you know any ways to help reduce content from being ripped off? I’d genuinely appreciate it.|

  11. #11 by cheap non owners insurance in Arnold MO on 23 de julho de 2017 - 3:38 am

    It’s good to see someone thinking it through.

  12. #12 by spesifikasi harga hp on 23 de julho de 2017 - 4:40 am

    Hiya, I am really glad I’ve found this info. Today bloggers publish just about gossip and internet stuff and this is actually annoying. A good blog with interesting content, that is what I need. Thanks for making this website, and I will be visiting again. Do you do newsletters by email?

  13. #13 by Business on 23 de julho de 2017 - 6:48 am

    I really like your writing style, fantastic info, appreciate it for posting :D. “Kennedy cooked the soup that Johnson had to eat.” by Konrad Adenauer.

  14. #14 by look auto insurance Troy MI on 23 de julho de 2017 - 7:39 am

    That’s way more clever than I was expecting. Thanks!

  15. #15 by polythene manufacturer on 23 de julho de 2017 - 7:53 am

    Wonderful story, reckoned we could combine several unrelated data, nevertheless definitely worth taking a look, whoa did a single learn about Mid East has got a lot more problerms also

  16. #16 by car insurance rates San Pedro CA on 23 de julho de 2017 - 7:55 am

    Last one to utilize this is a rotten egg!

  17. #17 by us agency car insurance Burleson TX on 23 de julho de 2017 - 8:14 am

    Woot, I will certainly put this to good use!

  18. #18 by list of car insurances in Carrollton TX on 23 de julho de 2017 - 8:16 am

    It’s much easier to understand when you put it that way!

  19. #19 by Toko Obat Herbal Online on 23 de julho de 2017 - 8:23 am

    Hey there. I found your website via Google at the same time as searching for a comparable topic, your website got here up. It looks good. I have bookmarked it in my google bookmarks to visit then.

  20. #20 by tips dan trik laptop on 23 de julho de 2017 - 8:24 am

    Hiya, I am really glad I have found this information. Today bloggers publish only about gossip and net stuff and this is really annoying. A good website with interesting content, this is what I need. Thank you for making this site, and I will be visiting again. Do you do newsletters by email?

  21. #21 by car insurance MS on 23 de julho de 2017 - 8:39 am

    I’m impressed. You’ve really raised the bar with that.

  22. #22 by cara dial paket kartu sakti yang hilang telkomsel terbaru on 23 de julho de 2017 - 9:04 am

    Hey there. I discovered your site by way of Google at the same time as looking for a comparable topic, your web site came up. It appears great. I’ve bookmarked it in my google bookmarks to come back then.

  23. #23 by cheap full coverage car insurance Charlotte NC on 23 de julho de 2017 - 9:05 am

    You’ve really captured all the essentials in this subject area, haven’t you?

  24. #24 by cheapest auto insurance Monroeville PA on 23 de julho de 2017 - 10:58 am

    Cool! That’s a clever way of looking at it!

  25. #25 by list of auto insurances in Quincy MA on 23 de julho de 2017 - 11:00 am

    You really found a way to make this whole process easier.

  26. #26 by Agen bola on 23 de julho de 2017 - 12:46 pm

    Hiya, I am really glad I have found this information. Today bloggers publish just about gossip and internet stuff and this is actually frustrating. A good site with exciting content, this is what I need. Thanks for making this web site, and I will be visiting again. Do you do newsletters by email?

  27. #27 by game rts offline terbaru paling seru on 23 de julho de 2017 - 12:58 pm

    Hi there. I found your website by way of Google at the same time as searching for a comparable subject, your site came up. It seems to be great. I have bookmarked it in my google bookmarks to visit then.

  28. #28 by cheap car insurance Rocklin CA on 23 de julho de 2017 - 1:03 pm

    Your’s is a point of view where real intelligence shines through.

  29. #29 by harga hp terbaru on 23 de julho de 2017 - 1:13 pm

    Hiya, I am really glad I have found this information. Nowadays bloggers publish only about gossip and internet stuff and this is really irritating. A good web site with interesting content, this is what I need. Thanks for making this web-site, and I will be visiting again. Do you do newsletters by email?

  30. #30 by contoh desain rumah minimalis terbaru paling populer on 23 de julho de 2017 - 1:40 pm

    Awesome write-up. I’m a regular visitor of your blog and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a long time.

  31. #31 by Home Improvement on 23 de julho de 2017 - 1:48 pm

    Hi, Neat post. There’s an issue together with your web site in internet explorer, might test this… IE nonetheless is the market leader and a large part of other folks will leave out your excellent writing because of this problem.

  32. #32 by Judi Online on 23 de julho de 2017 - 1:55 pm

    Hi there. I found your website by way of Google at the same time as looking for a similar topic, your site came up. It appears good. I have bookmarked it in my google bookmarks to visit then.

  33. #33 by how to apply singapore pr on 23 de julho de 2017 - 5:10 pm

    Good posts!

  34. #34 by Mississippi Gulf Coast on 23 de julho de 2017 - 5:27 pm

    usually posts some really interesting stuff like this. If you are new to this site

  35. #35 by list of car insurances in Lynchburg VA on 23 de julho de 2017 - 5:52 pm

    Wait, I cannot fathom it being so straightforward.

  36. #36 by Biloxi extended stay on 23 de julho de 2017 - 6:09 pm

    Every after inside a whilst we choose blogs that we study. Listed below would be the most up-to-date web pages that we pick

  37. #37 by Biloxi apartments on 23 de julho de 2017 - 6:52 pm

    check beneath, are some entirely unrelated websites to ours, nonetheless, they’re most trustworthy sources that we use

1 255 256 257
(não será publicado)