Want to master Blender? Click here! and get our E-Book

When you purchase through links on our site, we may earn an affiliate commission. Learn more

Creating a lens flare in the compositor in Blender

Lens flares can be a great way to spice up a render and give it a more realistic look. While we could add these effects in a separate program Blender comes with a built-in compositor that we can use to add these effects. So how do we do it?

To create a lens flare in Blender:

  • Go to the Compositing Workspace and enable use nodes
  • Go to Add > Search > Glare then drag and drop the node into the graph
  • Connect the Render layers image output to the glare node image input then connect the glare node image output to the composite image input
  • set the glare type to the desired lens flare type and adjust the settings. Increase the threshold value so only lights are creating flare

In the rest of the article we'll go into depth about this basic lens flare setup. We'll also go over how to combine different flares. Finally we'll go over some tricks we can use to adjust the look of the flares.

How to create a basic lens flare

To create a basic lens flare in Blender:

  • Go to the Compositing Workspace and enable use nodes
  • Go to Add > Search > Glare then drag and drop the node into the graph
  • Go to Add > Search > Viewer then drag and drop the node into the graph
  • Connect the Render layers image output to the glare node image input then connect the glare node image output to the composite image input and also connect the the glare image output to the viewer image input
  • Press F12 to render
  • use the viewer preview to adjust the glare settings until you're happy with the results, I recommend increasing the threshold so that only lights are creating flares

One issue you may encounter is that you cannot isolate the light with the threshold value. We'll need to make sure that the light is the brightest object in the scene. Make sure the light source has a bright object behind it so that we can isolate it.

In this example we've just directly passed our render through the glare node. This setup works but we could also create a mix node instead and then additively blend the flare in with the original image. For this to work properly we'd also need to set the Glare node mix value to 1.

Mixing the flare in separately would allow us a bit more control over the intensity of the flare but for this example we are keeping it as basic as possible.

How to combine different lens flares

To combine different Lens flares:

  • Go to Add > Search > Mix and Create one node for the original image and connect the original image to the first input
  • add one mix node for the first two flares and then one node for each flare after that
  • Connect the first two flares to the first mix node then for more than two flares connect the first mix node output to the first input of the next mix node then connect the next node to the second input
  • connect the final mix nodes output to the original image mix nodes second input then use the original image mix node as the Composite Image
  • Make sure that each glare node we use has it's Mix value set to 1

The written explanation for this can be a bit complicated but hopefully this image conveys the idea of the node setup better.

To help stay organized we can use frames to help organize our nodes. Depending on the complexity of the graph this may not be needed but if we plan on adding a lot of nodes this can be useful. First select the nodes you want to group together then press Ctrl + J.

As you can see this will create a frame around our nodes. We can give the frame a label by opening the properties tab with the N key, this should open a small menu on the right side of the compositing window. In the Node Tab just type the label you want into the Label field.

How to adjust the look of a lens flare

There are a few things we may want to adjust but don't have the options for. The examples provided below are intensity and scale. We can adjust both of these with just a few nodes and we'll go over that in these two sections.

Adjusting the lens flare size

To change the size of the lens flare:

  • Isolate the light in the render, for this example we can go to Add > Search > Math and set it's operation to greater than
  • connect the render layer image output to the first input of the math node then adjust the second value until only the light is visible in the output
  • Go to Add > Search > Dilate/Erode, drag and drop it into the graph then set the mode to threshold and connect the output to a glare node
  • Use the Distance value of the Dilate node to adjust the size of the flare to be larger or smaller

While it may seem like the best way to do this is to just use a scale node. A scale node likely would work but this method means we won't need to realign the flare with the light.

Being able to adjust the flare size can be especially handy when we want to combine multiple flares.

Note that we don't have to use the math node to separate our light source. If our light emitter is an object we can change its pass index and pass it in. For this example though it is the quickest method and should work for most cases.

We can also preserve the the color of the light by using the value we extracted as an alpha mask and then pass that output to the dilate node.

Adjusting the lens flare intensity

To increase the intensity of the flares:

  • Go to Add > Search > Mix and place the node, Set the mode to multiply
  • Connect the image output from the flare into the mix node and then connect the mix node output to where the flare was previously connected to
  • Select the second inputs color of the mix node and in the HSV panel adjust the value until we have the flare at the intensity we want, note to input values above 1 we have to type the value in

While this isn't the most intuitive way of adjusting the intensity of the flare it seems to do a better just of increasing the contrast without changing the brightness or requiring a lot of changes.

We could use a Bright/Contrast Node it tends to overly darken the image and can take a bit to get the values where we want them. With the mix node method it seems to to be much more consistent.

We could also use a math node set to multiply if we're not worried about preserving the colors. If we want to keep the color modulation this method seems to work the best.

Technically we could also separate the flare into it's R, G and B channels and multiply them separately then recombine them. At that point though we're basically doing what the mix node is doing just with more nodes.

Final thoughts

Lens flares can be a nice touch to add to a render. They can help give our lights a more realistic look and help smooth the harsh edges we might get with a really bright light.

With a basic setup we can get a few different types of lens flares right in Blender and without much hassle. Using a bit of mixing we could easily combine a few of these to create a much more advanced looking flare.

Adding a couple more nodes to the graph gives us the ability to resize the flares as well as adjust their intensity. combining this with additive blending means we can fine tune the flares to look just how we want them to.

Thank you for your time.

Written by: Damian Paterson

Editor & Publisher

Erik Selin
3D artist, writer, and owner of artisticrender.com

My top product picks for Blender artists

Recent posts

Subscribe!

Subscribers to our newsletter enjoy more value! How about a collection of 40 HDRI skies for free!

Recent posts

Subscribe to our E-Mails

Subscribers to our newsletter enjoy more value! How about a collection of 40 HDRI skies for free!
We don’t spam! Read our privacy policy for more info.