# Blender 3D: Noob to Pro/Advanced Tutorials/Cycles Fireflies 2

| Dealing with Fireflies in Cycles | • Table of Contents • Glossary | next module: "Procedural Eyeball in Cycles" |
You previously read about techniques for controlling fireflies in renders done with Blender Cycles, and how, when all else fails and tweaking renderer parameters doesn’t help, it is time to roll out the Despeckle filter. Sometimes a despeckle applied across the entire image may be too blunt, leading to unwanted effects in parts of the image where there are no fireflies.
But never fear. There are yet more options in Blender’s compositor that we have yet to explore, to give us even finer control over the application of despeckling, and hopefully avoid the final, desperate measure of hand-retouching (shock! horror!) individual blemishes in an image-editing program.
The basic principle is, fireflies are caused by specific interactions of types of materials and lighting, hence they will only occur in particular parts of the image. By separating out the problematic materials/lighting cases, we can selectively apply the filter just to them, minimizing side-effects on parts of the image that look just fine.
We will present a way to do the separation.

## Finer Despeckling: Separate Lighting Passes
### Separating The Lighting Passes

The Cycles renderer has the capability to separate out different kinds of light paths into separate passes for individual processing. Consider the diagram on the Blender wiki, showing how the direct lighting, indirect lighting and colour calculations are broken down by diffuse, glossy and transmission light paths, before being combined together with emission and environment lighting. We can split out all these passes, and use compositor nodes to recreate the standard combination as described there. But we can also intersperse our own processing onto particular passes, leaving the others untouched.
To tell Blender that we want to extract the light passes, go to the Render Layers context in the Properties window, and look for the Passes panel. Notice the four groups of 3 buttons each for “Direct”, “Indirect” and “Color” grouped under “Diffuse”, “Glossy”, “Transmission” and “Subsurface”? (Depending on your Blender version, the “Subsurface” group might not be present.) Click all these buttons, and also check the “Emission” and “Environment” boxes just below.
Now if you go back to the compositor window, you should see that the RenderLayers node has sprouted a whole lot of extra output terminals, one for each of the buttons/checkboxes you clicked.
Next, we want to recombine these to mimic the behaviour that Blender provides by default. If you go back to that Blender Wiki diagram above, you will see that, for each shader type (diffuse, glossy etc), the direct and indirect light passes are added together, and the sum is then multiplied by the colour calculation. The result from all the passes is then added together.
The Blender compositor has standard node types for adding and multiplying colours. Armed with this information, you might immediately set to work putting together an intricate node setup to implement the formula depicted in that diagram, perhaps ending up with something like at right.
Show this to a seasoned computer programmer, and they will perform the gesture known as a “facepalm”. Yes, technically this will work, but it is quite complicated-looking and error-prone. Supposing you get a connection wrong: how would you find it? How would you debug your node program?
For, make no mistake, nodes are a programming language. Putting together a node setup is very much like writing a computer program. One of the important principles is don’t repeat yourself. That is, if you find yourself doing the same sequence of steps more than once, it makes sense to spell it out once, and then next time just tell the computer to do the same thing again.
So let us see how a programmer would approach this same problem. To start with, consider the most basic operation, which is: add the direct and indirect components, and multiply by the colour. So create a pair of Mix nodes, one to do the Add and the other to do the Multiply, and wire them appropriately. Turn them into a group CTRL + G , and add group inputs and outputs as in the diagram.
To change the names of the inputs and outputs, you can select them in the list that appears in the Properties shelf N in the Node Editor window, then type a new name in the appropriate field just below the list.
Having done all the wiring, TAB out of the group, so you can give it a name. Here I call it “Pass Combine”. See how naming the inputs and outputs helps make it clearer what the node is for? And if you want to see the details, just TAB into the node for more. This technique is called abstraction, where you start by seeing only the overview, but you can progressively peel back the layers to see more and more detail, but only where you want to. This is an important technique for dealing with complexity, which is what programmers do every day.
We will need four instances of this group, plus another bunch of Mix nodes to add them all together. We are adding 6 quantities, so we will need 5 Mix nodes. Again, I make a group to combine all these adders, just to make things neater.
I call the resulting group “Add6”. Blender only provides nodes to add two quantities at a time, yet here we have made our own custom node that can take 6 inputs at once. Neat, huh?
So now we combine our building blocks into a new building block that computes the combination of all the passes, and looks like this.
Note the ordering of the group inputs, to ensure a nice and neat arrangement when we connect this node up below. You can rearrange the inputs by selecting one from the list in the Properties Shelf N and using the up- and down-arrow buttons next to the list to change its position.
And then when we connect that building block (here called “Combine All”) into all the RenderLayers outputs, our complete node setup now looks like this.
Compare this with the original simple-minded recreation of the pass-combining algorithm: which would you rather be presented with when you open a Blender document?

### Fixing The Fireflies

Anyway, now that we have separated the lighting passes, such that we can recombine them to produce the original image anyway, how do we actually go about fixing the fireflies?
First we have to isolate which passes are producing the fireflies. Click the “Backdrop” checkbox in the header of the compositor Node Editor window. Now, CTRL + SHIFT + LMB on the RenderLayers node, and you should see a new Viewer node automatically appear and connect itself to the first output terminal on that node. At the same time, the background of the window changes to show the image produced by that output terminal. The first terminal should be showing the complete image, including the fireflies.
Keep pressing CTRL + SHIFT + LMB , and the Viewer node will connect to each output terminal in turn. Some may be all black or all white, but don’t worry, just keep going. When you come to the Diffuse Indirect output, you should see something like at right, mostly dark, but with noticeable fireflies. Make a note and keep going; I also found that the Glossy Indirect output was another source of problems in this case.
So we need to insert a Despeckle node between the Diffuse Indirect output from the RenderLayer node, and the corresponding Diffuse Indirect input on our Combine All node. But instead of just making a simple Despeckle node, let’s make a custom node group. Why? Because we’ll need it in two places. So rather than having to set it up twice, just do the setup once, and insert two instances. That way, we can adjust the despeckle settings in just one place, and have it automatically take effect wherever there is an instance. Also, maybe we want to try other filters in combination with or instead of Despeckle; again, we would only need to make the change in one place, and it would automatically affect all instances.
“Don’t repeat yourself”, remember?
So here we are, with a couple of instances of our custom “Fix Fireflies” node group inserted in the most troublesome light paths.
And here is the resulting render.

## Conclusion

Fireflies can be troublesome, particularly because there is no 100%-foolproof way of getting rid of them. After all, if there were, why not just build it in as an automatic part of every render? This pair of pages has presented a range of techniques for dealing with them, from simple to complex. Of course it makes sense to try the simple ones first, and only if they’re not good enough, is it worth expending effort on something more complex.

## See Also

* This video by Bartek Skorupa, which was the inspiration for this page.
| Dealing with Fireflies in Cycles | • Table of Contents • Glossary | next module: "Procedural Eyeball in Cycles" |