Pretty cool eh :D
So, I am going to post here this 2D implementation. Keep in mind that this effect will not work on the WP7 device as it uses custom shaders to do what it needs to do, might have a look at a CPU implementation, but I reckon it will suck.
If you refer back to my post on this for 3D you will see all the same shaders, the difference in this 2D sample is the way the light mask is built. Effectively you need to render your light source, over that render the elements in your scene that are obscuring that source over the top in black to create the light mask, then apply the Crepuscular post processing effect. Then render the scene as you would normaly and then using an additive blend apply the god ray’s over the top.
1. Draw Light Source
Here the post processor is rendering the light mask at the position we want on the screen, as you can see I have put up a few keyboard controls you can use to alter the parameters to the effect, so you can move the light source around, alter the exposure, stuff like that.
2. Draw Light Mask
There are a few items in this scene, a number of “mountain” images which are just wrap able textures and a samurai head icon for my mouse pointer, all png’s so we can use the alpha channel on them to allow light to bleed through. The post process is then applied to this to make the light bleed past the edges of the mask to give the god ray effect.
3. Draw Scene
The scene is then drawn ready to be blended with the processed mask.
4. Combine Scene and Ray Images
Finally it’s all brought together to give the overall effect.
5. Animate It
As you can see it renders at a good frame rate, 60fps, and this is at 900x1440 on my laptop. I have not personally ran this sample on my 360, buy x35mm has I believe.
Check out Dawn of the Ronin (pre god rays) here.
The solution for this sample can be found here.
I have also made an update to this so that the effect takes screen resolution into account here.
If you use this technique in your work, please let me know, be cool to see it used in the real world, just like x35mm has done in his game.