@@ -7,109 +7,18 @@ use noise::{
77pub fn height ( seed : u32 ) -> impl NoiseFn < f64 , 2 > {
88 /// Frequency of the planet's continents. Higher frequency produces
99 /// smaller, more numerous continents. This value is measured in radians.
10- const CONTINENT_FREQUENCY : f64 = 1.0 ;
10+ const CONTINENT_FREQUENCY : f64 = 0.125 / 8. ;
1111
1212 /// Lacunarity of the planet's continents. Changing this value produces
1313 /// slightly different continents. For the best results, this value should
1414 /// be random, but close to 2.0.
1515 const CONTINENT_LACUNARITY : f64 = 2.208984375 ;
1616
17- /// Lacunarity of the planet's mountains. Changing the value produces
18- /// slightly different mountains. For the best results, this value should
19- /// be random, but close to 2.0.
20- const MOUNTAIN_LACUNARITY : f64 = 2.142578125 ;
21-
22- /// Lacunarity of the planet's hills. Changing this value produces
23- /// slightly different hills. For the best results, this value should be
24- /// random, but close to 2.0.
25- const HILLS_LACUNARITY : f64 = 2.162109375 ;
26-
27- /// Lacunarity of the planet's plains. Changing this value produces
28- /// slightly different plains. For the best results, this value should be
29- /// random, but close to 2.0.
30- const PLAINS_LACUNARITY : f64 = 2.314453125 ;
31-
32- /// Lacunarity of the planet's badlands. Changing this value produces
33- /// slightly different badlands. For the best results, this value should
34- /// be random, but close to 2.0.
35- const BADLANDS_LACUNARITY : f64 = 2.212890625 ;
36-
37- /// Specifies the "twistiness" of the mountains.
38- const MOUNTAINS_TWIST : f64 = 1.0 ;
39-
40- /// Specifies the "twistiness" of the hills.
41- const HILLS_TWIST : f64 = 1.0 ;
42-
43- /// Specifies the "twistiness" of the badlands.
44- const BADLANDS_TWIST : f64 = 1.0 ;
45-
4617 /// Specifies the planet's sea level. This value must be between -1.0
4718 /// (minimum planet elevation) and +1.0 (maximum planet elevation).
4819 const SEA_LEVEL : f64 = 0.0 ;
4920
50- /// Specifies the level on the planet in which continental shelves appear.
51- /// This value must be between -1.0 (minimum planet elevation) and +1.0
52- /// (maximum planet elevation), and must be less than `SEA_LEVEL`.
53- const SHELF_LEVEL : f64 = -0.375 ;
54-
55- /// Determines the amount of mountainous terrain that appears on the
56- /// planet. Values range from 0.0 (no mountains) to 1.0 (all terrain is
57- /// covered in mountains). Mountains terrain will overlap hilly terrain.
58- /// Because the badlands terrain may overlap parts of the mountainous
59- /// terrain, setting `MOUNTAINS_AMOUNT` to 1.0 may not completely cover the
60- /// terrain in mountains.
61- const MOUNTAINS_AMOUNT : f64 = 0.5 ;
62-
63- /// Determines the amount of hilly terrain that appears on the planet.
64- /// Values range from 0.0 (no hills) to 1.0 (all terrain is covered in
65- /// hills). This value must be less than `MOUNTAINS_AMOUNT`. Because the
66- /// mountains terrain will overlap parts of the hilly terrain, and the
67- /// badlands terrain may overlap parts of the hilly terrain, setting
68- /// `HILLS_AMOUNT` to 1.0 may not completely cover the terrain in hills.
69- const HILLS_AMOUNT : f64 = ( 1.0 + MOUNTAINS_AMOUNT ) / 2.0 ;
70-
71- /// Determines the amount of badlands terrain that covers the planet.
72- /// Values range from 0.0 (no badlands) to 1.0 (all terrain is covered in
73- /// badlands). Badlands terrain will overlap any other type of terrain.
74- const BADLANDS_AMOUNT : f64 = 0.3125 ;
75-
76- /// Offset to apply to the terrain type definition. Low values (< 1.0)
77- /// cause the rough areas to appear only at high elevations. High values
78- /// (> 2.0) cause the rough areas to appear at any elevation. The
79- /// percentage of rough areas on the planet are independent of this value.
80- const TERRAIN_OFFSET : f64 = 1.0 ;
81-
82- /// Specifies the amount of "glaciation" on the mountains. This value
83- /// should be close to 1.0 and greater than 1.0.
84- const MOUNTAIN_GLACIATION : f64 = 1.375 ;
85-
86- /// Scaling to apply to the base continent elevations, in planetary
87- /// elevation units.
88- const CONTINENT_HEIGHT_SCALE : f64 = ( 1.0 - SEA_LEVEL ) / 4.0 ;
89-
90- /// Maximum depth of the rivers, in planetary elevation units.
91- const RIVER_DEPTH : f64 = 0.0234375 ;
92-
93- // ////////////////////////////////////////////////////////////////////////
94- // Function group: continent definition
95- // ////////////////////////////////////////////////////////////////////////
96-
97- // ////////////////////////////////////////////////////////////////////////
98- // Function subgroup: base continent definition (7 noise functions)
99- //
100- // This subgroup roughly defines the positions and base elevations of the
101- // planet's continents.
102- //
103- // The "base elevation" is the elevation of the terrain before any terrain
104- // features (mountains, hills, etc.) are placed on that terrain.
105- //
106- // -1.0 represents the lowest elevations and +1.0 represents the highest
107- // elevations.
108- //
10921 fn base_continent_def ( seed : u32 ) -> impl NoiseFn < f64 , 2 > {
110- // 1: [Continent module]: This FBM module generates the continents. This
111- // noise function has a high number of octaves so that detail is visible at
112- // high zoom levels.
11322 let base_continent_def_fb0 = Fbm :: < Perlin > :: new ( seed)
11423 . set_frequency ( CONTINENT_FREQUENCY )
11524 . set_persistence ( 0.5 )
@@ -172,24 +81,68 @@ pub fn height(seed: u32) -> impl NoiseFn<f64, 2> {
17281 base_continent_def
17382 }
17483
175- // 1: [Coarse-turbulence module]: This turbulence module warps the output
176- // value from the base-continent-definition subgroup, adding some coarse
177- // detail to it.
178- let continentDef_tu0 = Turbulence :: < _ , Perlin > :: new ( base_continent_def ( seed) )
179- . set_seed ( seed + 10 )
180- . set_frequency ( CONTINENT_FREQUENCY * 15.25 )
181- . set_power ( CONTINENT_FREQUENCY / 113.75 )
182- . set_roughness ( 13 ) ;
183-
184- // 2: [Intermediate-turbulence module]: This turbulence module warps the
185- // output value from the coarse-turbulence module. This turbulence has a
186- // higher frequency, but lower power, than the coarse-turbulence module,
187- // adding some intermediate detail to it.
188- let continentDef_tu1 = Turbulence :: < _ , Perlin > :: new ( continentDef_tu0)
189- . set_seed ( seed + 11 )
190- . set_frequency ( CONTINENT_FREQUENCY * 47.25 )
191- . set_power ( CONTINENT_FREQUENCY / 433.75 )
192- . set_roughness ( 12 ) ;
193-
194- continentDef_tu1
84+ fn continent_tu_def (
85+ seed : u32 ,
86+ ) -> Cache <
87+ Select <
88+ f64 ,
89+ impl NoiseFn < f64 , 2 > ,
90+ Turbulence < Turbulence < Turbulence < impl NoiseFn < f64 , 2 > , Perlin > , Perlin > , Perlin > ,
91+ impl NoiseFn < f64 , 2 > ,
92+ 2 ,
93+ > ,
94+ > {
95+ // 1: [Coarse-turbulence module]: This turbulence module warps the output
96+ // value from the base-continent-definition subgroup, adding some coarse
97+ // detail to it.
98+ let continent_def_tu0 = Turbulence :: < _ , Perlin > :: new ( base_continent_def ( seed) )
99+ . set_seed ( seed + 10 )
100+ . set_frequency ( CONTINENT_FREQUENCY * 15.25 )
101+ . set_power ( CONTINENT_FREQUENCY / 113.75 )
102+ . set_roughness ( 13 ) ;
103+
104+ // 2: [Intermediate-turbulence module]: This turbulence module warps the
105+ // output value from the coarse-turbulence module. This turbulence has a
106+ // higher frequency, but lower power, than the coarse-turbulence module,
107+ // adding some intermediate detail to it.
108+ let continent_def_tu1 = Turbulence :: < _ , Perlin > :: new ( continent_def_tu0)
109+ . set_seed ( seed + 11 )
110+ . set_frequency ( CONTINENT_FREQUENCY * 47.25 )
111+ . set_power ( CONTINENT_FREQUENCY / 433.75 )
112+ . set_roughness ( 12 ) ;
113+
114+ // 3: [Warped-base-continent-definition module]: This turbulence module
115+ // warps the output value from the intermediate-turbulence module. This
116+ // turbulence has a higher frequency, but lower power, than the
117+ // intermediate-turbulence module, adding some fine detail to it.
118+ let continent_def_tu2 = Turbulence :: < _ , Perlin > :: new ( continent_def_tu1)
119+ . set_seed ( seed + 12 )
120+ . set_frequency ( CONTINENT_FREQUENCY * 95.25 )
121+ . set_power ( CONTINENT_FREQUENCY / 1019.75 )
122+ . set_roughness ( 11 ) ;
123+
124+ // 4: [Select-turbulence module]: At this stage, the turbulence is applied
125+ // to the entire base-continent-definition subgroup, producing some very
126+ // rugged, unrealistic coastlines. This selector module selects the
127+ // output values from the (unwarped) base-continent-definition subgroup
128+ // and the warped-base-continent-definition module, based on the output
129+ // value from the (unwarped) base-continent-definition subgroup. The
130+ // selection boundary is near sea level and has a relatively smooth
131+ // transition. In effect, only the higher areas of the base-continent-
132+ // definition subgroup become warped; the underwater and coastal areas
133+ // remain unaffected.
134+ let continent_def_se = Select :: new (
135+ base_continent_def ( seed) ,
136+ continent_def_tu2,
137+ base_continent_def ( seed) ,
138+ )
139+ . set_bounds ( SEA_LEVEL - 0.0375 , SEA_LEVEL + 1000.0375 )
140+ . set_falloff ( 0.0625 ) ;
141+
142+ let continent_def = Cache :: new ( continent_def_se) ;
143+
144+ continent_def
145+ }
146+
147+ continent_tu_def ( seed)
195148}
0 commit comments