top of page

4D Perlin and Worley noise fractals

I've been working on this for the last few days. I don't consider any of the code I wrote here to be particularly impressive; it's all stuff that was very easy and/or stuff that has been done before. However, the output was cool enough that I felt it would be a good idea to share it.

I wrote some code that created 2D Perlin noise:

inline float PerlinNoise(float density, float radius, float2 UV) { float oneDivDensity = 1.0 / density; float2 upperLeftCorner = floor(UV * density); float finalValue = 0; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { float2 cornerPos = upperLeftCorner + float2(i, j); float2 cornerValue = normalize(hash22(cornerPos) - float2(0.5, 0.5)); float2 cornerVect = UV - cornerPos * oneDivDensity; float value = dot(cornerValue, cornerVect * density / radius); finalValue += smoothstep(oneDivDensity, 0, length(cornerVect)) * value; } } return clamp(finalValue, -1, 1); }

Now, this is an old and tried method dating back decades (although I wrote the code myself, and I came up with this particular system for interpolation, I'm sure that's also been done before). It generates some simple 2D noise based on UVs:

I wanted to make this 3D, and converting the code to 3D took all of 5 minutes (just adding another nested loop and turning all my float2s into float3s). It was so easy I decided to make it 4D, so that it could be both applied to 3D objects seamlessly, and animated. While I was at it, I took my old Worley Noise / Vornoi code, and converted that to 4D as well, which was also easy. Making them fractals was as simple as iteratively adding noise with higher and higher density and exponentially lower magnitude (after making sure the range of the noise was -0.5 to 0.5 instead of 0 to 1) and then converting it back to 0 to 1 range. This worked for both the Perlin noise and the Worley noise.

Here's a video showcasing the result:

Featured Posts
Recent Posts
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page