God rays (aka light shafts, light beams, light rays) are beautiful phenomenon caused by the light going through some medium denser than air (like dust or smoke). Before going into details here's my photo showing them in real life:
There are several approaches to render them. One of them, based on slicing volume with planes, I described some time ago here.
This time inspired by my discussion with Lukasz Zmijewski, I decided to implement God rays as a screen-space effect.
First of all, it has to be mentioned that this effect is not a replacement for the other version. This one is more global and works best for sun rays outdoors. However, it is more difficult to use gobo (cookie) or animate it with noise. Also I don't think it would look good when used for indoor scenes.
The idea behind this effect is straight-forward: take your scene and blur it using radial blur starting at screen-space sun position. Then blend the result additively with the scene.
The only problem with such an implementation is that whole scene would be equally blurred no matter the rays should be visible at a given point or not, ie. occlussion isn't taken into account. However, this is very simple to fix and here are two possible solutions:
1) render scene to the texture and output colour information only for objects which should be blurred (typically this would be the sky, sun and clouds) - output 0 (ie. black) for the rest of the scene (all occluders like terrain or trees),
2) in case of deferred shading use G-Buffer contents. It can be material ID or some other characteristic that says the object is an occluder or not.
I use second approach in my engine and when blurring I check if the normal of the point is of zero length. I use such normal vector for objects not influenced by light (but which still needs to be rendered to the G-buffer) like the sky. If normal vector length is larger than object is an occluder. Not the best way I admit but works without problems.
One more thing - in reality the rays are disappearing at some distance. This can be easily achieved by using linear or exponential decay factor.
Here is the screenshot from nGENE showing this phenomenon in action: