Boids Simulation with Noise

Git: https://github.com/Ryan-Mus/Noise-Boids

This project implements a boids simulation in both 2D and 3D using Unity, with a focus on using different types of noise to influence boid spawning. I used this github as a start project. It has 2D and 3D boids using a realy quick algorithm. Use this to see what the start project looks like in browser.

Introduction

I was inspired by gil damoiseaux (R&D engineer at JangaFX) after following a optional day course on using noise to generate height maps @DAE. I found flocking the visual most appealing subject of the course Gameplay Programming @DAE and I thought why not try to incorperate noise in to flocking.

The simulation incorporates four different types of noise that can be used to create varied and interesting boid movement patterns:

  1. Perlin noise
  2. Voronoi/Worley noise
  3. Simplex noise
  4. Gradient noise

The spawn frequencies and directions of the boids are determined by the generated noise. Each noise is generated by using spawn location as input.

Each noise is uniquely implemented to use its characteristics to make interesting results (click this image to watch the results video)

Watch the video

Types of noise

Small Disclaimer: If I say random it is psuedo random in reality.

Color of noise

Everybody knows the white noise, The most known example of white noise is TV static. The color of noise tells us more about the frequencies that are in the noise. White noise has equal amplitude over all the frequencies

White Noise:

Other color of noise have different distribution of frequencies: Where Pink has more low frequencies and blue has more High frequencies

Other colors of noise:

I used mostly pink type of noise because that has more lower frequenties making it to have more big spots my boids spawn. But I have one exception and that is for my voronoi noise. That is more of a blue/violet noise using high frequenties around the edges of the cell. The voronoi is an exception because I use the inverse of the generated noise to determine the spawn rate making the inside of the cell the area where the most boids spawn instead of the edges.

Perlin noise

Just generating noise doesn’t make anything really interesting. It starts to be interesting when the noise keeps in mind it neighboring values. Perlin noise is made from a divinding a space in to grid and giving each cell a different direction vector. Then, for each corner of that cell, you measure how far the point is from the corner and compute the dot product between the corner’s gradient and the vector pointing to the point. These dot products are then blended together using a smooth interpolation function (In my case a simple lerp). To have more control over the result I added 2 factors: Frequency and octaves. With the frequency you change the “scale” of the noise. Higher frequencies mean more waves and thus more zoomed out. Then we have octaves, octaves are used to add more detail. It adds more values with dubble the frequency but halve the amplitude. Perlin noise is a type of gradient noise because it uses interpolation function to create a Gradient.

Voronoi / Worley noise

Unlike Perlin noise which uses a random direction vectors, Voronoi noise uses a random point inside of a cell. Then a value of a certain position is determined by the distance of the closest point of that position. Sometimes the second closest or even third closest point is taken to calculate the distance and use that as value. Using this algorithm you get a result that looks like Cells, veins, organic structures. In my case I use the Worley noise inverted so I get dark edges and bright blobs. These blobs are where the boids spawn.

Simplex noise

Simplex noise is an improved version of perlin noise. The problem with perlin noise was the way it scaled when you go up in dimensions. If you have 2 dimensions you have 4 corners where you do the dotproduct and interpolation. When you have 3 dimensions you need to calculate the 8 corners. This algorithm scales 2^n. To improve the algorithm simplex uses triangles instead of square grid. Making it scale n + 1 when going up in dimensions. For the rest it is the same algorithm using a random direction vector per cell and using the dotproduct to interpolate between the points. Using this non rectangle grid makes noise to have less directional artifects.

Gradient noise

Gradient noise is a type of noise. Perlin and Simplex are examples of gradient noise. In this project I added this noise setting to make interesting visual result by using perlin noise and added a swirl to it. I use a swirl depending on the position. This makes result of the perlin noise have more curves and longer streaks of boids spawning. This results in beautiful curves of boids spawning that start flocking in the same direction.

Results

Possible extra with noise

I use the noise mainly for spawning conditions and directions but these noisemaps can be use for generating a flow field where the noise decides where the boids should go towards. It would be a bit like simulating wind that is influencing the boids. These would definitely result in cool looking results and If I had more time would have loved to implemented them.

How It Works

  1. Noise Selection: Use the noise button to cycle between the four noise types
  2. Parameter Adjustment: Adjust sliders to fine-tune noise parameters in the Main camera object
  3. Real-time Regeneration: Boids are automatically regenerated when parameters change
  4. GPU Acceleration: Noise calculations are performed on the GPU via compute shaders

References

Start Project:

Wikipedia:

Youtube:

Other websites: