Introduction

Rendering in games is quite different comparing to the other situations as it not only requires quality but also efficiency. While fire rendered by ray tracing is widely used in industrial CG software such as Maya or Blender, real-time fire rendering in game is still a problem need to be solved. Different solutions are created for this specific topic. Although most of them are not physically based, they provide good visual effects. In this article I summary the wildly used methods for rendering fire in games.

Render with Shader

This is the basic way to render a fire in a game. The input is normally one or several pre-painted textures. The most important part of the shader is how to add the noise to make the right shape and surface of fire. Some shaders directly take a pre-build Perlin noise texture as the input and then use the noise to create the fire. This might cost too much texture space when there are a lot of objects using this shader. A more elegant way is to create the Perlin noise in real time inside the shader. This also let the shader user adjust the size and scale of Perlin noise easily by modifying parameters.

Origin algorithm of creating Perlin noise is quite simple [1]. It takes the nearby gradients and mixed them in a special way as well as an ease function. Here will not cover the detailed steps but introduce an improved way in games to get a better detailed Perlin noise result. This function is based on a random noise texture which is used for get the values of random gradients. In order to get a more detailed result, different sample rates are used. Smaller sample rate has less detailed and would determine the basic shape of the whole noise. Larger sample rate has more detailed information. Combine those value with different parameters and will then leads to the final result.

Fire Rendered by Shader using Perlin Noise

Render with Particle System

This is the most wildly-used way to create fire VFX in games. Comparing to only using the shader, using particle system provide a more flexible way to adjust the shape of the fire. At first the particle system only emits red small particles to simulate the fire. This requires a huge number of particles and the result is not constant. Later this method was improved. The particle system no longer simply creates small dust as particle but creates the fire textures. This is used until now and have a pretty acceptable result. When applying with particle force zone, the fire can also receive influences from outer force like wind. The quality of the final result using particle system depends on both the particle shader and the particle system parameter settings.

The shader takes fire textures as input. The textures have different forms which lead to different shader algorithm. One kind of the texture is just a simple fire image or something similar. The shader gets the image and apply noises on that. Another form is a fire animation sheet. The shader takes the whole texture as a 2D animation sheet. By setting the UV of the created particles, the shader can display each frame in the sheet with a custom speed. This makes the whole fire looks more dynamic as every single little particle fire is also animated.

The particle system needs to be carefully adjusted to set the parameters right such as particle life time, velocity, color during life time and so on. The particles also need to always face to the camera as they are 2D textures. This requires experiments on the particle system of game engines to get a better result.

Fire VFX created by particle system (Single Sprite from Internet)

Using particle system can also create smoke effect together with the
fire. Smoke effect is a mature VFX in games. A common way is to use the smoke
animation sheet together with a normal sheet. The normal sheet is the secret to
make the result looks realistic. The normal can enhance the surface shape of
the smoke and make the smoke more nature.

Combining the two particle systems together or simply use one particle system but adjust the color and shapes during particle lifetime can make a satisfiable fire in games. The problem is that the fire can only be influenced by the force zone but can not be influenced by other physical mesh objects in the scene. This means if a ball is put on the particle systems, the shape of fire would not change.

A sample of smoke animation sheet

Associated normal sheet

Another problem for the particle system is that the other project on the scene also would not be influenced by the fire. For example, the objects around the fire would not receive the light from the fire. One solution for the light problem is to put a point light in the fire and change its position to make a feeling of the shaking fire light.

Red smoke made with particle system

Render by Particle System with Collision

Usually the fire
rendered with particle system can receive the influence of wind using particle
force zone in game engines but could not be influenced by the other objects. This
means that if a block was put in the middle of fire, the fire shape would not
change. To solve this problem, collision system needs to be added into the
particle system.

This needs mainly two changes comparing to the original particle
fire. The first change is on the textures. The textures need to be a smaller
size so that the collision would become more realistic. The origin particle
fire use big detailed animated fire textures so that the shape would look
dynamic and constant. The texture sometime is too large to show the collision
of the other object. When add collision system to those particles, their
positions change in a large scale. Noise would also be put in this situation to
increase the dynamic of the whole shape as the texture size is scaled down. The
second change is the number of particles. In order to get a better and smooth
simulation of the collision, the number of particles need to be far larger than
the origin system.

To reach a better result, particle force zone also needs to be added. Normally if we put a big cylinder in the middle of fire, the fire would separate at the bottom of the cylinder and then try to combine the two branches together at the top of the cylinder. Particle force zone is added to force the particles gather to the middle. 

Particle System Rendered Fire with Collision System

Volumetric Rendering

Volumetric
rendering is usually used in rendering cloud in games. For the cloud situation,
the shader takes several 2D textures and combine them as a 3D texture. Add some
noise and using ray marching algorithm to get final render result. Cloud would
not change its shape in a short time and would not be as dynamic as fire. The
cloud would also not have a physically based shaped. This make it possible for
rendering cloud with a pre-painted 3D texture. Fire has a more dynamic
situation. Its shape is based on the physical and would be influenced a lot
from the outside.

There exist some methods that use a 3D texture to render a fire in game. Their performance is just like the particle system methods and even worse as they need more texture space and details.

The incompressible Navier-Stokes equations are used to render real-time fire in recent researches.

In this equation, u is the velocity field, p is the pressure field, v is the kinematic viscosity of the fluid, ρ is the density and f is the external force field. This equation is usually calculated in three steps and needs to solve two Poisson equations during the process. This can be parallel computed with GPU using OpenGL but hard to achieve in game engines using shaders. Another problem for physical based volumetric rendered fire is that the efficiency is still too low. In order to get a good detailed of fire, when the whole size is too large, the total time cost is intolerant.

However, volumetric rendering is still the future of fire rendering in games. The NS equation needs a better simplified solution. Once the complexity is reduced to an acceptable level, volumetric rendering would be the best way as it can simulate the physical influence that the fire received from the outside.

Final Result

As we are trying to reach a photorealistic rendering result in game engines, the final result is achieved with particle system in Unity Engine with a high-quality fire animation texture sheet. Different game engines have different kinds of particle systems. In Unity, the particle system has mainly 22 parts of settings as listed below.

Particle System Settings

Fire Animation Texture (From Internet)

Their functions are clearly showed in their names. They cover almost all the settings we need for a particle system. The mainly used settings are Emission, Shape, Renderer and the overall setting.

Usually there are two ways to play the animation in the texture sheet. One is to write our own shader for the particle material. The other one is to use the Texture Sheet Animation setting of the particle system to play the animation on the sheet by modifying the UV of every particle. Here we use the Texture Sheet Animation settings to play the animation for each particle.

Texture Sheet Animation Settings

There are two settings extremely important for particle fire. The first one is the size of the particles. As we are creating particles from fixed texture sheet, it is better to have a random size of each particle to make them more dynamic. The second one is the color of the particles. Directly creating new particle would suddenly create a flame texture in the scene which would look interrupt and unrealistic. In order to fix this, we need to set the alpha channel of the particles as a changing curve during its lifetime. At the beginning the alpha value is 0 and then turns to be 255 which would finally get back to 0 at the end.

Color curve of each particle

Then the final result would look like below.

Final Result

Conclusion

Shader can be used when lack of art assets like the fire texture and can reach a low realistic result. The shader method is also lack of control and hard to adjust the shape. There are little games that are still using this method to create fire nowadays.

Using particle system to create fire VFX in game is still the most wildly used methods and has a pretty acceptable result. Good render result needs detailed fire textures as well as normal sheets and animation sheets. This is the most suitable method for games. By adding collision system into the whole particle system, fire shape can also be influenced by the other objects. Though it can simulate the shape well, this method can not simulate the lighting effect in a realistic way.

Volumetric is the future of the fire rendering in games. This method can render the fire in a physical based way and have more detailed information. However, its algorithm complexity is still too high to use in games. Once a better solution for NS equation or a better way of simulation is created, volumetric rendering can take the place of rendering fire.

References

[1]   Ken Perlin. Improving noise. In Proceedings
of the 29th annual conference on Computer graphics and interactive techniques

– SIGGRAPH ’02, page 681, 2002.

[2] Tang Yong. Real-time
Fire Simulation Combined with NS Equation and Volume Rendering

[3] Vincent
Pegoraro. Physically-Based Realistic Fire Rendering

[4] Zeki Melek. Interactive
Simulation of Fire

[5] Alfred R.
Fuller. Real-time procedural volumetric fire

[6] Ashwin
Bangalore. A Technique for Art Direction of Physically Based Fire Simulation