Let's say I have a heightmap, but I want to create flat areas on it. The easiest solution would be to just say that every value between 0.2 and 0.4 should just become 0.3, but to keep the terrain continuous, I need to make sure that the values below 0.2 are mapped between 0 and 0.3 and the values above 0.4 get mapped between 0.3 and 1
So if we make a diagram, where the x axis is the value and the y is the outcome, then we get this:
This is fine when you have only 1 flat area, but if I'm trying to recreate something like a farmland in Peru, I have to create a lot of these:
So how can I create an efficient function, which given a value and an array containing the from and to values of the flattened areas transforms the value in the new system.
For instance, using the same example, a value of 0.25 would return 0.3 and a value of 0.5 would return 0.41666....