Skip to main content

X_Tesla gizmo

With this gizmo you will be able to create lightning and electricity effects. The effect is very customizable and flexible. You have control over the direction, shape, branches, complexity, colour, animation and many rendering options.

The gizmo includes some realistic render option such as the temperature based chromatic aberration and glow, an advanced soften filter, an easy to use 2 colour system. Or you can just disable everything with a simple check box, that’s also OK.

Start by picking 2 points on the image where the lightning will be generated, choose the detail and the turbulence size, adjust the number of branches and the animation speed, then you will only have to choose the color you like the most and you are ready to go!

Procedural Lightning


Create electric arcs between two points

Very customizable


Take control of the shape, width, color, speed and more

Complex rendering


Temperature based glow and chromatic aberration

Animation Engine


Easily animate the electricity

 Some lightning examples

Understanding Lightning

 

Lightning as Noise

Every Photoshop user has played, at some point of their lives, with the “difference clouds” effect. For those who haven’t, that effect is used to generate perlin noise. Then you can contrast the image so the result reassembles electric arcs. This technique is seen in 90% of the “Realistic Lightning in Photoshop!” tutorials. Google it to find out why I wrote “Realistic” in italics. In defence of Photoshop, I don’t know any other easy techniques to create procedural effects. From now on, we will call this type of effect “noise lightning”.

Anyway, you do not need a physics degree to kind of notice that noise lightning is kind of wrong. Let’s see why. There are four main reasons: first of all, the result lightning has a variable width. Real electric arcs sometimes do have this propriety but not as much as the noise lightning. The reason of this problem lies on the very nature of the perlin noise itself. Secondly, the lightning can sometimes go back on its path. This creates a weird wiggle effect. Again this can also be seen sometimes on natural electric arcs. But the noise lightning always does that. You cannot predict and you have absolutely no control over when or how this will happen. The third problem is very related to the second issue. Sometimes the lightning goes back up and meets itself again, creating closed arcs of electricity, even circular patterns split from the core. Maybe someone will correct me, but I have not seen this is nature yet. And the last issue we can see is that no branches are created (except for those weird disconnected patterns). If you want to create ramifications you have to do it manually. You also have to erase the disconnected arcs manually, meaning that it is not very procedural.

 

noise lightning 1

Photoshop’s “difference clouds” applied to a linear gradient. This effect can also be done in Nuke, After Effects or many other softwares. 

If we contrast the image, we can see how we are getting rid of the low amplitude noise and we are keeping the highlights.

Note the disconnected patterns and circular arcs that appear through the lightning. The lightning can sometimes curve over itself, creating weird looking “blobs” of electricity.

The previous effect, cleaned manually to get rid of all the errors. This can be good enough for a still, but for animated electricity it is unimaginable to clean it frame by frame.

Lightning as a Fractal

Fractal appear everywhere in Nature. From seashells to plants, simple mathematical patterns create very complex shapes. I’ve always been fascinated by the nature of fractals, and how the simplest form can create the most beautiful pattern. Lightnings are a natural phenomena, so it might not be insane to try to describe them in a fractal-ish way.

There are two possible approaches. The first one is to describe the turbulent movement across the lightning path as the result of a fractal, such as the Koch snowflake. This is very interesting, but for now we will focus on how can we create branches for our lightning. We will start by looking out the window and taking a B&W picture. Then we will process the image to get rid of all the leaves and very small branches, to see the main shape of the tree. You can clearly see the fractal patterns whe have been talking about.

 

These structures are called “fractal trees”. They are very easy to understand with diagrams. We start by picking one point and drawing a line. Then we split the line by half and divide the line in two separate branches. We will call this process an iteration. We repeat the process and get 4 different branches. We repeat the process again and the number of branches doubles the previous iteration.

Fractal_Tree_1Fractal_Tree_2Fractal_Tree_3 Fractal_Tree_4

However, the resulting structure is very symmetrical. By randomising the amount. direction and size of the branches we can get very organic looks. And I even dare to say that we could achieve realistic shapes using only this technique. Many experiments have already been done, and some of them are really promising. Fractals have been in CGI software for long, and they still have a great potential. They have even more uses than the longitude of the side of a fractal.

 

 

Lightning as a Wave

Before I mentioned how fractal behaviours could describe the turbulence of the lightning. One way to prove this is by looking at the lightning is if it were a sound wave.  Let’s take this picture on the left and try to analyse the shape of the electricity by thinking of it as the sum of multiple waves with different frequencies. What does this mean? Let’s take the shape of the lightning and decompose it in much more simple shapes. In the first iteration we will use only 5 points to describe the lightning shape. In the second iteration we will add an intermediate point between each pair of points. And so on for the third and four iterations. With this method, we can recreate the shape of the lightning.

Congratulations, we have just discovered that lightnings can be created using fractal noise. But you may wonder: “before you didn’t talk very well about contrasting noise patterns to create electric effects”. Yes, that is right. But here we are not using 2D noise images, we are using 1D noise waves. That means that no disconnected patterns or circular lightings will appear, no matter how we try to distort the wave. We can also keep the width of the lightning constant, depending of how we render it. And this wave can be animated easily, moving the noise in the x or z axis. It has, though, two problems. First of all, if you want the lightning to curve on itself, you won’t be able to. And second, no branches are generated.

For my gizmo I used a combination of fractal trees for creating the branches and fractal noise waves for the shapes of the core and its branches. I had to use python to make the branches stick to the core. Fractal noise gives you a great flexibility with just a few controls: one for the amplitude, one for the frequency and two controls for the amplitude and the frequency of the small detail.

Lightning as a Fluid

 

Let’s take this to the next level. If we really want to replicate the electricity movement we need to understand what electricity is. And electric current is the flow of electrons between two points with a difference of potential. With lightning, the electrons travel through the air searching for the path with the smallest resistance between two points.

The air opposes to the flow of electricity, creating a resistance. The electrons cause the air to heat and emit the light we see. They also produce the thunder sound, which travels at the speed of sound, much slower than the speed of light, causing the typical delay between the lightning and its thunder. Also, don’t get struck by lightning.

The electric discharge always takes the easiest path. In perfect conditions, that’s a straight line between two points. Because the air isn’t homogeneous, there is some turbulence. The resistance to the flow of electrons stars heating up the air.

The hot air expands, turning less dense than the cold air and therefore it starts to rise, making the electric arc move upwards. The path becomes less straight due to air turbulence. The path gets longer and longer the higher and more turbulent it gets.

The electric arc becomes more and more unstable. Finally it breaks, because the higher and more turbulent the path becomes, the less efficient it turns for the electricity to flow. A new arc is created between the two points and the cycle starts again.

 

This means that electric arcs are affected by wind, something that can be seen in some musical Tesla coil videos. That’s also the reason why Jacob Ladder always goes upwards. So, if we want to create a realistic lightning movement, the best approach will be to set up a fluid container with a variable density solver. The lightning will be created between the two points, and will look for high temperatures and low density areas as preferred paths. Then the lightning will heat up the fluid around it, changing its velocity and starting the movement in the system.

 

It wouldn’t be hard to create branches from that lightning at those points where two paths have similar temperatures and densities. It shouldn’t be slow to simulate or render, since you don’t need extreme resolutions to make the calculations. Also, it would be a great tool for composers, because you could have a realistic temperature-based chromatic aberration, or velocity-based colour. Perhaps the hardest thing to do would be making the asset easy to use for artists. I haven’t got the chance to test this, I’ve only theorized it. If I get some free time, I might try to make something like this in Houdini.

And, talking about fluids, I’m writing my own fluid simulation solver. It is not based on the Navier-Strokes equations, and it is conceived to speed up the connection between the FX department and the compositing team. Enough spoilers for now, I will post more news soon.

X_Tesla nodegraph as of version 1.1

“I don’t like Thomas Edison. I’m a fan of Nikola Tesla.”

David Lynch