top of page

Dynamic Grid Generator in Unity 3D

Breakdown

One of the biggest limitations I faced with my first fire progation system was its use of vertex points for spawning fire emitters/particles. The density of the fire on a mesh was determined by how many vertices a mesh had. Higher vertex count meant high flame density.

The wireframe of the mesh. Each vertex is a propagation point for fire.

As seen in the image above, each vertex is a propagation point for an emitter. The problem was if any change was required in the flame density, I had to return to Maya to edit the edge loops on the mesh. To address this limitation, I needed a system that can dynamically create propagation points. I used a similar algorithm discussed by Jean-Francois Levesque, programmer who developed the fire propagation system seen in Far Cry 3.

 

The first step was to generate a grid of cells. Using the bounding box of a mesh, I generated a grid of cubes that fill the bounding box. The resolution of the grid can be controlled parametrically. Higher resolution would generate more cells that could act as a propagation point. 

The images above show the various levels of grid resolution for different types of objects.  The next step was to calculate the cells which overlap or collide with the surface of the mesh. This is to prevent emitters from spawning in the air and only on the surface of the mesh.

The above images show the probable propagation points for spawning fire particles. The initial algorithm involved raytracing from the centre of each cell towards the centre of the mesh's bounding box. This however, produced an uneven distribution of propagation points, particularly concentrated points near the centre of the bounding box. 

 

I developed another algorithm which planar projects the raytraces from all six sides of the bounding box. This produced a better distribution of propagation points. The points mapped accurately across the surface of an object no matter the complexity. If a mesh had grooves or empty spaces, they were not considered. So if there was an object such as a donut, the centre of the donut will be left empty. 

The algorithm is able to trace any complex surface and generate propagation points which can be used to spawn and propagate fire. The propagation algorithm I designed was inspired by Djikstra's shortest path algorithm. I designed and developed this propagation system using both the Unreal 4 engine and its blueprint scripting tool AND Unity3D and its C# Scripting.

 

Additional enhancement include the following:

 

1) Propagation to skeletal meshes and

2) Propagation across moving physics objects

bottom of page