godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.04k stars 21.18k forks source link

Simplex Noise functions (2D, 3D, and 4D) #1268

Closed bdero closed 6 years ago

bdero commented 9 years ago

Simplex Noise (also known as improved Perlin Noise) has many uses in modern game development, as it lies at the heart of procedural generation. Infinite terrain, voxel worlds, clouds, and just about any texture with realistic, natural patterns can be generated using Simplex Noise. It's commonplace in modern game engines.

Simple examples of simplex noise use:

Fortunately, it's also pretty easy to implement.

The ideal implementation would involve allowing the user to set the RNG's seed somehow (whether it's set using a separate function in advance or passed as a parameter to the noise functions), and exposing the noise functions in "@GDScript", which might look something like this:

float simplex2d(x, y)
float simplex3d(x, y, z)
Chaosus commented 6 years ago

And maybe performance is not so critical for this, because it called usually several times at level creation step and not in process function.. Not much games uses noise for generate level chunks on fly. And for graphical part of shaders there is already existed assets in Asset library...

JosefKuchar commented 6 years ago

Any progress on this so far?

aaronfranke commented 6 years ago

If we add 4D noise, it may be worthwhile to add 4D math types first (such as Vector4).

OvermindDL1 commented 6 years ago

For note, 5D and higher noise has immense uses as well, don't just constrain it to lower dimensions. It is not hard to create an N-Dimension version of the algorithm (though I did that via C++ templates long long ago so the usages got optimized extremely well, and I think I was using perlin then...).

aaronfranke commented 6 years ago

For 5+ D noise, it would make sense to add it since it is useful, but I would suggest only as a generic-ish function. For example, a function accepts float arrays, and passing an array of 7 floats = 7D noise.

OvermindDL1 commented 6 years ago

For example, a function accepts float arrays, and passing an array of 7 floats = 7D noise.

That's what I did in C++, if it could statically know the size of the array then it generated optimized code, else it fell back to recursion (which depending on what was being done could be about the same speed or a lot slower, depending on how well SSE could be used).

JFonS commented 6 years ago

I went ahead and added open-simplex-noise as a Godot module in #21569. Just commenting here in case someone wants to improve on it (maybe add 5+D noise?) since I won't be working on it in the near future. If anyone wants to work on it I'm open to answering questions.

Calinou commented 6 years ago

Simplex noise was implemented in #21569, so this issue can now be closed.

Thanks for your contribution @JFonS! :tada: