Draw lightning

30

We have summarized how to make lightning with CG.

thumb.pngWhat you actually made will be on top.

Making Shapes

We will present three ways to draw a thunderous shape.

1. Draw by hand

Recommended Level: ★★★★ ☆

It's a primitive method, but it's the quickest way to do it, with few assumptions (no body and no lid).

  • merit
    • You can freely decide how to stretch
    • The number of starting points and the number of branches are free
    • Thickness and thinness are also freely
    • If it is a small amount, it can be drawn in a short time
  • demerit
    • Sense is questioned
    • It's painful to make in large quantities

If you search for "lightning drawing method" on the Internet, you can find various things, but the methods are really infinitely different, and you can see the depth.

2. Academic Methods

Lightning Basics

I'm saying this, but I've never learned anything professionally, so I'm saying something quite appropriate. Please point it out in the comments if it is clearly wrong.

Mechanism of lightning ← recommend this article from the following explanation (because it has a figure ...)

What is lightning discharge -Physics of lightning discharge- If you want to know more about ←, click here

Dielectric breakdown

First, let's talk about breakdown. An insulator is an object that is difficult to conduct electricity, but there is a limit to everything, and even if it is an insulator, if you apply a high voltage, it will ionize and pass electricity as a result. Whether it is rubber or pure water, which is famous as an insulator, there is a difference in degree, but it causes dielectric breakdown. Air is also an insulator, but if a high voltage is applied, it will be dielectric and break down, and it will conduct electricity.

Lightning Passage

There are various types of lightning, but here we will talk about negative polarity lightning strikes that are directed downwards. The situation where this lightning occurs is a situation where a negative charge is gathered in the sky near the surface and a positive charge is gathered on the surface. Between the negative charge (empty) and the positive charge (surface) is filled with insulator air (capacitor).

When a lot of negative charges are collected in this situation and the voltage is high, the dielectric breakdown of the air begins.

Since the air is not uniform, such as unevenness such as a lot of moisture and little dirt, or mixed with garbage, the destruction proceeds in order from the place where insulation breakdown is likely to occur. This is said to be the reason why lightning takes the shape of a zigzag.

Since dielectric breakdown occurs not only in one place, but also in multiple places, the shape becomes branched like a tree (although the roots are turned upside down at the top).

By the way, it seems that about 3000V is necessary to proceed by dividing and breaking down air by 1 mm1. Even with 1 million V, you can only advance 30 cm.

I have omitted a lot, but in this article I will not be troubled if I understand this much.

DBM(Dielectric Breakdown Model)

Recommended Level: ★★ ☆☆☆

Fractal Dimension of Dielectric Breakdown - Physical Review Letters

DBM is a typical method that makes it possible to simulate the mechanism of lightning described above with a physical computational model. The paper was published in 1984. Since it is an IEEE paper, you can either belong to an organization such as a university that you can subscribe to, become an individual member, or buy the paper for about 40 dollars (I bought it).

Computer simulation of lightning discharge pattern to lightning rod

↑ There is a rough explanation in this paper, so you do not have to read the original paper.

dbm.gifThe GIF video is a lightning generation animation with a negative charge (black) in the sky and a positive charge (white) on the surface. Grows step by step towards a positive charge.

In this method, the space is divided into squares, and one of them is registered as the first dielectrically damaged mass (yellow in the video). We determine whether or not new dielectric breakdown occurs for the cells adjacent to the destroyed cells (candidate squares), and if the determination is successful, increase the number of destroyed cells and propagate repeatedly. The judgment is based on probability, but the formula is (1) the probability of destruction increases as you get closer to the ground surface (the white part of the video), and (2) the probability of destruction of the old part gradually decreases.

14_dbm_top_b.png14_dbm_top_a.pngLeft: A collection of dielectric squares, Right: Short branches with color adjusted to darken

It is very easy to understand and it produces a nice shape, but this method takes a lot of time and is not recommended. Each time a single dielectric breakdown occurs, the overall calculation must be repeated until the entire space is in equilibrium, so the more the total number of squares, the slower it becomes. The computed order is said to be $O(n*G^{1.5})$2 if the number of iterations is n and the total number of masses is G2. It took about 20 minutes to generate a 300x300 image on the Core i7-7700K (4.2GHz).

  • merit
    • Realistic shapes based on theory can be obtained
    • Can also be applied to 3D
    • If you determine the charge of the space appropriately, you can extend it in any direction you like.
    • Nesting complexity can also be adjusted by parameters
  • demerit
    • Fatally slow

DBM Fast Improved Version

Recommended Level: ★★★★ ☆

The DBM is so slow that I searched for something a little faster, and I found one (probably) open access paper on the net, so I'll show you. If you can find a better thesis, you can find something better, but I can't put that much passion and money into it.

Fast Simulation of Laplacian Growth

16_fastdbm_mono.png16_fastdbm_gray.png

In the original DBM, it was necessary to recalculate the charge of the entire space every time it was dielectric and broken, but this improved method overwhelmingly reduces the amount of calculation by recalculating only the candidate squares adjacent to the destroyed squares. The probability of dielectric failure of a new candidate mass is defined to increase with distance from the starting point. The computed quantity order has shrunk to $O(n^2)$2. Even this is painful when the image size becomes larger, but it is much faster and more practical than DBM. It only takes about 7700 seconds or so to generate a 300x300 image on the Core i7-7700K (GHz) (fast!). )。

If you implement the paper as it is, you can only create a shape that radiates from the center like the image, but if you try to bias it, such as increasing the probability of the lower side, you can extend the branch in any direction and increase the degree of freedom.

  • merit
    • Significantly faster than a plain DBM
    • The resulting shape is also not much different from DBM.
  • demerit
    • Since it is a 2007 paper, a patent may exist (unconfirmed)

DLA(Diffusion-limited aggregation)

Recommendation: ★★★ ☆☆

Original Paper: Diffusion-Limited Aggregation, a Kinetic Critical Phenomenon - Physical Review Letters Only two DLA articles within Qiita DLA is like art. It's beautiful. Numerical Simulation in Python (2) - Diffusion Rate-Limiting Agglomeration (DLA)

DLA is a physical phenomenon called diffusion rate-limiting agglomeration. If you know the game of Katamari Soul, it would be easier to understand if you imagined it. If you don't know, please imagine snowflakes or salt crystals. At the beginning there is a small nucleus, and a large number of fine particles fly around it (Brownian motion, which you learn in high school). Particles that touch the nucleus stick to the nucleus and become part of it. The nucleus grows rapidly while taking in the fine particles around it.

17_dla_mono.png17_dla_gray.png

The final shape is a tree shape with roots in the center. It's very similar to DBM's. DBM is also a type of DLA, so it is natural to say that it is natural.

In the case of DLA, it is difficult to control which square is added to the new shape because it depends almost entirely on the random number, but by devising a device such as biasing the initial position of the fine particles, you may be able to stretch the shape as you want to some extent. Since the implementation is a monkey, it took about 20 seconds to generate 300x300, but I think that it is faster if it is seriously implemented.

  • merit
    • Significantly faster than a plain DBM
    • The stretching method can be controlled depending on the arrangement method of the fine particles
    • There are a lot of articles and implementations on the web
  • demerit
    • Fineness of branching cannot be adjusted
    • Adjustment of the number of fine particles and the initial position varies depending on the image size, so it is difficult to adjust (normalization should be easier)

Other methods that I have examined but have not confirmed

3. Simple Approach

Recommended Level: ★★★★ ☆

Handwriting is dull, but the academic way is realistic, but the processing is slow and there is not enough freedom. Isn't there a way to generate a decent image a little more appropriately?

Failure probability constant method

Simulation of discharge patterns (Lichtenberg shapes) - Lazy Life, Easy Exit

The method introduced on this site, like DBM and DLA, is that whether or not dielectric breakdown progresses is determined by probability, but the probability is all constant regardless of location.

By setting the probability to a fixed value at all squares, the way the branch grows is quite different from DBM, etc., but the calculation is completed very quickly. I was able to generate 300x300 in about 0.3 seconds.

01_basic.png

Make probabilities uneven

※ From here, it will be a completely original method. It is a sense of ad hoc MAX.

The above method is good for high speed, but I do not like that the shape is a little regular. Wouldn't that feel a little more unstable? As mentioned in the original article above, if the probability is a fixed value, the shape of the nesting will not be complicated much even if the probability is lowered.

If so, try to make the shape a little more irregular by making the probability uneven locally.

Let's try to express the dielectric breakdown probability for each mass as a grayscale image. Let's say black is 0% and white is 100%. In the case of a fixed value, the whole is painted in one color.

02_valuenoisemodel_prob.png

This time, we tried to create such a probability distribution using noise called value noise. Even if it is not value noise separately, the same distribution will be obtained for perlin noise etc. The image generated by this is as follows. Did it feel a little irregular?02_valuenoisemodel.png

Making a Probability Mask Manually

If you look at the image above, you may intuitively notice that the lightning created in this way is almost always stretched to avoid the part with low probability.

Conversely, if you prepare an image with a high probability of the part you want to pass through and a low probability of the part you do not want to pass, you can easily control the path of lightning.

Prepare a handwritten image like this and let it generate lightning according to this probability.

mask03.png

The gray area is 30%. Generate from the top left. The results are as follows:

03_imagemodel2_gray.png

There is a tendency to run in-course a little, but it can be managed by adjusting the shading of the probability image.

Paint colors

I think that which method you choose depends on the person, but let's say that the shape is done for the time being, and next I will think about how to paint the color. In the case of handwriting, please paint as you like according to your own sense.

For information, it is assumed that you have a tree structure (bidirectional connection) with the root starting point (in the case of either method 2 or 3, it is possible to prepare it by recording the correspondence of the source ⇔ the destination of the failure when dielectric breakdown occurs).

The image below shows only the longest branch extracted from the lightning tree generated using Method 3. We will use this form to illustrate it.

flare_longest.png

How to use Gaussian Blur

If you draw it as it is like the image above, you will be worried about the crunching of the dots, so I will add blur to erase the dot feeling and to express the diffusion of light unique to lightning.

Apply a Gaussian blur with a radius of 1 to an image depicting a line of thickness 1. Next, apply Gaussian blur with a radius of 4 to the image depicting a line of thickness 3. While changing the thickness and radius, add and combine everything after making several levels of images. Then, it should be finished with a vague glowing feeling.

fig.png

The relationship between thickness and radius and how many steps to layer depends on the degree of clarity of the lightning you are looking for, so please try to find a salt plum that is just right.

apply.png

When I applied it, I felt that it became somewhat like that. Depending on the person, you may be worried that there is still a little dot feeling.

Method using electrostatic potential simulation

If you place the charge $Q$ in space, the potential $V$ decreases in inverse proportion to the distance ($V = Q/r$). When $Q = 1$, the difference in the height of the potential generated by the charge is visualized as an image.

field_example.png

It is a grayscale image, but it is adjusted so that the potential of 1.0 or higher is the brightness 255 (white) and the potential 0.0 is the luminance 0 (black). Doesn't it look like a point light source with a dim light spreading out from the center?

If you place it in a row in the path of lightning and simulate the mutual effect of electric charges, it looks like lightning shines.

flare_00.png

It is okay if the entire path has exactly the same charge value, but if you adjust the value so that the value changes for each part, you can change the thickness freely. However, if the change is too large, it will become mottled and dirty, so be gentle.

thunder.gif

The GIF above is interpolated so that the charge at the start point (upper left) of lightning is 0.5 and the end (lower right) is 1.5, and the charge in the middle varies linearly so that it changes linearly. The upper left is thinner and the lower right is thicker, and I think it has created a little dynamic. A GIF consists of three images, each of which has a charge corrected by 1.0x, 0.5x, and 0.1x (so that it glows and disappears). Isn't this alone enough to make them a lot worse?

Specific simulation methods are realized by solving Laplace's equations using the Gauss–Seidel method. It may seem difficult at first glance, but it is a simple algorithm that repeats simple calculations until there are no changes.

Solving Laplace equations by difference method - Akita Technical College (section 2.3 here. This is the easiest to understand.) [Scientific and technical calculations using Python] Numerical solution by Jacobi method of two-dimensional Laplace-Poisson equations for electrostatic potentials, elliptical partial differential equations, and simulation of Poisson's equations that are the easiest in the world for boundary value problems - Tokai University (Poisson's equations are a slightly more complex version than Laplace's equations. The content is almost the same, so it is helpful.)

In addition, this method is only introduced because it looks like it, but it does not mean that it is correct to do this especially academically. I don't know the correct way so can someone please tell me.

In addition, the Gauss–Seidel method is $O(n^3)$ (maybe) when applied normally, so it slows down significantly as the image size increases. I think there are many sparse parts in the image, so I think it will be faster if processing is devised.

source code

There is a library and a Python sample that wrote the base part in C++ and made it available from Python. I think it is difficult to handle if you do not know both languages, but for reference.

The last two methods allow you to draw lightning (one branch) with the ease of drawing a straight line, and I think that it is worth using only this for the time being.

bibliography

Otoba Electric Industry Co., Ltd. Ed., Shigeru Yokoyama, Masaru Ishii, "Science of Lightning Deciphered through Photographs" Ohmsha, Inc. (2011)

at last

Even if it is called lightning, I think that what you imagine is slightly different depending on the person, so I think that there is no such thing as an OK as long as there is this method. Refer to the methods presented here and try to create your own lightning.

As for the contents of this article, I have omitted it a lot because it will be too long to write concretely, so if you want to know the details, please feel free to ask in the comment section, Twitter, email, etc.

Share:
30
chromia
Author by

chromia

Githubからもらったアイコンが人の顔に見えるのが勿体なくてアイコンを変えられない。

Updated on July 27, 2020