Perlin.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. // Taken from: https://github.com/nothings/stb/blob/master/stb_perlin.h
  3. //
  4. // stb_perlin.h - v0.3 - perlin noise
  5. // public domain single-file C implementation by Sean Barrett
  6. //
  7. // LICENSE
  8. //
  9. // See cpp file.
  10. //
  11. // Contributors:
  12. // Jack Mott - additional noise functions
  13. //
  14. // float PerlinNoise3(float x,
  15. // float y,
  16. // float z,
  17. // int x_wrap = 0,
  18. // int y_wrap = 0,
  19. // int z_wrap = 0)
  20. //
  21. // This function computes a random value at the coordinate (x,y,z).
  22. // Adjacent random values are continuous but the noise fluctuates
  23. // its randomness with period 1, i.e. takes on wholly unrelated values
  24. // at integer points. Specifically, this implements Ken Perlin's
  25. // revised noise function from 2002.
  26. //
  27. // The "wrap" parameters can be used to create wraparound noise that
  28. // wraps at powers of two. The numbers MUST be powers of two. Specify
  29. // 0 to mean "don't care". (The noise always wraps every 256 due
  30. // details of the implementation, even if you ask for larger or no
  31. // wrapping.)
  32. //
  33. // Fractal Noise:
  34. //
  35. // Three common fractal noise functions are included, which produce
  36. // a wide variety of nice effects depending on the parameters
  37. // provided. Note that each function will call PerlinNoise3
  38. // 'octaves' times, so this parameter will affect runtime.
  39. //
  40. // float PerlinRidgeNoise3(float x, float y, float z,
  41. // float lacunarity, float gain, float offset, int octaves,
  42. // int x_wrap, int y_wrap, int z_wrap);
  43. //
  44. // float PerlinFBMNoise3(float x, float y, float z,
  45. // float lacunarity, float gain, int octaves,
  46. // int x_wrap, int y_wrap, int z_wrap);
  47. //
  48. // float PerlinTurbulenceNoise3(float x, float y, float z,
  49. // float lacunarity, float gain,int octaves,
  50. // int x_wrap, int y_wrap, int z_wrap);
  51. //
  52. // Typical values to start playing with:
  53. // octaves = 6 -- number of "octaves" of noise3() to sum
  54. // lacunarity = ~ 2.0 -- spacing between successive octaves (use exactly 2.0 for wrapping output)
  55. // gain = 0.5 -- relative weighting applied to each successive octave
  56. // offset = 1.0? -- used to invert the ridges, may need to be larger, not sure
  57. //
  58. float PerlinNoise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
  59. float PerlinRidgeNoise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves, int x_wrap, int y_wrap, int z_wrap);
  60. float PerlinFBMNoise3(float x, float y, float z, float lacunarity, float gain, int octaves,int x_wrap, int y_wrap, int z_wrap);
  61. float PerlinTurbulenceNoise3(float x, float y, float z, float lacunarity, float gain, int octaves, int x_wrap, int y_wrap, int z_wrap);