Unity Compute Shader Noise Library

I am working on a port of FastNoise to compute shaders.

This has been superseded by FastNoise Lite

Hello!

Today I am releasing my port of FastNoise from C++/C# to Unity Compute Shaders. The API is near identical to the original, and should be just as fast. I am writing this because of the lack of a (open-source at least) noise library for compute shaders which supported seeding. This is also helpful as you can produce the same noise values as on the CPU using the original library, thus proving to be very helpful for moving, for example, terrain generators to the GPU for faster performance, while still supporting GPUless systems.

As of this post, the only two types of noise not supported by this library is 4D Simplex noise and cellular noise. I'm going to add them soon.

You can get my port here, the C# library here and the original C++ version here. This library also has a port to Java and a version which uses SIMD CPU functions.

An example of using this library is shown below. This a part of a prodcedural terrain generator used with my marching cubes implementation.

1// Determine position
2float3 pos = ...;
3
4// Configure noise
5FNSetSeed(seed);
6FNSetFrequency(frequency);
7
8// Get noise
9float noise = FNGetPerlin(pos);
10
11// Add the point data to the buffer.
12points[...] = float4(pos, -pos.y + noise * 6.0);
HLSL

I have removed everything that is not relevant to the example (such as position determination). Here you can see the same process in C# (again, part of a larger system):

1// Create FastNoise object or update seed.
2if (_noise == null) {
3    _noise = new FastNoise(seed);
4} else _noise.SetSeed(seed);
5
6// Set frequency
7_noise.SetFrequency(frequency);
8
9// Get noise
10float noise = _noise.GetPerlin(pos.x, pos.y, pos.z);
11
12// Return the point data (the position and density)
13return new PointData(pos, -pos.y + noise * 6.0f);
C#

Be sure to star the repository if this is helpful to you!