4

For example if my generated levels look roughly like this:

enter image description here

But once in a while I would like to have the "amplitude" rise say 10 times than the rest of the level, so that it would look something like:

enter image description here

That is, once in a while there are deep "trenches" in the level. Now I know that my terrain's Y values are always between for example 200 and 1000 pixels. I there a way for them to mostly be in that range, but once in a while there is a drop to for example 10000 pixels?

House
  • 73,224
  • 17
  • 184
  • 273

1 Answers1

9

Add another layer of noise to control the amplitude. Scale the noise up (on the X axis) to make the changes in amplitude gradual. Further, you can apply the amplitude changes in a exponential fashion. By applying them in this way, the difference in the noise values of .3 to .4 are not nearly as significant as the difference in the values .9 to 1. This strategy ensures that you do get some deep trenches, but you don't get them frequently.

Note that this method can easily be applied to also cause high mountains if desired.

House
  • 73,224
  • 17
  • 184
  • 273
  • That sounds like a good solution. Just to clarify, what exactly do you mean when you say "add another layer of noise"? Another noise function that controls the amplitude of the original one? – radioprotector Sep 02 '13 at 20:55
  • 1
    Correct. The new layer sits above the current noise and its output feeds into the input of your existing noise algorithm, supplying the amplitude. – House Sep 02 '13 at 21:00
  • Agreed! A single Noise field is almost never used alone because it's nothing more than a mildly grumpy sampling over space. You get the most interesting results by using one noise source to modify another, just like @Byte56 is talking about. – Patrick Hughes Sep 02 '13 at 22:22
  • I tried the method @Byte56 proposed. Not sure if I did it correctly. Now I get my Y coordinates by taking my original noise function (which is scaled) and raising it to the power of another noise function, which is not scaled. It kind of works, but I get quite steep trenches that are not really wide (reason why they are steep I guess), while the rest of the terrain doesn't vary too much. – radioprotector Sep 02 '13 at 22:39
  • 1
    Nearly there. Scale the amplitude noise along the X axis to make the transitions more gradual. I should have been a little more specific in my original description that I was talking about the X axis. You do this by scaling the inputs to this noise function down. – House Sep 02 '13 at 23:57
  • @Byte56 he should scale both x and y something like scalefac * perlin1D(x/scalefac) + perlin1D(x). Also, if only "once in a while" is a requirement you can do scalefac * min(perlin1D(x/scalefac),cutoff) + perlin1D(x) – PeterT Sep 03 '13 at 00:07
  • @PeterT Right, scaling the input to stretch the noise, and scaling the output to change the amplitude. But I don't think they need to be the same scale value. I think the min function is a good idea, as it would just use regular noise until the scaled value was "strong" enough to start using the altered value. Probably a more predictable alternative to applying the changes exponentially. – House Sep 03 '13 at 00:20
  • I seem to be getting there, thanks for the help! Going to try different methods proposed here later. So far I noticed that the "trenches" are usually deeper than the most of the terrain, but not that much deeper. What would I adjust if I wanted the trenches to be for example from 10 to 50 times the "normal" amplitude? – radioprotector Sep 03 '13 at 00:38
  • What parts of the suggestion have you tried? Applying the amplitude exponentially could be a good way to do what you want. – House Sep 03 '13 at 00:51
  • Well here is what it looks like now. tilePosition.Y = (float)Math.Pow(Math.Abs(pNoise.GeneratePerlinNoise(noiseXValue)) * scale, Math.Abs(pNoise.GeneratePerlinNoise(noiseXValue * 0.5f))) * someOtherScaling; Not sure if that's right or by which amount I should scale things. I sometimes get negative values from my perlin noise function, that's why I'm using absolute values. Not sure if that's a problem. – radioprotector Sep 03 '13 at 02:05
  • 1
    Ramping up the power should increase the amplitude, making the trenches lower. At this point I think you have the functions you need, and it's just a tweaking the numbers game. I've found in situations like this, it's interesting to put sliders in your game and change these values on-the-fly. See part of this answer about mixing noise for some other options. – House Sep 03 '13 at 02:12