# Python n-dimensional simplex noise

Simplex noise is like perlin noise, except much faster for higher dimensions, and has no square/cubic artifacts (perlin noise, depending on implementation and use can have some)

Panda has built in 2D and 3D perlin noise.

I implemented nD simplex noise in python. It samples 2D in .08 ms and 15d in .04 ms on my computer. It seems to be pretty much linear time for the number of dimensions.

Here is a little 3D noise sample made with the included example texMaker:

https://github.com/Craig-Macomber/N-dimensional-simplex-noise

Full simplex.py contents:
https://github.com/Craig-Macomber/N-dimensional-simplex-noise/blob/master/simplex.py

It was a fun python project. Look at all those list comprehensions (they are 3 deep at one point). It’s just a fantastic example of how cool python is. My n-D version is shorter than even the 2D example java implementation I worked from (by far). Every line in there except a few does something complex on one or more lists!

I’ll admit it could use quite a few improvements (I think my seed based shuffling code is defective and a few things also need adjustments). (Edit: fixed) It could use some adjustments on the functions to tune the appearance (adjust the attenuation radios and power), but it does work pretty well. The comments need some improvements (Edit: fixed mostly), and it needs more docs in general. Also, it needs some histogram analyses in the test code, and optional derivative vector computation (Edit: added).

Edit: Links moved, source posted to gitHub

Faster better more:

There are some pretty bad seam artifacts in there. I’ll have to look into what is causing them. I’m going to update the code in the main post. I’ll update the downloads later (if you want the new one now, just let me know)

Now with nD derivative vector computation for optimized normal computation. When using for animated 3D texturing (4D noise) the 4th dimensional derivative is change over time, which can make for some pretty neat effect I imagine. Imagine applying it to a stream surface mesh. You could compute the total derivative per pixel quickly to do things like adjusting color and spec for splashing/bubbles produced when high temporal derivatives are involved, as well as per pixel wavy normals animated properly, and animated matching mesh, all in a shader.

This code will be hooked up with a GPU version that produces identical results so you can render with it, and sample it on the CPU as needed. This will allow for baking vertex transforms and/or normals while syncing it with the procedural texturing

This is 3D procedural noise in the fragment shader, no cashing. Notice that it is properly shaded as if normal mapped (using noise derivatives). This is a slice of 3D noise, animated over time (I also have 4D noise working in shaders). Also, note the FPS. This is suitable for using multiple octaves of for realtime shading. When combined with sampling several larger octaves in the vertex shader, and a few in the fragment shader, it should create fast procedural noise. I don’t have a version of CPU noise that is a exact match yet, but I will eventually.

That is 140 million noise 3D samples per second by the way. GPUs are pretty impressive. There is a bit of room for optimization too, though it would untidy the code a bit.

Here is the 4D version:

Notice that it looks almost the same, though a bit lower FPS. It would be used for animated procedural noise on a 3D surface.

Once I get it working a bet more soundly, I’ll post the shader source.

Nice, very impressive! I imagine this could be used to simulate dynamic volumetric fog and clouds.

Thanks. I have an idea for how to use the 3D and 4D CPU and GPU versions together for various cloud LODs (Single plane sky with generated texture, placed particles, and ray marched near field volumetric fog). With the derivatives of the different scale sample’s derivatives, interesting lighting should be possible, including fake AO, and glow effects. It will be cool.

I’ll also be using different scale on CPU GPU (both vertex and fragment shaders) for my planets. I just need to get the CPU to match the GPU, but I’m not doing that until I get the artifacts cleared up.

It will be a while before I get too much further though. Other things are eating my panda time.

I just played around with this thing, very nice.
How hard would it make it so it was seamless on all sides of the cube?

You can just use 3D noise for that. Or 4D if you need animated. Sample a sphere for a spherical cube map.

Edit: Ok, we discussed this. Conclusion: Tillable noise can be done, but simplex noise dislikes tiling. To sample from a cashed tileable block, it will have to be unskewed. This may cause inefficiency and minor artifacts. On GPUs, cashing 4D textures is currently impractical, so it would only be useful for 2D and 3D on the gpu.

Hi can’t see your thing, server is down sorry

Fixed

Hi Craig.
thanks for the code.