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 auto acceptance insurance Anchorage AK on 16 de janeiro de 2017 - 10:08 am

    dit :Thanks for another magnificent post. Where else could anybody get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the search for such information.

  2. #2 by car insurance New Bedford MA on 16 de janeiro de 2017 - 11:01 am

    Delicious!! I doubled the recipe and it was just right for a 9×13 pan. A batch of cream cheese frosting was the icing on the cake, and it was served for company last evening. No one even knew it was gluten free. This is a new favorite at our house. Thanks!

  3. #3 by http://carinsurancelit.top/NY/Far-Rockaway/low-income-car-insurance-dmv/ on 16 de janeiro de 2017 - 11:51 am

    Ya que me venga este gobierno a cagar po lo que posteo, me retiro de bloguear, uno bloguea lo que queire, siempre y cuando sea algo coherente y que pueda transmitir.

  4. #4 by best auto insurance in Mason MI on 16 de janeiro de 2017 - 12:47 pm

    picture was taken on our visit to Bonnie Springs Ranch. These guys get to roam free around the petting zoo area, but they were tuckered out when we came

  5. #5 by Dodie Kirkpatrick on 16 de janeiro de 2017 - 1:01 pm

    After study a few of the blog posts on your website now, and I truly like your way of blogging. I bookmarked it to my bookmark website list and will be checking back soon. Pls check out my web site as well and let me know what you think.

  6. #6 by list of car insurances in Dowagiac MI on 16 de janeiro de 2017 - 1:10 pm

    This article is a home run, pure and simple!

  7. #7 by affordable auto insurance South Lake Tahoe CA on 16 de janeiro de 2017 - 1:10 pm

    Scrivi il tuo commento Puoi usare questi tags HTML : <a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <strike> <strong> var RecaptchaOptions = { theme : ‘white’, lang : ‘en’ , tabindex : 5 };   #submit {display:none;}

  8. #8 by auto insurance quotes Edwardsville IL on 16 de janeiro de 2017 - 1:51 pm

    We need a lot more insights like this!

  9. #9 by no down payment car insurance in Prairie Home MO on 16 de janeiro de 2017 - 2:03 pm

    J’ai 42 ans et j’avais de nombreux vieux plombages. J’en ai fait remplacer une partie l’automne dernier et les autres en janvier 2009. Ma dentiste ne m’a jamais informée que de les remplacer représentait un quelconque danger pour ma santé. Je souffrais de maux de tête depuis avant même mon adolescence. Et bizarrement, mes maux de tête ont beaucoup diminué l’automne dernier et je n’en ai presque plus maintenant. Je n’avais jamais fait de rapport entre les maux de tête et les plombage. Un ami m’en a récemment parlé. Ma qualité de vie s’est grandement améliorée!

  10. #10 by skechers outlet online on 16 de janeiro de 2017 - 4:11 pm

    After research a couple of of the blog posts in your website now, and I truly like your approach of blogging. I bookmarked it to my bookmark web site listing and can be checking back soon. Pls take a look at my website online as nicely and let me know what you think.

  11. #11 by autokredit ballonfinanzierung rechner on 16 de janeiro de 2017 - 4:28 pm

    It’s wonderful to have you on our side, haha!

  12. #12 by Custom Car Interior on 16 de janeiro de 2017 - 4:32 pm

    How do i make movies bigger within my blogger internet site larger?

  13. #13 by http://besteronlinekredit.pw/challans-cap-océan.html on 16 de janeiro de 2017 - 5:32 pm

    Check that off the list of things I was confused about.

  14. #14 by kredit wenig einkommen deutschland on 16 de janeiro de 2017 - 7:17 pm

    I am looking for some funding for safe and environmetally friendly: Bio Fueling and other projects. (We are located in michigan)We have a 4 phase plan to get profits starting as early next year!First phase is almost completed.Contact or call: 1-989-545-6158 Leave message and contact info

  15. #15 by http://besterkreditvergleich.net/ratenkredit-berlin-niedrig-zins-rechner.html on 16 de janeiro de 2017 - 8:31 pm

    I am already a member of Madurai Namdwar situated in TVS Nagar. I am continuously watching KAKKA KAKKA GURUVARUL KAKKA IN VIJAY TV. PLEASE MAIL ME THE ADDRESS OF GOVINDAPURAM BAGAVAN NAMA BOTHENTHRA SWAMIJI ADISHTANAM ADDRESS AND THE ROUTE FROM MADURAI TO GOVINDAPURAM ADHISTANAM RADHE KRISHNA

  16. #16 by kredit vermittler sucht auslaendische firma kredit geber nehmerzylinder on 16 de janeiro de 2017 - 9:20 pm

    Anya nem rég végezte el ezt a tanfolyamot a Crystal Nailsnél, bár én nem vagyok oda az ilyen jellegű körmökért, de nagyon szépeket tud vele készíteni. Tényleg egyszerű de mutatós.

  17. #17 by http://onlinekrediteimvergleich.top/kredit-hauskauf-usa.html on 16 de janeiro de 2017 - 10:32 pm

    I was looking everywhere and this popped up like nothing!

  18. #18 by Car Insurance Quotes Online on 16 de janeiro de 2017 - 11:03 pm

    I want to put the advertisements in blogger, so I can get obligations?.

  19. #19 by http://kostenloskreditevergleichen.net/kredit-europa-hypothek-service-nummer.html on 16 de janeiro de 2017 - 11:10 pm

    emails to put them in a folder so I can keep them out of my inbox, but review them a couple of times a week. I, too, am looking forward to a better solution.

  20. #20 by http://guenstigerkreditonline.net/arbeitslosen-kredit-seriös.html on 17 de janeiro de 2017 - 12:41 am

    NJ Patient,I have discussed some of the “matrix”, energy and human information flow ideas with people who understand the concepts, but they ask” ok so what can you do about it, you or i cannot effect that”that brings up an interesting point. what do you do with that info? how do you react to it?. I guess i am at a similar stage to my son. he has figured out that gravity exists and is till in the process of testing it ( picking up and then dropping anything he can get his hands on…. 11 months old) but doesnt quite get how to use it yet.I am still not quite sure what to do with the idea’s and concepts i have recently aquired.

  21. #21 by http://guenstigerkreditonline.net/automobili-na-kredit-bih.html on 17 de janeiro de 2017 - 2:29 am

    Mr.Grove, were you joking when you suggested that Americans get a "re-cap" from Al-Jazeera? Why would we want to do that? I appreciate your skills in the use of satire. It was a joke right??????

  22. #22 by http://besteronlinekredit.pw/kredit-darlehen-orte-finanzierung-geld-ägypten.html on 17 de janeiro de 2017 - 3:05 am

    Your posting ALMOST made me want to come home to be there to enjoy one of my favorite places on the peninsula and be there for the artists reception for the MPC Printmakers.Sounds like the wedding celebration continued days after the wedding, too.

  23. #23 by Poliwag Pokemon on 17 de janeiro de 2017 - 3:24 am

    Currently it looks like Expression Engine is the preferred blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?

  24. #24 by Holiday Vacations on 17 de janeiro de 2017 - 3:43 am

    I’ve been surfing on-line greater than 3 hours as of late, but I never discovered any fascinating article like yours. It¡¦s pretty price sufficient for me. Personally, if all webmasters and bloggers made excellent content material as you probably did, the net will probably be much more useful than ever before.

  25. #25 by http://onlinekrediteimvergleich.top/kreditvertrag-muster-download-gratis-italiano.html on 17 de janeiro de 2017 - 4:41 am

    iPHONiX dit :bizzare j’ai testé sur ipod il s’installe bien LOL mais fonctionne pas, supprime le puis installe du repo officiel…

  26. #26 by самолетни билети до прага on 17 de janeiro de 2017 - 4:42 am

    very nice post, i certainly love this website, keep on it

  27. #27 by http://onlinekreditetestsieger.net/vendée-mes-comptes.html on 17 de janeiro de 2017 - 4:49 am

    Gaetana scrive:Mariangela…come sempre sei riuscita ad evidenziare “il dramma”.Purtroppo il nostro pensiero è bombardato dai nemici che tu combatti nell’articolo: ogni giorno essi ci provocano una totale distrazione dalla realtà.Spero che il tuo articolo possa contribuire a stimolare le menti ed aiutare il teatro.

1 110 111 112
(não será publicado)