Category Archives: Effects

Adding Volumetric Light Scattering to Rebirth Engine

I’ve just implemented a post-process volumetric light scattering effect.

Volumetric light scattering is a very handy effect we can use for lots of things. For example I wanted to make a scene with a mysterious light hovering in the woods.

The following video shows my scene. Of course it’s powered by Rebirth Engine, and everything is real-time (take a look at the dynamic shadows on the floor):

Implementing this effect is really straightforward, I followed this amazing article from GPU gems

All we need to do is:

  1. We draw a simple version of the scene where every occluding object is drawn in black (the light source remain bright):

2. Then we process the occlusion scene using a light scattering shader like the one presented in the GPU Gems article and we blend the result over the original scene:

What the GPU gems shader does is basically compute the ray from the current pixel (the pixel we are processing) to the light source in screen space and check whether the ray hits the light or if there’s any occluding object. Unfortunately we have to sample neighboring pixels too, i.e. we have to sample the texture more than once for every pixel.

We can save some cycles by reducing the number of samples we use or by using an occlusion texture resolution smaller than the screen resolution.

The shader from GPU Gems also has some parameters we can change to tweak the effect, we can pass them to the shader in real time, but it’s recommendable to set the number of samples as a constant parameter and re compile if we want to change it because of the performance (Using a loop whose limit is a variable instead of a constant in a shader is really inefficient).

This is it for now; I’m going to enhance my scene adding new effects so keep posted for future updates.