Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Perlin and Simplex noise #15877

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Add Perlin and Simplex noise #15877

wants to merge 4 commits into from

Conversation

kno10
Copy link
Contributor

@kno10 kno10 commented Mar 8, 2025

Add Perlin and Simplex noise using the FastNoiseLite library (did not try alternatives such as FastNoise2).

Incorporates #15858
Closes #11468

To test, set flags = perlin, compat or flags = simplex, compat (absvalue is also supported).

For compat, I tried to get scaling somewhat consistent with the vaule noise currently used, but it's not perfect.
First of all, the library limits the noise to -1:+1, whereas the Luanti code did not include any such rescaling. Secondly, Simplex noise is "by design" more dense than Perlin or value noise. So if you use existing scale parameters, it is suggested to use compat. But for a new use case (e.g., a new mapgen), I would suggest not using this.

You can have terrain as weird as before when the mountain generator is active:
perlin

but the axis-aligned artifacts of value noise are gone. For mountains, this makes them look too blob-like IMHO. Works well with valleys generator, too.

With the current value noise, because it interpolates between points sampled on a grid, such artifacts arise frequently (most visible in mountains, as these use fewer octaves -- the grid is very visible on the minimap, too):
value-noise

@Zughy Zughy added Feature ✨ PRs that add or enhance a feature Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it labels Mar 8, 2025
@kno10 kno10 force-pushed the perlin branch 2 times, most recently from a2280dd to e223be0 Compare March 10, 2025 01:17
@sfan5 sfan5 marked this pull request as draft March 15, 2025 09:15
@kno10 kno10 force-pushed the perlin branch 2 times, most recently from f38fb77 to 452a011 Compare March 21, 2025 13:41
@kno10 kno10 marked this pull request as ready for review March 21, 2025 14:36
@wmikita
Copy link

wmikita commented Mar 22, 2025

IMO it's weird for Perlin and Simplex noise implementations to be accessible by passing flags to a value noise implementation (especially considering they're clearly conflicting), even though "simplex" was already there as a not-yet-implemented somebody-was-assigned-this-11-years-ago-and-here-we-are flag.
from what I can see, this results in a cluttered value noise implementation, with the clutter having to weirdly adjust itself in order to be more like the value noise already present. I would suggest separate classed for both if not for backwards compatibility issues that would arise with PerlinNoise; how about a new GradientNoise class, and then make the specific noise used a string enum passed to the constructor?
also, I'm not sure why anybody would want to use the compat flag? what compatibility does it actually provide?

@sfence sfence added the Breaking Change Changes an existing API behavior in an incompatible way label Mar 22, 2025
@kno10
Copy link
Contributor Author

kno10 commented Mar 23, 2025

Well, I did not want to break any compatibility by introducing a new API.
The compat mode allows you to easily use the current mapgen defaults, but with a smoother noise.
In particular for exploring the difference it is nice if you can use the noise with existing mapgens.
At the same time, it does not break any existing world.

New mapgens may use Perlin or Simplex noise by default, with new default scales that work well with standard parameters. Note that Simplex noise is about 15% finer than Perlin noise by design, so ultimately mapgen developers will likely focus on one of them (most likely Simplex, although it is a bit slower than Perlin noise unless this higher density allows us to reduce the number of octaves).

As for clutter, some of the code duplication is intentional to make it easier for the compiler to inline, e.g., have the conditionals rather outside of hot loops and duplicate the loop code.

@sfence
Copy link
Contributor

sfence commented Mar 23, 2025

Break compatibility is caused by renaming PerlinNoise in LUA mod API for example.

@sfence sfence removed the Breaking Change Changes an existing API behavior in an incompatible way label Mar 24, 2025
@sfence
Copy link
Contributor

sfence commented Mar 24, 2025

@kno10 Sorry, my error I miss line lua_register(L, "PerlinNoise", create_object); // deprecated name.

kno10 added 4 commits March 24, 2025 21:26
Fixes luanti-org#15775: Perlin noise is not Perlin noise, but fractal value noise.
A simpler noise algorithm that does not put gradients but values on the
corners of a grid, then interpolates inbetween.

This does *not* change the noise, only the method and class names.
@kno10 kno10 force-pushed the perlin branch 2 times, most recently from 0fb2626 to ab59c31 Compare March 24, 2025 21:28
@grorp grorp added the Waiting (on dependency) Waiting on another PR or external circumstances (not for rebases/changes requested) label Mar 24, 2025
@grorp grorp changed the title WIP: Add Perlin and Simplex noise Add Perlin and Simplex noise Mar 24, 2025
@grorp grorp marked this pull request as draft March 24, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature @ Mapgen Roadmap: supported by core dev PR not adhering to the roadmap, yet some core dev decided to take care of it Waiting (on dependency) Waiting on another PR or external circumstances (not for rebases/changes requested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider simplex noise instead of/in addition to classical Perlin noise
6 participants