Hexagonal shaped lens flares as a post-process PDF Print E-mail

Lens flare are splats of light that results from complex light scattering within a camera lenses. As bokeh depth-of-field, it can take the shape of the mecanical aperture diaphragm of the camera (not only, more complexe form can results from this phenomena).

A way to achieve this effect is to render a bunch of screen quads according to the position of light relatively to the view position. This quads will follow a line defined by the center of the screen to the light position in screen space as shown here. A more complex but physically based simulation can also be achieved if you know the configuration of your camera (lenses, diameter, depth, etc.).

It is also possible to generate this effect as a screen space post-process. Here are the possible implementations:

  1. Downsample the light buffer (containing your scene linear color before post processing is applied).
  2. Threshold this buffer to only have bright parts of it generating lens flares.
  3. Render lens flare. Two methods are available:
    1. Analyse the buffer to generate lens flare quad geometry using R2VB or CL/Compute/Cuda (used in Unreal Engine 4, slide 41).
      (Pros: variety of flares (can use different shapes in each color channel of a texture) and very adaptative. Cons: memory overhead used for geometry and high fillrate in worst case)
    2. Blur this light buffer to automatically generate the final lens flare. Then use a sparse radial blur with as many samples as flares you want.
      (Pros: Constant cost. Cons: Single shape for all flares, less variety)
      1. Use a gaussian blur shown here. This is especially good when combined to screenspace dirt. Without it, the Gaussian blur alone is not very convinincing.
      2. Use of FFT to blur all the pixel according to a specific shape. This very elegant technique is used in Futurmark 2011 demos.

The simple idea I wanted to test was to use a simple blur filter and at the same time get visually more complex shaped flares. The hexagonal blur filter presented by John White here to achieve depth of field blur is a perfect fit! This will be better than a simple Gaussian blur, it is not much more expensive plus it looks more convicing.

Some parts of the environment are very bright and generate lens flares. Per flare color are applied. Yes this is programmer art :).
Left: raw lens flare buffer after thresholding applied (threshold buffer has 1/4 resolution). Right: with hexagonal blur applied.

This is what happens when lens flares are aligned (expected when flare sources are at the center of the screen).


I wanted to go further but then saw this very good web page about the same topic and decided to stop here as it already describes combination with dirt and chromatic aberation which are easy to add at this point. Still, I wanted to have my webpage to show another possible use of the hexagonal blur. With the right lens flare colors, I am sure this is a very usable technique.


Here is a link to the Demo and Video. This is a XCode project as I still do not have my PC in UK for now. Also I can't give performance because the OpenGL distribution on my Mac does not provide the timer query extension.

Last Updated on Friday, 26 October 2012 12:17