April 28, 2017

Short April Updates - from forest fires to foam skirts

Forest Fire

Many years ago I took a class in Differential Equations. One of the assignments was to simulate the evolution of a forest fire and the result was displayed on a graph. The problem was that you only got the end result and couldn't see how the fire evolved to get to the final result. A few years later I learned Unity, and decided to see if I could simulate a forest fire while at the same time see how it evolved. And it turned out I could.
The forest fire worked, but the visuals didn't. The first problem I had was smoke. A forest fire is large and you need a lot of smoke to cover the entire area - and that is not good from a performance perspective, and the resulting simulation was running in like 3 fps (30 fps is the goal). Luckily, both Unity and I have improved our skills.
The first thing I improved was to replace the fire particles with a glowing-ground-shader. Most of the time, you can't see the fire because of all the smoke, so by having just flat fire instead of fire particles makes no difference. I also decided to use animated smoke particles from Unity's free library of particles: Free VFX Image Sequences & Flipbooks. By using animated particles, the smoke will look more thick and you can use less particles to achieve the same result.
The second problem I had when I created the original forest fire was similar to the smoke problem: a lot of trees will decrease the performance of the simulation. To solve that problem when I created the original version was to combine all trees into a single mesh. This is also a complicated solution because it will make it much more difficult to remove the trees as they burn down. Luckily I could now replace all that code with a single shader called GPU instancing, which is something Unity recently added. If you add one of those materials to objects with the same mesh, Unity will automatically combine them, and the performance will improve. Anyway, this was the result:


As said in the forest fire update I added an animated glow shader to simulate the fire. The reason was that I've also improved my shader skills. The first shader skill I learned was Interior Mapping, which is a technique used to simulate floors in buildings. The second technique was Parallax Mapping, which is a technique not that different from interior mapping, but you can simulate more "organic" deformations, such as this:

Tesla Simulator

I few years ago I made a Tesla Simulator to market a book I wrote about a guy called Elon Musk. It was available to the public through Unity's webplayer, which you could run directly in a browser like Chrome or Firefox. The problem now is that most browsers have stopped supporting the webplayer, so I had to make an offline version. At the same time I've cleaned up a lot of silly coding mistakes I made, because the Tesla Simulator was the first project I made in Unity - and I've apparently learned a lot since then.

"Make a boat" tutorial

One of my most popular Unity tutorial I've made is Make a realistic boat in Unity. What the tutorial didn't have was how to add foam to the boat, and I've thought a lot about what the best way is to add foam to a boat. Then I found this tweet:

...which was a cool idea on how to add foam, so I decided to implement it: Add foam. To make that work, I had to learn a technique called Convex Hull, which I wrote a separate tutorial on how to implement: Find the convex hull of random points.

No comments:

Post a Comment