Lens Flares Effect in Java

Written by Luis Cruz on Monday, 15 August 2011. Posted in Academic Portfolio

Advanced Image Synthesis | CS 7490

Maxwell Render

This project for the Advanced Image Synthesis class had the objective to simulate lens flare effect in an image automatically. The brightest spot would be found using histograms and then used as a source for the effect. This project was implemented in Java. Lens flares are generated in real life by reflection, scattering and refraction of the light through different lenses.


Although in some situations lens flares are avoided because of two important reasons: image contrast reduction and it adds light to dark areas; lenses flares effects are very common on post-production of images/footage where artificial CGI elements are composited in order to add a sense of realism, and also sometimes is being used to add a sense of drama and sophistication to the image.


Physical mechanisms in lenses and physiological structure of the eye creates a space where incoming light can be reflected, scattered and diffracted. These mechanisms are scattering in the cornea, lens and retina and diffraction in the coherent cell structures on the outer radial areas of the lens [1].

For good optical systems and most of the images the flare effects is distributed across the image; therefore, it is not noticeable by the viewer, but if the image includes a very light source, then the flare effect can have enough intensity to be visible.

Other physical elements such as special lenses, zooms and even the eyelashes may contribute to stronger image artifacts and a brighter flare, due to internal scattering in different layers of lenses and diffraction artifacts due to eyelashes.

In this project, we will go through the implementation and generation of a lens flare effect with procedural textures and image segmentation to find brighter spots on image.

Lens Flare Elements

Although the physical mechanism behind the light scattering in the eye is understood, the exact structure of the cells in the eye is not completely know to the extent that we can simulate the light behavior [1].

A physical accurate model of the light behavior in lenses and eye will need to be implemented using ray tracing and some linear equations. Unfortunately, this technique is not fast enough for a "real-time" interaction in a production pipeline, and more importantly it does not allow the user to create more dramatic and artistic flare effects that are being used in production.

There fore an "image based" technique is used to create lens flare effects, that is, we decompose the effect in all of its core elements and create procedural textures that can be composited later, it is not uncommon in video games that actual pre-fabricated texture images are used in order to save resources.


lensflareelements_bloomThe bloom or glow is caused by scattering and diffraction. This glow is located at the center of the light source (source of the lens flare). The following is the implementation code in the Java language:



Lenticular halos (halo + ring + spike) are caused by the circular optical grating formed by the radial fibers at the perophery of the crystalline lens [1].

lensflareelements_halo1 lensflare_halo1_java
lensflareelements_halo2 lensflare_halo2_java


lensflareelements_ringRings go hand in hand with the halo in order to increase the intensity, the rings are centered at the source along the bloom and a halo.



lensflareelements_spikeThe implementation for the spikes are based in particles.  That is we start at a randome angle and we start painting additive particles across its radius.


Lens Flare Compositing

After you have all the textures for the elements of the lens flare, then the next step is to organize these textures.

  1. Find the direction vector V from the center of the image to the light source.
  2. Store the length L of this vector
  3. Normalize V
  4. By having the vector V and the distance L, we can position all the elements by simply multiplying the texture position by V and L; therefore, you can use single offset values to spread the textures.
  5. After you have the correct position, then we need to blend the textures onto the image, we use an additive blend (ADD), a blending mode of (Screen) may also work in some situations but ADD provides the ebst results.
  6. At this point you have a Lens Flare where you can choose the light source, but in our implementation we find the brightest spot on the image:
    1. Change the color space of the image to grayscale
    2. Construct a histogram to analyze the color of the brightest spots, amount, etc
    3. By using a threshold, crush the dark and midtones
    4. Your result should be some or one blob
    5. Get the size and position of the chosen blob
    6. that will be your light source for the lens flare.


Test 1

Original Image


Brightest blob


Lens Flare result


Test 2

Original Image


Lens Flare Result


Diffraction Artifacts

By using a modified version of our textures, we can simulate some diffractive anomalies on the lenses such as dirt orbs, rain orbs and eyelashes diffraction. We used textures using the Screen and Add blending modes, box blur and directional blur filter kernels. The following two pictures show an experimentation:




[1] Spencer, G., Shirley, P., Zimmerman, K., and Greenberg, D. P. 1995. Physically-based glare effects for digital images. In Proceedings of the 22nd Annual Conference on Computer Graphics and interactive Techniques S. G. Mair and R. Cook, Eds. SIGGRAPH '95. ACM, New York, NY, 325-334. DOI= http://doi.acm.org/10.1145/218380.218466
Lens Flares by Alan Gordie
Understanding Camera Lens Flares
Lens Flares - Wikipedia
Fast OpenGL Rendering of Lens Flares
Lens Flares Effects
The Art of Modeling Lens Flares
Thresholding (image Processing)
Thresholding and Segmentation

Social Bookmarks

About the Author

Luis Cruz

I am pursuing my MS in Computer Science at Georgia Institute of Technology (GaTech) with emphasis in Computer Graphics. I received by BS in Computer Science at GaTech in 2009 with specialization in Software Engineering and Computer Graphics.

Leave a comment

You are commenting as guest.