rthome / SharpNoise

A library for generating coherent noise.
https://www.nuget.org/packages/SharpNoise
GNU Lesser General Public License v3.0
37 stars 18 forks source link

Normalizing Noise Maps #21

Closed nshcat closed 3 years ago

nshcat commented 4 years ago

Hello, I have been looking through the documentation, and I am wondering whether there is any built-in functionality to normalize/map all values inside a noise map instance to a certain fixed range (such as [0.0, 1.0]) based on the minimum and maximum?

Of course, implementing this yourself isn't a big deal, but since I have been doing it in multiple projects again and again I feel like this could be a nice thing to implement as a library feature. What is your opinion on this? (I would be willing to add such functionality if its a desired feature)

rthome commented 4 years ago

Hi, while there's the Clamp module to limit the minimum and maximum generated values, there's nothing to normalize values in a noise map.

I can imagine some use cases where that would be useful though, so if you're willing to contribute the code, I'd be more than happy to accept it :)

nshcat commented 4 years ago

After looking into the architecture of the library, AFAICT it seems to not be possible to have a remapping like this as a module, since there is no way to know the extreme values at that point.

Maybe having different transformations on noise maps would be a good idea? There are different normalization mappings in use for terrain (for example, you could have non-linear ones to pronounce mountains or "compress" certain ranges of height values. This is done in Unity for example, and are described as curves there), so I don't think just adding a simple linear Normalize() member would do this awesome library justice :)

What are you thoughts on this?

rthome commented 4 years ago

I definitely agree that normalization would need to work on noise maps - modules are just stateless (well, almost) signal processors in a way and don't know about past or future values passing through them.

You could get somewhat clever and derive the potential output value range for normalization from the parameters of each module type, but that wouldn't be practical with the current implementation and maybe not at all.

I think transformations for whole noise maps could be quite interesting and useful. The current Noise{Map,Cube} / Builder / Model system might not be very well suited to it, though. It's a bit of a relic from the original late 90s-style C++ ...

As an aside, applying non-linear filters is already possible, for example with the Curve and Power modules. But those reach their limits when you need to take context into account, such as the actual value range in a noise map for normalization. So depending on your needs, going overboard with a whole new noise map transformation system, while potentially fun, might not be neccessary ;)

Anyway, if you decide to mess around and come up with something worth having, I would be happy to include it in the library and put it on NuGet.

rthome commented 3 years ago

Closed due to inactivity.