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

[SUGGESTION] Add a way to get the nearest cellular position #91

Open
MarcusElg opened this issue Jun 18, 2022 · 2 comments
Open

[SUGGESTION] Add a way to get the nearest cellular position #91

MarcusElg opened this issue Jun 18, 2022 · 2 comments

Comments

@MarcusElg
Copy link

The cellular/voronoi noise generation is great, it is possible to get both distance and cell index. Unfortunely there isn't a way to get the nearest voronoi point/cell center.

Why is this useful?
Cellular noise is very useful for placing biomes in procedural world generation, by making an entire cell a single biome. The biome can then by chosen depending on different noise maps for temperature, humidity etc (Like https://towardsdatascience.com/replicating-minecraft-world-generation-in-python-1b491bc9b9a4 does for example). But this requires the cell position to be able to sample these other noise maps.

How can this be implemented?
This is one way that I solved it with my own version of the method. When finding the nearest voronoi point this point can be saved instead of just saving the distance and hash:

if (newDistance < distance0)
{
          distance0 = newDistance;
          closestHash = hash;
          nearestX = xi + RAND_VECS_2D[idx] * cellularJitter;
          nearestY = yi + RAND_VECS_2D[idx | 1] * cellularJitter;
}

This value can then be domain warped and finally divided with the noise frequency to get the position in global space.

I'm probably not the only one wanting this feature and I feel like it would make a lot of sense to have in the library, especially as it is quite simple to implement. I could send a pr myself, I wonder what the best way to return the value is tho as the current function only returns one value.

@granitrocky
Copy link

I just looked at this suggestion, and I think I know of a non-destructive way to implement this. I added mNearestX and mNearestY to the class definition and set them using the technique you described.

From there, I added a function that users can call to get the active center. The only hiccup is that this center function needs to be queried every time you poll the noise function, adding one more function into the pipeline. I don't know that there would be a better way to do it without refactoring.

@MrJones16
Copy link

I second this idea, it would be very useful! Because this feature doesn't exist, I'm going to have to write my own noise generation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants