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 ESL on 26 de setembro de 2016 - 3:58 am

    Looking forward to reading more. Great blog.Much thanks again. Keep writing.

  2. #2 by to read more on 26 de setembro de 2016 - 6:37 am

    I appreciate you sharing this blog.Thanks Again. Much obliged.

  3. #3 by Dee Grennay on 26 de setembro de 2016 - 10:34 am

    free site

  4. #4 by social apps on 26 de setembro de 2016 - 11:24 am

    below youll uncover the link to some web pages that we think you need to visit

  5. #5 by Wynajem Podnośników Nożycowych Warszawa on 26 de setembro de 2016 - 12:11 pm

    What i don’t realize is in fact how you’re no longer really much more smartly-favored than you might be now. You’re so intelligent. You understand thus considerably in relation to this subject, made me individually imagine it from a lot of numerous angles. Its like women and men are not interested until it’s something to accomplish with Woman gaga! Your individual stuffs nice. Always maintain it up!

  6. #6 by flooring on 26 de setembro de 2016 - 4:33 pm

    Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is magnificent, let alone the content!. Thanks For Your article about sex.

  7. #7 by home care on 26 de setembro de 2016 - 6:24 pm

    The information and facts mentioned in the write-up are some of the very best readily available

  8. #8 by watchjav on 26 de setembro de 2016 - 6:25 pm

    Just file making clear content. I beg your pardon? exactly I needed! I have been previously browsing search engines like google the complete sunlight hours for some correct item such as this

  9. #9 by grand national runners on 26 de setembro de 2016 - 6:27 pm

    Say, you got a nice blog.Really looking forward to read more. Awesome.

  10. #10 by Zaproszenia ślubne on 26 de setembro de 2016 - 7:46 pm

    Hello my friend! I want to say that this post is amazing, nice written and come with approximately all significant infos. I would like to see extra posts like this.

  11. #11 by to learn more on 26 de setembro de 2016 - 10:04 pm

    That is a great tip especially to those new to the blogosphere. Short but very accurate information Appreciate your sharing this one. A must read article!

  12. #12 by for more information on 26 de setembro de 2016 - 11:52 pm

    Whats up very nice website!! Man.. Excellent..

  13. #13 by visit on 27 de setembro de 2016 - 1:40 am

    Very good article. I absolutely appreciate this site. Continue the good work!

  14. #14 by Home Improvement on 27 de setembro de 2016 - 1:44 am

    Super-Duper site! I am loving it!! Will be back later to read some more. I am bookmarking your feeds also

  15. #15 by Zaproszenia ślubne on 27 de setembro de 2016 - 2:56 am

    I got what you intend, thanks for posting .Woh I am happy to find this website through google. “It is a very hard undertaking to seek to please everybody.” by Publilius Syrus.

  16. #16 by see on 27 de setembro de 2016 - 3:29 am

    This is a really good tip particularly to those new to the blogosphere. Brief but very accurate info Thanks for sharing this one. A must read post!

  17. #17 by софия продажба имот on 27 de setembro de 2016 - 4:00 am

    There are certainly a lot of details like that to take into consideration. That is a great point to bring up. I offer the thoughts above as general inspiration but clearly there are questions like the one you bring up where the most important thing will be working in honest good faith. I don?t know if best practices have emerged around things like that, but I am sure that your job is clearly identified as a fair game. Both boys and girls feel the impact of just a moment’s pleasure, for the rest of their lives.

  18. #18 by auto wrecker colorado springs on 27 de setembro de 2016 - 4:35 am

    Thanks for sharing, this is a fantastic blog post.Thanks Again. Much obliged.

  19. #19 by putlocker on 27 de setembro de 2016 - 6:08 am

    Really appreciate you sharing this article post. Want more.

  20. #20 by pc repair on 27 de setembro de 2016 - 7:08 am

    There is definately a great deal to know about this topic. I love all the points you have made.

  21. #21 by apply singapore pr on 27 de setembro de 2016 - 7:11 am

    Nice post!

  22. #22 by water purification on 27 de setembro de 2016 - 7:40 am

    Awesome blog article.Much thanks again. Really Great.

  23. #23 by schuylkill county school employees credit union on 27 de setembro de 2016 - 9:02 am

    thank you for all your efforts that you have put in this. Very interesting info. Truth sits upon the lips of dying men. by Matthew Arnold.

  24. #24 by popcorn machine rental on 27 de setembro de 2016 - 9:13 am

    Very informative blog post.Thanks Again. Awesome.

  25. #25 by Alline Linea on 27 de setembro de 2016 - 9:29 am

    ploobs.com.br does it yet again! Quite a informative site and a well-written article. Nice work!

  26. #26 by hacking facebook account on 27 de setembro de 2016 - 9:46 am

    Can I simply just say what a comfort to discover a person that actually knows what they are discussing over the internet. You actually know how to bring an issue to light and make it important. More and more people have to check this out and understand this side of your story. It’s surprising you’re not more popular given that you definitely have the gift. why not try here: http://bit.ly/2b3E2rq

  27. #27 by Digital Marketing Courses In Nigeria on 27 de setembro de 2016 - 11:00 am

    Im thankful for the blog post.Much thanks again. Keep writing.

  28. #28 by concrete molds for sale on 27 de setembro de 2016 - 11:37 am

    Hello there! I could have sworn I’ve been to this site before but after reading through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be book-marking and checking back often!

  29. #29 by magician for birthday party Singapore on 27 de setembro de 2016 - 12:27 pm

    I loved your blog. Will read on…

  30. #30 by tshirt on 27 de setembro de 2016 - 12:54 pm

    You, my pal, ROCK! I found exactly the info I already searched everywhere and simply could not find it. What a perfect web site.

  31. #31 by eheringe palladium weissgold on 27 de setembro de 2016 - 2:47 pm

    Thanks for an explanation. All ingenious is simple.

  32. #32 by weekly pay on 27 de setembro de 2016 - 4:41 pm

    Wow, that as what I was exploring for, what a stuff! present here at this webpage, thanks admin of this web page.

1 37 38 39
(não será publicado)