-
Notifications
You must be signed in to change notification settings - Fork 119
/
complexplanet.rs
1771 lines (1546 loc) · 81.9 KB
/
complexplanet.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
extern crate noise;
use noise::{core::worley::ReturnType, utils::*, *};
mod utils;
/// This example demonstrates how to use the noise-rs library to generate
/// terrain elevations for a complex planetary surface.
///
/// The terrain elevations are generated by a collection of over a hundred
/// noise functions in a hierarchy of groups and subgroups. Each group and
/// subgroup outputs a single output value that originates from a caching
/// module (`noise::modules::Cache`). Each group and subgroup can be thought of
/// as a single complex noise function that can be used as a source function for
/// other noise functions. The caching module was chosen as the source of the
/// output value to prevent costly recalculations by each group and subgroup
/// requesting an output value from it.
///
/// The following is a list of module groups and subgroups that build the
/// planet's terrain:
///
/// 1. Group (continent definition)
/// * Subgroup (base continent definition)
/// * Subgroup (continent definition)
/// 2. Group (terrain type definition)
/// * Subgroup (terrain type definition)
/// 3. Group (mountainous terrain)
/// * Subgroup (mountain base definition)
/// * Subgroup (high mountainous terrain)
/// * Subgroup (low mountainous terrain)
/// * Subgroup (mountainous terrain)
/// 4. Group (hilly terrain)
/// * Subgroup (hilly terrain)
/// 5. Group (plains terrain)
/// * Subgroup (plains terrain)
/// 6. Group (badlands terrain)
/// * Subgroup (badlands sand)
/// * Subgroup (badlands cliffs)
/// * Subgroup (badlands terrain)
/// 7. Group (river positions)
/// * Subgroup (river positions)
/// 8. Group (scaled mountainous terrain)
/// * Subgroup (scaled mountainous terrain)
/// 9. Group (scaled hilly terrain)
/// * Subgroup (scaled hilly terrain)
/// 10. Group (scaled plains terrain)
/// * Subgroup (scaled plains terrain)
/// 11. Group (scaled badlands terrain)
/// * Subgroup (scaled badlands terrain)
/// 12. Group (final planet)
/// * Subgroup (continental shelf)
/// * Subgroup (base continent elevation)
/// * Subgroup (continents with plains)
/// * Subgroup (continent with hills)
/// * Subgroup (continents with mountains)
/// * Subgroup (continents with badlands)
/// * Subgroup (continents with rivers)
/// * Subgroup (unscaled final planet)
/// * Subgroup (final planet)
///
/// A description for each group and subgroup can be found above the source
/// code for that group and subgroup.
#[allow(non_snake_case)]
fn main() {
/// Planet seed. Change this to generate a different planet.
const CURRENT_SEED: u32 = 0;
/// Frequency of the planet's continents. Higher frequency produces
/// smaller, more numerous continents. This value is measured in radians.
const CONTINENT_FREQUENCY: f64 = 1.0;
/// Lacunarity of the planet's continents. Changing this value produces
/// slightly different continents. For the best results, this value should
/// be random, but close to 2.0.
const CONTINENT_LACUNARITY: f64 = 2.208984375;
/// Lacunarity of the planet's mountains. Changing the value produces
/// slightly different mountains. For the best results, this value should
/// be random, but close to 2.0.
const MOUNTAIN_LACUNARITY: f64 = 2.142578125;
/// Lacunarity of the planet's hills. Changing this value produces
/// slightly different hills. For the best results, this value should be
/// random, but close to 2.0.
const HILLS_LACUNARITY: f64 = 2.162109375;
/// Lacunarity of the planet's plains. Changing this value produces
/// slightly different plains. For the best results, this value should be
/// random, but close to 2.0.
const PLAINS_LACUNARITY: f64 = 2.314453125;
/// Lacunarity of the planet's badlands. Changing this value produces
/// slightly different badlands. For the best results, this value should
/// be random, but close to 2.0.
const BADLANDS_LACUNARITY: f64 = 2.212890625;
/// Specifies the "twistiness" of the mountains.
const MOUNTAINS_TWIST: f64 = 1.0;
/// Specifies the "twistiness" of the hills.
const HILLS_TWIST: f64 = 1.0;
/// Specifies the "twistiness" of the badlands.
const BADLANDS_TWIST: f64 = 1.0;
/// Specifies the planet's sea level. This value must be between -1.0
/// (minimum planet elevation) and +1.0 (maximum planet elevation).
const SEA_LEVEL: f64 = 0.0;
/// Specifies the level on the planet in which continental shelves appear.
/// This value must be between -1.0 (minimum planet elevation) and +1.0
/// (maximum planet elevation), and must be less than `SEA_LEVEL`.
const SHELF_LEVEL: f64 = -0.375;
/// Determines the amount of mountainous terrain that appears on the
/// planet. Values range from 0.0 (no mountains) to 1.0 (all terrain is
/// covered in mountains). Mountains terrain will overlap hilly terrain.
/// Because the badlands terrain may overlap parts of the mountainous
/// terrain, setting `MOUNTAINS_AMOUNT` to 1.0 may not completely cover the
/// terrain in mountains.
const MOUNTAINS_AMOUNT: f64 = 0.5;
/// Determines the amount of hilly terrain that appears on the planet.
/// Values range from 0.0 (no hills) to 1.0 (all terrain is covered in
/// hills). This value must be less than `MOUNTAINS_AMOUNT`. Because the
/// mountains terrain will overlap parts of the hilly terrain, and the
/// badlands terrain may overlap parts of the hilly terrain, setting
/// `HILLS_AMOUNT` to 1.0 may not completely cover the terrain in hills.
const HILLS_AMOUNT: f64 = (1.0 + MOUNTAINS_AMOUNT) / 2.0;
/// Determines the amount of badlands terrain that covers the planet.
/// Values range from 0.0 (no badlands) to 1.0 (all terrain is covered in
/// badlands). Badlands terrain will overlap any other type of terrain.
const BADLANDS_AMOUNT: f64 = 0.3125;
/// Offset to apply to the terrain type definition. Low values (< 1.0)
/// cause the rough areas to appear only at high elevations. High values
/// (> 2.0) cause the rough areas to appear at any elevation. The
/// percentage of rough areas on the planet are independent of this value.
const TERRAIN_OFFSET: f64 = 1.0;
/// Specifies the amount of "glaciation" on the mountains. This value
/// should be close to 1.0 and greater than 1.0.
const MOUNTAIN_GLACIATION: f64 = 1.375;
/// Scaling to apply to the base continent elevations, in planetary
/// elevation units.
const CONTINENT_HEIGHT_SCALE: f64 = (1.0 - SEA_LEVEL) / 4.0;
/// Maximum depth of the rivers, in planetary elevation units.
const RIVER_DEPTH: f64 = 0.0234375;
// ////////////////////////////////////////////////////////////////////////
// Function group: continent definition
// ////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: base continent definition (7 noise functions)
//
// This subgroup roughly defines the positions and base elevations of the
// planet's continents.
//
// The "base elevation" is the elevation of the terrain before any terrain
// features (mountains, hills, etc.) are placed on that terrain.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
fn baseContinentDef() -> impl NoiseFn<f64, 3> {
// 1: [Continent module]: This FBM module generates the continents. This
// noise function has a high number of octaves so that detail is visible at
// high zoom levels.
let baseContinentDef_fb0 = Fbm::<Perlin>::new(CURRENT_SEED)
.set_frequency(CONTINENT_FREQUENCY)
.set_persistence(0.5)
.set_lacunarity(CONTINENT_LACUNARITY)
.set_octaves(14);
// debug::render_noise_module("complexplanet_images/00_0_baseContinentDef_fb0\
// .png",
// &baseContinentDef_fb0,
// 1024,
// 1024,
// 100);
// 2: [Continent-with-ranges module]: Next, a curve module modifies the
// output value from the continent module so that very high values appear
// near sea level. This defines the positions of the mountain ranges.
let baseContinentDef_cu = Curve::new(baseContinentDef_fb0)
.add_control_point(-2.0000 + SEA_LEVEL, -1.625 + SEA_LEVEL)
.add_control_point(-1.0000 + SEA_LEVEL, -1.375 + SEA_LEVEL)
.add_control_point(0.0000 + SEA_LEVEL, -0.375 + SEA_LEVEL)
.add_control_point(0.0625 + SEA_LEVEL, 0.125 + SEA_LEVEL)
.add_control_point(0.1250 + SEA_LEVEL, 0.250 + SEA_LEVEL)
.add_control_point(0.2500 + SEA_LEVEL, 1.000 + SEA_LEVEL)
.add_control_point(0.5000 + SEA_LEVEL, 0.250 + SEA_LEVEL)
.add_control_point(0.7500 + SEA_LEVEL, 0.250 + SEA_LEVEL)
.add_control_point(1.0000 + SEA_LEVEL, 0.500 + SEA_LEVEL)
.add_control_point(2.0000 + SEA_LEVEL, 0.500 + SEA_LEVEL);
// debug::render_noise_module("complexplanet_images/00_1_baseContinentDef_cu\
// .png",
// &baseContinentDef_cu,
// 1024,
// 1024,
// 100);
// 3: [Carver module]: This higher-frequency BasicMulti module will be
// used by subsequent noise functions to carve out chunks from the
// mountain ranges within the continent-with-ranges module so that the
// mountain ranges will not be completely impassible.
let baseContinentDef_fb1 = Fbm::<Perlin>::new(CURRENT_SEED + 1)
.set_frequency(CONTINENT_FREQUENCY * 4.34375)
.set_persistence(0.5)
.set_lacunarity(CONTINENT_LACUNARITY)
.set_octaves(11);
// debug::render_noise_module("complexplanet_images/00_2_baseContinentDef_fb1\
// .png",
// &baseContinentDef_fb1,
// 1024,
// 1024,
// 100);
// 4: [Scaled-carver module]: This scale/bias module scales the output
// value from the carver module such that it is usually near 1.0. This
// is required for step 5.
let baseContinentDef_sb = ScaleBias::new(baseContinentDef_fb1)
.set_scale(0.375)
.set_bias(0.625);
// debug::render_noise_module("complexplanet_images/00_3_baseContinentDef_sb\
// .png",
// &baseContinentDef_sb,
// 1024,
// 1024,
// 100);
// 5: [Carved-continent module]: This minimum-value module carves out
// chunks from the continent-with-ranges module. it does this by ensuring
// that only the minimum of the output values from the scaled-carver
// module and the continent-with-ranges module contributes to the output
// value of this subgroup. Most of the time, the minimum value module will
// select the output value from the continent-with-ranges module since the
// output value from the scaled-carver is usually near 1.0. Occasionally,
// the output from the scaled-carver module will be less than the output
// value from the continent-with-ranges module, so in this case, the output
// value from the scaled-carver module is selected.
let baseContinentDef_mi = Min::new(baseContinentDef_sb, baseContinentDef_cu);
// debug::render_noise_module("complexplanet_images/00_4_baseContinentDef_mi\
// .png",
// &baseContinentDef_mi,
// 1024,
// 1024,
// 100);
// 6: [Clamped-continent module]: Finally, a clamp module modifies the
// carved continent module to ensure that the output value of this subgroup
// is between -1.0 and 1.0.
let baseContinentDef_cl = Clamp::new(baseContinentDef_mi).set_bounds(-1.0, 1.0);
// 7: [Base-continent-definition subgroup]: Caches the output value from
// the clamped-continent module.
let baseContinentDef = Cache::new(baseContinentDef_cl);
baseContinentDef
}
// debug::render_noise_module("complexplanet_images/00_5_baseContinentDef.png",
// &baseContinentDef,
// 1024,
// 1024,
// 100);
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: continent definition (5 noise functions)
//
// This subgroup warps the output value from the base-continent-definition
// subgroup, producing more realistic terrain.
//
// Warping the base continent definition produces lumpier terrain with
// cliffs and rifts.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Coarse-turbulence module]: This turbulence module warps the output
// value from the base-continent-definition subgroup, adding some coarse
// detail to it.
let continentDef_tu0 = Turbulence::<_, Perlin>::new(baseContinentDef())
.set_seed(CURRENT_SEED + 10)
.set_frequency(CONTINENT_FREQUENCY * 15.25)
.set_power(CONTINENT_FREQUENCY / 113.75)
.set_roughness(13);
// debug::render_noise_module("complexplanet_images/01_0_continentDef_tu0.png",
// &continentDef_tu0,
// 1024,
// 1024,
// 1000);
// 2: [Intermediate-turbulence module]: This turbulence module warps the
// output value from the coarse-turbulence module. This turbulence has a
// higher frequency, but lower power, than the coarse-turbulence module,
// adding some intermediate detail to it.
let continentDef_tu1 = Turbulence::<_, Perlin>::new(continentDef_tu0)
.set_seed(CURRENT_SEED + 11)
.set_frequency(CONTINENT_FREQUENCY * 47.25)
.set_power(CONTINENT_FREQUENCY / 433.75)
.set_roughness(12);
// debug::render_noise_module("complexplanet_images/01_1_continentDef_tu1.png",
// &continentDef_tu1,
// 1024,
// 1024,
// 1000);
// 3: [Warped-base-continent-definition module]: This turbulence module
// warps the output value from the intermediate-turbulence module. This
// turbulence has a higher frequency, but lower power, than the
// intermediate-turbulence module, adding some fine detail to it.
let continentDef_tu2 = Turbulence::<_, Perlin>::new(continentDef_tu1)
.set_seed(CURRENT_SEED + 12)
.set_frequency(CONTINENT_FREQUENCY * 95.25)
.set_power(CONTINENT_FREQUENCY / 1019.75)
.set_roughness(11);
// debug::render_noise_module("complexplanet_images/01_2_continentDef_tu2.png",
// &continentDef_tu2,
// 1024,
// 1024,
// 1000);
// 4: [Select-turbulence module]: At this stage, the turbulence is applied
// to the entire base-continent-definition subgroup, producing some very
// rugged, unrealistic coastlines. This selector module selects the
// output values from the (unwarped) base-continent-definition subgroup
// and the warped-base-continent-definition module, based on the output
// value from the (unwarped) base-continent-definition subgroup. The
// selection boundary is near sea level and has a relatively smooth
// transition. In effect, only the higher areas of the base-continent-
// definition subgroup become warped; the underwater and coastal areas
// remain unaffected.
let continentDef_se = Select::new(baseContinentDef(), continentDef_tu2, baseContinentDef())
.set_bounds(SEA_LEVEL - 0.0375, SEA_LEVEL + 1000.0375)
.set_falloff(0.0625);
// debug::render_noise_module("complexplanet_images/01_3_continentDef_se.png",
// &continentDef_se,
// 1024,
// 1024,
// 1000);
// 5: [Continent-definition group]: Caches the output value from the
// clamped-continent module. This is the output value for the entire
// continent-definition group.
let continentDef = Cache::new(continentDef_se);
// debug::render_noise_module("complexplanet_images/01_4_continentDef.png",
// &continentDef,
// 1024,
// 1024,
// 1000);
// ////////////////////////////////////////////////////////////////////////
// Function group: terrain type definition
// ////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: terrain type definition (3 noise functions)
//
// This subgroup defines the positions of the terrain types on the planet.
//
// Terrain types include, in order of increasing roughness, plains, hills,
// and mountains.
//
// This subgroup's output value is based on the output value from the
// continent-definition group. Rougher terrain mainly appears at higher
// elevations.
//
// -1.0 represents the smoothest terrain types (plains and underwater) and
// +1.0 represents the roughest terrain types (mountains).
//
// 1: [Warped-continent module]: This turbulence module slightly warps the
// output value from the continent-definition group. This prevents the
// rougher terrain from appearing exclusively at higher elevations. Rough
// areas may now appear in the the ocean, creating rocky islands and
// fjords.
let terrainTypeDef_tu = Turbulence::<_, Perlin>::new(&continentDef)
.set_seed(CURRENT_SEED + 20)
.set_frequency(CONTINENT_FREQUENCY * 18.125)
.set_power(CONTINENT_FREQUENCY / 20.59375 * TERRAIN_OFFSET)
.set_roughness(3);
// 2: [Roughness-probability-shift module]: This terracing module sharpens
// the edges of the warped-continent module near sea level and lowers the
// slope towards the higher-elevation areas. This shrinks the areas in
// which the rough terrain appears, increasing the "rarity" of rough
// terrain.
let terrainTypeDef_te = Terrace::new(terrainTypeDef_tu)
.add_control_point(-1.00)
.add_control_point(SHELF_LEVEL + SEA_LEVEL / 2.0)
.add_control_point(1.00);
// 3: [Terrain-type-definition group]: Caches the output value from the
// roughness-probability-shift module. This is the output value for the
// entire terrain-type-definition group.
let terrainTypeDef = Cache::new(terrainTypeDef_te);
// /////////////////////////////////////////////////////////////////////////
// Function group: mountainous terrain
// /////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////
// Function subgroup: mountain base definition (9 noise functions)
//
// This subgroup generates the base-mountain elevations. Other subgroups
// will add the ridges and low areas to the base elevations.
//
// -1.0 represents low mountainous terrain and +1.0 represents high
// mountainous terrain.
//
// 1: [Mountain-ridge module]: This ridged-multifractal-noise function
// generates the mountain ridges.
let mountainBaseDef_rm0 = RidgedMulti::<Perlin>::new(CURRENT_SEED + 30)
.set_frequency(1723.0)
.set_lacunarity(MOUNTAIN_LACUNARITY)
.set_octaves(4);
// 2: [Scaled-mountain-ridge module]: Next, a scale/bias module scales the
// output value from the mountain-ridge module so that its ridges are not
// too high. The reason for this is that another subgroup adds actual
// mountainous terrain to these ridges.
let mountainBaseDef_sb0 = ScaleBias::new(mountainBaseDef_rm0)
.set_scale(0.5)
.set_bias(0.375);
// 3: [River-valley module]: This ridged-multifractal-noise function
// generates the river valleys. It has a much lower frequency than the
// mountain-ridge module so that more mountain ridges will appear outside
// of the valleys. Note that this noise function generates ridged-multifractal
// noise using only one octave; this information will be important in the
// next step.
let mountainBaseDef_rm1 = RidgedMulti::<Perlin>::new(CURRENT_SEED + 31)
.set_frequency(367.0)
.set_lacunarity(MOUNTAIN_LACUNARITY)
.set_octaves(1);
// 4: [Scaled-river-valley module]: Next, a scale/bias module applies a
// scaling factor of -2.0 to the output value from the river-valley module.
// This stretches the possible elevation values because one-octave ridged-
// multifractal noise has a lower range of output values than multiple-
// octave ridged-multifractal noise. The negative scaling factor inverts
// the range of the output value, turning the ridges from the river-valley
// module into valleys.
let mountainBaseDef_sb1 = ScaleBias::new(mountainBaseDef_rm1)
.set_scale(-2.0)
.set_bias(-0.5);
// 5: [Low-flat module]: This low constant value is used by step 6.
let mountainBaseDef_co = Constant::new(-1.0);
// 6: [Mountains-and-valleys module]: This blender module merges the scaled-
// mountain-ridge module and the scaled-river-valley module together. It
// causes the low-lying areas of the terrain to become smooth, and causes
// the high-lying areas of the terrain to contain ridges. To do this, it
// uses the scaled-river-valley module as the control module, causing the
// low-flat module to appear in the lower areas and causing the scaled-
// mountain-ridge module to appear in the higher areas.
let mountainBaseDef_bl = Blend::new(
&mountainBaseDef_co,
&mountainBaseDef_sb0,
&mountainBaseDef_sb1,
);
// 7: [Coarse-turbulence module]: This turbulence module warps the output
// value from the mountain-and-valleys module, adding some coarse detail to
// it.
let mountainBaseDef_tu0 = Turbulence::<_, Perlin>::new(mountainBaseDef_bl)
.set_seed(CURRENT_SEED + 32)
.set_frequency(1337.0)
.set_power(1.0 / 6730.0 * MOUNTAINS_TWIST)
.set_roughness(4);
// 8: [Warped-mountains-and-valleys module]: This turbulence module warps
// the output value from the coarse-turbulence module. This turbulence has
// a higher frequency, but lower power, than the coarse-turbulence module,
// adding some fine detail to it.
let mountainBaseDef_tu1 = Turbulence::<_, Perlin>::new(mountainBaseDef_tu0)
.set_seed(CURRENT_SEED + 33)
.set_frequency(21221.0)
.set_power(1.0 / 120157.0 * MOUNTAINS_TWIST)
.set_roughness(6);
// 9: [Mountain-base-definition subgroup]: Caches the output value from the
// warped-mountains-and-valleys module.
let mountainBaseDef = Cache::new(mountainBaseDef_tu1);
// /////////////////////////////////////////////////////////////////////////
// Function subgroup: high mountainous terrain (5 noise functions)
//
// This subgroup generates the mountainous terrain that appears at high
// elevations within the mountain ridges.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Mountain-basis-0 module]: This ridged-multifractal-noise function,
// along with the mountain-basis-1 module, generates the individual
// mountains.
let mountainousHigh_rm0 = RidgedMulti::<Perlin>::new(CURRENT_SEED + 40)
.set_frequency(2371.0)
.set_lacunarity(MOUNTAIN_LACUNARITY)
.set_octaves(3);
// 2: [Mountain-basis-1 module]: This ridged-multifractal-noise function,
// along with the mountain-basis-0 module, generates the individual
// mountains.
let mountainousHigh_rm1 = RidgedMulti::<Perlin>::new(CURRENT_SEED + 41)
.set_frequency(2341.0)
.set_lacunarity(MOUNTAIN_LACUNARITY)
.set_octaves(3);
// 3: [High-mountains module]: Next, a maximum-value module causes more
// mountains to appear at the expense of valleys. It does this by ensuring
// that only the maximum of the output values from the two ridged-
// multifractal-noise functions contribute to the output value of this
// subgroup.
let mountainousHigh_ma = Max::new(mountainousHigh_rm0, mountainousHigh_rm1);
// 4: [Warped-high-mountains module]: This turbulence module warps the
// output value from the high-mountains module, adding some detail to it.
let mountainousHigh_tu = Turbulence::<_, Perlin>::new(mountainousHigh_ma)
.set_seed(CURRENT_SEED + 42)
.set_frequency(31511.0)
.set_power(1.0 / 180371.0 * MOUNTAINS_TWIST)
.set_roughness(4);
// 5: [High-mountainous-terrain subgroup]: Caches the output value from the
// warped-high-mountains module.
let mountainousHigh = Cache::new(mountainousHigh_tu);
// /////////////////////////////////////////////////////////////////////////
// Function subgroup: low mountainous terrain (4 noise functions)
//
// This subgroup generates the mountainous terrain that appears at low
// elevations within the river valleys.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Lowland-basis-0 module]: This ridged-multifractal-noise function,
// along with the lowland-basis-1 module, produces the low mountainous
// terrain.
let mountainousLow_rm0 = RidgedMulti::<Perlin>::new(CURRENT_SEED + 50)
.set_frequency(1381.0)
.set_lacunarity(MOUNTAIN_LACUNARITY)
.set_octaves(8);
// 1: [Lowland-basis-1 module]: This ridged-multifractal-noise function,
// along with the lowland-basis-0 module, produces the low mountainous
// terrain.
let mountainousLow_rm1 = RidgedMulti::<Perlin>::new(CURRENT_SEED + 51)
.set_frequency(1427.0)
.set_lacunarity(MOUNTAIN_LACUNARITY)
.set_octaves(8);
// 3: [Low-mountainous-terrain module]: This multiplication module combines
// the output values from the two ridged-multifractal-noise functions. This
// causes the following to appear in the resulting terrain:
// - Cracks appear when two negative output values are multiplied together.
// - Flat areas appear when a positive and a negative output value are
// multiplied together.
// - Ridges appear when two positive output values are multiplied together.
let mountainousLow_mu = Multiply::new(mountainousLow_rm0, mountainousLow_rm1);
// 4: [Low-mountainous-terrain subgroup]: Caches the output value from the
// low-mountainous-terrain module.
let mountainousLow = Cache::new(mountainousLow_mu);
// /////////////////////////////////////////////////////////////////////////
// Function subgroup: mountainous terrain (7 noise functions)
//
// This subgroup generates the final mountainous terrain by combining the
// high-mountainous-terrain subgroup with the low-mountainous-terrain
// subgroup.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Scaled-low-mountainous-terrain module]: First, this scale/bias module
// scales the output value from the low-mountainous-terrain subgroup to a very
// low value and biases it towards -1.0. This results in the low mountainous
// areas becoming more-or-less flat with little variation. This will also
// result in the low mountainous areas appearing at the lowest elevations in
// this subgroup.
let mountainousTerrain_sb0 = ScaleBias::new(mountainousLow)
.set_scale(0.03125)
.set_bias(-0.96875);
// 2: [Scaled-high-mountainous-terrain module]: Next, this scale/bias module
// scales the output value from the high-mountainous-terrain subgroup to 1/4
// of its initial value and biases it so that its output value is usually
// positive.
let mountainousTerrain_sb1 = ScaleBias::new(mountainousHigh)
.set_scale(0.25)
.set_bias(0.25);
// 3: [Added-high-mountainous-terrain module]: This addition module adds the
// output value from the scaled-high-mountainous-terrain module to the
// output value from the mountain-base-definition subgroup. Mountains now
// appear all over the terrain.
let mountainousTerrain_ad = Add::new(mountainousTerrain_sb1, &mountainBaseDef);
// 4: [Combined-mountainous-terrain module]: Note that at this point, the
// entire terrain is covered in high mountainous terrain, even at the low
// elevations. To make sure the mountains only appear at the higher
// elevations, this selector module causes low mountainous terrain to appear
// at the low elevations (within the valleys) and the high mountainous
// terrain to appear at the high elevations (within the ridges). To do this,
// this noise function selects the output value from the added-high-
// mountainous-terrain module if the output value from the mountain-base-
// definition subgroup is higher than a set amount. Otherwise, this noise
// module selects the output value from the scaled-low-mountainous-terrain
// module.
let mountainousTerrain_se = Select::new(
mountainousTerrain_sb0,
mountainousTerrain_ad,
&mountainBaseDef,
)
.set_bounds(-0.5, 999.5)
.set_falloff(0.5);
// 5: [Scaled-mountainous-terrain-module]: This scale/bias module slightly
// reduces the range of the output value from the combined-mountainous-
// terrain module, decreasing the heights of the mountain peaks.
let mountainousTerrain_sb2 = ScaleBias::new(mountainousTerrain_se)
.set_scale(0.8)
.set_bias(0.0);
// 6: [Glaciated-mountainous-terrain-module]: This exponential-curve module
// applies an exponential curve to the output value from the scaled-
// mountainous-terrain module. This causes the slope of the mountains to
// smoothly increase towards higher elevations, as if a glacier ground out
// those mountains. This exponential-curve module expects the output value
// to range from -1.0 to +1.0.
let mountainousTerrain_ex =
Exponent::new(mountainousTerrain_sb2).set_exponent(MOUNTAIN_GLACIATION);
let mountainousTerrain = Cache::new(mountainousTerrain_ex);
// ////////////////////////////////////////////////////////////////////////
// Function group: hilly terrain
// ////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: hilly terrain (11 noise functions)
//
// This subgroup generates the hilly terrain.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Hills module]: This billow-noise function generates the hills.
let hillyTerrain_bi = Billow::<Perlin>::new(CURRENT_SEED + 60)
.set_frequency(1663.0)
.set_persistence(0.5)
.set_lacunarity(HILLS_LACUNARITY)
.set_octaves(6);
// 2: [Scaled-hills module]: Next, a scale/bias module scales the output
// value from the hills module so that its hilltops are not too high. The
// reason for this is that these hills are eventually added to the river
// valleys (see below).
let hillyTerrain_sb0 = ScaleBias::new(hillyTerrain_bi).set_scale(0.5).set_bias(0.5);
// 3: [River-valley module]: This ridged-multifractal-noise function generates
// the river valleys. It has a much lower frequency so that more hills will
// appear in between the valleys. Note that this noise function generates
// ridged-multifractal noise using only one octave; this information will be
// important in the next step.
let hillyTerrain_rm = RidgedMulti::<Perlin>::new(CURRENT_SEED + 61)
.set_frequency(367.5)
.set_lacunarity(HILLS_LACUNARITY)
.set_octaves(1);
// 4: [Scaled-river-valley module]: Next, a scale/bias module applies a
// scaling factor of -2.0 to the output value from the river-valley module.
// This stretches the possible elevation values because one-octave ridged-
// multifractal noise has a lower range of output values than multiple-
// octave ridged-multifractal noise. The negative scaling factor inverts
// the range of the output value, turning the ridges from the river-valley
// module into valleys.
let hillyTerrain_sb1 = ScaleBias::new(hillyTerrain_rm)
.set_scale(-2.0)
.set_bias(-1.0);
// 5: [Low-flat module]: This low constant value is used by step 6.
let hillyTerrain_co = Constant::new(-1.0);
// 6: [Mountains-and-valleys module]: This blender module merges the scaled-
// hills module and the scaled-river-valley module together. It causes the
// low-lying areas of the terrain to become smooth, and causes the high-
// lying areas of the terrain to contain hills. To do this, it uses uses the
// scaled-hills module as the control module, causing the low-flat module to
// appear in the lower areas and causing the scaled-river-valley module to
// appear in the higher areas.
let hillyTerrain_bl = Blend::new(hillyTerrain_co, hillyTerrain_sb1, hillyTerrain_sb0);
// 7: [Scaled-hills-and-valleys module]: This scale/bias module slightly
// reduces the range of the output value from the hills-and-valleys
// module, decreasing the heights of the hilltops.
let hillyTerrain_sb2 = ScaleBias::new(hillyTerrain_bl)
.set_scale(0.75)
.set_bias(-0.25);
// 8: [Increased-slope-hilly-terrain module]: To increase the hill slopes
// at higher elevations, this exponential-curve module applies an
// exponential curve to the output value the scaled-hills-and-valleys
// module. This exponential-curve module expects the input value to range
// from -1.0 to 1.0.
let hillyTerrain_ex = Exponent::new(hillyTerrain_sb2).set_exponent(1.375);
// 9: [Coarse-turbulence module]: This turbulence module warps the output
// value from the increased-slope-hilly-terrain module, adding some
// coarse detail to it.
let hillyTerrain_tu0 = Turbulence::<_, Perlin>::new(hillyTerrain_ex)
.set_seed(CURRENT_SEED + 62)
.set_frequency(1531.0)
.set_power(1.0 / 16921.0 * HILLS_TWIST)
.set_roughness(4);
// 10: [Warped-hilly-terrain module]: This turbulence module warps the
// output value from the coarse-turbulence module. This turbulence has a
// higher frequency, but lower power, than the coarse-turbulence module,
// adding some fine detail to it.
let hillyTerrain_tu1 = Turbulence::<_, Perlin>::new(hillyTerrain_tu0)
.set_seed(CURRENT_SEED + 63)
.set_frequency(21617.0)
.set_power(1.0 / 117529.0 * HILLS_TWIST)
.set_roughness(6);
// 11: [Hilly-terrain group]: Caches the output value from the warped-hilly-
// terrain module. This is the output value for the entire hilly-terrain
// group.
let hillyTerrain = Cache::new(hillyTerrain_tu1);
// ////////////////////////////////////////////////////////////////////////
// Function group: plains terrain
// ////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: plains terrain (7 noise functions)
//
// This subgroup generates the plains terrain.
//
// Because this subgroup will eventually be flattened considerably, the
// types and combinations of noise functions that generate the plains are not
// really that important; they only need to "look" interesting.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Plains-basis-0 module]: This billow-noise function, along with the
// plains-basis-1 module, produces the plains.
let plainsTerrain_bi0 = Billow::<Perlin>::new(CURRENT_SEED + 70)
.set_frequency(1097.5)
.set_persistence(0.5)
.set_lacunarity(PLAINS_LACUNARITY)
.set_octaves(8);
// 2: [Positive-plains-basis-0 module]: This scale/bias module makes the
// output value from the plains-basis-0 module positive since this output
// value will be multiplied together with the positive-plains-basis-1
// module.
let plainsTerrain_sb0 = ScaleBias::new(plainsTerrain_bi0)
.set_scale(0.5)
.set_bias(0.5);
// 3: [Plains-basis-1 module]: This billow-noise function, along with the
// plains-basis-2 module, produces the plains.
let plainsTerrain_bi1 = Billow::<Perlin>::new(CURRENT_SEED + 71)
.set_frequency(1097.5)
.set_persistence(0.5)
.set_lacunarity(PLAINS_LACUNARITY)
.set_octaves(8);
// 4: [Positive-plains-basis-1 module]: This scale/bias module makes the
// output value from the plains-basis-1 module positive since this output
// value will be multiplied together with the positive-plains-basis-0
// module.
let plainsTerrain_sb1 = ScaleBias::new(plainsTerrain_bi1)
.set_scale(0.5)
.set_bias(0.5);
// 5: [Combined-plains-basis module]: This multiplication module combines
// the two plains basis modules together.
let plainsTerrain_mu = Multiply::new(plainsTerrain_sb0, plainsTerrain_sb1);
// 6: [Rescaled-plains-basis module]: This scale/bias module maps the output
// value that ranges from 0.0 to 1.0 back to a value that ranges from
// -1.0 to +1.0.
let plainsTerrain_sb2 = ScaleBias::new(plainsTerrain_mu)
.set_scale(2.0)
.set_bias(-1.0);
// 7: [Plains-terrain group]: Caches the output value from the rescaled-
// plains-basis module. This is the output value for the entire plains-
// terrain group.
let plainsTerrain = Cache::new(plainsTerrain_sb2);
// ////////////////////////////////////////////////////////////////////////
// Function group: badlands terrain
// ////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: badlands sand (6 noise functions)
//
// This subgroup generates the sandy terrain for the badlands.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Sand-dunes module]: This ridged-multifractal-noise function generates
// sand dunes. This ridged-multifractal noise is generated with a single
// octave, which makes very smooth dunes.
let badlandsSand_rm = RidgedMulti::<Perlin>::new(CURRENT_SEED + 80)
.set_frequency(6163.5)
.set_lacunarity(BADLANDS_LACUNARITY)
.set_octaves(1);
// 2: [Scaled-sand-dunes module]: This scale/bias module shrinks the dune
// heights by a small amount. This is necessary so that the subsequent
// noise functions in this subgroup can add some detail to the dunes.
let badlandsSand_sb0 = ScaleBias::new(badlandsSand_rm)
.set_scale(0.875)
.set_bias(0.0);
// 3: [Dune-detail module]: This noise function uses Voronoi polygons to
// generate the detail to add to the dunes. By enabling the distance
// algorithm, small polygonal pits are generated; the edges of the pits
// are joined to the edges of nearby pits.
let badlandsSand_wo = Worley::new(CURRENT_SEED + 81)
.set_frequency(16183.25)
.set_return_type(ReturnType::Distance);
// 4: [Scaled-dune-detail module]: This scale/bias module shrinks the dune
// details by a large amount. This is necessary so that the subsequent
// noise functions in this subgroup can add this detail to the sand-dunes
// module.
let badlandsSand_sb1 = ScaleBias::new(badlandsSand_wo)
.set_scale(0.25)
.set_bias(0.25);
// 5: [Dunes-with-detail module]: This addition module combines the scaled-
// sand-dunes module with the scaled-dune-detail module.
let badlandsSand_ad = Add::new(badlandsSand_sb0, badlandsSand_sb1);
// 6: [Badlands-sand subgroup]: Caches the output value from the dunes-with-
// detail module.
let badlandsSand = Cache::new(badlandsSand_ad);
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: badlands cliffs (7 noise functions)
//
// This subgroup generates the cliffs for the badlands.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Cliff-basis module]: This Perlin-noise function generates some coherent
// noise that will be used to generate the cliffs.
let badlandsCliffs_fb = Fbm::<Perlin>::new(CURRENT_SEED + 90)
.set_frequency(CONTINENT_FREQUENCY * 839.0)
.set_persistence(0.5)
.set_lacunarity(BADLANDS_LACUNARITY)
.set_octaves(6);
// 2: [Cliff-shaping module]: Next, this curve module applies a curve to
// the output value from the cliff-basis module. This curve is initially
// very shallow, but then its slope increases sharply. At the highest
// elevations, the curve becomes very flat again. This produces the
// stereotypical Utah-style desert cliffs.
let badlandsCliffs_cu = Curve::new(badlandsCliffs_fb)
.add_control_point(-2.000, -2.000)
.add_control_point(-1.000, -1.000)
.add_control_point(-0.000, -0.750)
.add_control_point(0.500, -0.250)
.add_control_point(0.625, 0.875)
.add_control_point(0.750, 1.000)
.add_control_point(2.000, 1.250);
// 3: [Clamped-cliffs module]: This clamping module makes the tops of the
// cliffs very flat by clamping the output value from the cliff-shaping
// module.
let badlandsCliffs_cl = Clamp::new(badlandsCliffs_cu).set_bounds(-999.125, 0.875);
// 4: [Terraced-cliffs module]: Next, this terracing module applies some
// terraces to the clamped-cliffs module in the lower elevations before the
// sharp cliff transition.
let badlandsCliffs_te = Terrace::new(badlandsCliffs_cl)
.add_control_point(-1.000)
.add_control_point(-0.875)
.add_control_point(-0.750)
.add_control_point(-0.500)
.add_control_point(0.000)
.add_control_point(1.000);
// 5: [Coarse-turbulence module]: This turbulence module warps the output
// value from the terraced-cliffs module, adding some coarse detail to it.
let badlandsCliffs_tu0 = Turbulence::<_, Perlin>::new(badlandsCliffs_te)
.set_seed(CURRENT_SEED + 91)
.set_frequency(16111.0)
.set_power(1.0 / 141539.0 * BADLANDS_TWIST)
.set_roughness(3);
// 6: [Warped-cliffs module]: This turbulence module warps the output value
// from the coarse-turbulence module. This turbulence has a higher
// frequency, but lower power, than the coarse-turbulence module, adding
// some fine detail to it.
let badlandsCliffs_tu1 = Turbulence::<_, Perlin>::new(badlandsCliffs_tu0)
.set_seed(CURRENT_SEED + 92)
.set_frequency(36107.0)
.set_power(1.0 / 211543.0 * BADLANDS_TWIST)
.set_roughness(3);
// 7: [Badlands-cliffs subgroup]: Caches the output value from the warped-
// cliffs module.
let badlandsCliffs = Cache::new(badlandsCliffs_tu1);
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: badlands terrain (3 noise functions)
//
// Generates the final badlands terrain.
//
// Using a scale/bias module, the badlands sand is flattened considerably,
// then the sand elevations are lowered to around -1.0. The maximum value
// from the flattened sand module and the cliff module contributes to the
// final elevation. This causes sand to appear at the low elevations since
// the sand is slightly higher than the cliff base.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Scaled-sand-dunes module]: This scale/bias module considerably
// flattens the output value from the badlands-sands subgroup and lowers
// this value to near -1.0.
let badlandsTerrain_sb = ScaleBias::new(badlandsSand).set_scale(0.25).set_bias(-0.75);
// 2: [Dunes-and-cliffs module]: This maximum-value module causes the dunes
// to appear in the low areas and the cliffs to appear in the high areas.
// It does this by selecting the maximum of the output values from the
// scaled-sand-dunes module and the badlands-cliffs subgroup.
let badlandsTerrain_ma = Max::new(badlandsCliffs, badlandsTerrain_sb);
// 3: [Badlands-terrain group]: Caches the output value from the dunes-and-
// cliffs module. This is the output value for the entire badlands-terrain
// group.
let badlandsTerrain = Cache::new(badlandsTerrain_ma);
// debug::render_noise_module("complexplanet_images/12_2_badlandsTerrain.png",
// &badlandsTerrain,
// 1024,
// 1024,
// 1000);
// ////////////////////////////////////////////////////////////////////////
// Function group: river positions
// ////////////////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////////
// Function subgroup: river positions (7 noise functions)
//
// This subgroup generates the river positions.
//
// -1.0 represents the lowest elevations and +1.0 represents the highest
// elevations.
//
// 1: [Large-river-basis module]: This ridged-multifractal-noise function
// creates the large, deep rivers.
let riverPositions_rm0 = RidgedMulti::<Perlin>::new(CURRENT_SEED + 100)
.set_frequency(18.75)
.set_lacunarity(CONTINENT_LACUNARITY)
.set_octaves(1);
// 2: [Large-river-curve module]: This curve module applies a curve to the
// output value from the large-river-basis module so that the ridges become