NoiseCombiner.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include <Noise.h>
  3. class NoiseCombinerM : public Noise
  4. {
  5. private:
  6. Noise* a;
  7. Noise* b;
  8. public:
  9. NoiseCombinerM(Noise* a, Noise* b)
  10. : Noise(),
  11. a(a),
  12. b(b)
  13. {}
  14. virtual int getSeed() const
  15. {
  16. return 0;
  17. }
  18. virtual double getNoise(double x, double y, double z)
  19. {
  20. return (((a->getNoise(x, y, z) - 0.5) * 2) * (b->getNoise(x, y, z)) * 0.9 + 0.1)
  21. / 2 + 0.5;
  22. }
  23. };
  24. class NoiseCombinerA : public Noise
  25. {
  26. private:
  27. Noise* a;
  28. Noise* b;
  29. public:
  30. NoiseCombinerA(Noise* a, Noise* b)
  31. : Noise(),
  32. a(a),
  33. b(b)
  34. {}
  35. virtual int getSeed() const
  36. {
  37. return 0;
  38. }
  39. virtual double getNoise(double x, double y, double z)
  40. {
  41. return a->getNoise(x, y, z)* 0.7 + b->getNoise(x, y, z) * 0.3;
  42. }
  43. };
  44. class RescaleNoise : public Noise
  45. {
  46. Noise* n;
  47. double factor;
  48. public:
  49. RescaleNoise(Noise* n, double factor)
  50. : Noise(),
  51. n(n),
  52. factor(factor)
  53. {}
  54. virtual int getSeed() const
  55. {
  56. return n->getSeed();
  57. }
  58. virtual double getNoise(double x, double y, double z)
  59. {
  60. return MAX(MIN(n->getNoise(x, y, z) * factor, 1.0), 0.0);
  61. }
  62. };
  63. class FlattenNoise : public Noise
  64. {
  65. Noise* n;
  66. double factor;
  67. double minValue;
  68. public:
  69. FlattenNoise(Noise* n, double factor, double minValue)
  70. : Noise(),
  71. n(n),
  72. factor(factor),
  73. minValue(minValue)
  74. {}
  75. virtual int getSeed() const
  76. {
  77. return n->getSeed();
  78. }
  79. virtual double getNoise(double x, double y, double z)
  80. {
  81. return MAX(0, MIN(1, (n->getNoise(x, y, z) - 0.5) * factor + 0.5 + minValue));
  82. }
  83. };
  84. class NegatedNoise : public Noise
  85. {
  86. Noise* n;
  87. public:
  88. NegatedNoise(Noise* n)
  89. : Noise(),
  90. n(n)
  91. {}
  92. virtual int getSeed() const override
  93. {
  94. return n->getSeed();
  95. }
  96. virtual double getNoise(double x, double y, double z) override
  97. {
  98. return 1 - n->getNoise(x, y, z);
  99. }
  100. };