@@ -9,17 +9,19 @@ public class HeightMapLayerGenerator : WorldMapLayerGenerator
99 {
1010 public enum MapType
1111 {
12- Noise ,
12+ ValueNoise ,
13+ SimplexNoise ,
14+ PerlinNoise ,
1315 Falloff ,
14- NoiseWithFalloff
16+ SimplexNoiseWithFalloff ,
17+ PerlinNoiseWithFalloff ,
18+ ValueNoiseWithFalloff
1519 }
1620
1721 [ SerializeField ] private bool step = false ;
1822
1923 [ SerializeField ] private int stepCount = 10 ;
2024
21- [ SerializeField ] private Vector2 offset = Vector2 . zero ;
22-
2325 [ FormerlySerializedAs ( "noiseScale" ) ] [ SerializeField ] private float frequency = 1 ;
2426
2527 [ SerializeField ] private int octaves = 4 ;
@@ -32,42 +34,61 @@ public enum MapType
3234
3335 [ SerializeField ] private float falloffB = 2.2f ;
3436
35- [ SerializeField ] private MapType mapType = MapType . Noise ;
37+ [ SerializeField ] private Vector2 falloffOffset = Vector2 . zero ;
38+
39+ [ SerializeField ] private MapType mapType = MapType . SimplexNoise ;
3640
3741 public HeightMapLayerData Generate ( int width , int height , uint seed )
3842 {
39- float [ , ] noiseMap ;
40-
41- switch ( mapType )
43+ var heightMap = new float [ width * height ] ;
44+ for ( var y = 0 ; y < height ; y ++ )
4245 {
43- case MapType . Noise :
44- noiseMap = Noise . GenerateNoiseMap ( width , height , seed , offset , frequency , octaves ,
45- persistence , lacunarity ) ;
46- break ;
47- case MapType . Falloff :
48- noiseMap = Noise . GenerateFalloffMap ( width , height , falloffA , falloffB ) ;
49- break ;
50- case MapType . NoiseWithFalloff :
51- var falloffMap = Noise . GenerateFalloffMap ( width , height , falloffA , falloffB ) ;
52- noiseMap = Noise . GenerateNoiseMap ( width , height , seed , offset , frequency , octaves , persistence , lacunarity , falloffMap ) ;
53- break ;
54- default :
55- throw new ArgumentOutOfRangeException ( ) ;
56- }
57-
58- float [ ] heightMap = new float [ width * height ] ;
59- for ( int y = 0 ; y < height ; y ++ )
60- {
61- for ( int x = 0 ; x < width ; x ++ )
46+ for ( var x = 0 ; x < width ; x ++ )
6247 {
63- var val = noiseMap [ x , y ] ;
48+ var i = y * width + x ;
49+ switch ( mapType )
50+ {
51+ case MapType . ValueNoise :
52+ heightMap [ i ] = ValueNoise . Fractal2D ( x , y , ( uint ) seed , frequency , octaves , lacunarity , persistence ) ;
53+ break ;
54+ case MapType . PerlinNoise :
55+ heightMap [ i ] = PerlinGradientNoise . Fractal2D ( x , y , ( uint ) seed , frequency , octaves , lacunarity , persistence ) ;
56+ break ;
57+ case MapType . SimplexNoise :
58+ heightMap [ i ] = SimplexGradientNoise . FractalGradient2D ( x , y , ( uint ) seed , frequency , octaves , lacunarity , persistence ) . value ;
59+ break ;
60+ case MapType . Falloff :
61+ heightMap [ i ] = Noise . GenerateFalloffPoint ( x , y , width , height , falloffA , falloffB , falloffOffset ) ;
62+ break ;
63+ case MapType . SimplexNoiseWithFalloff :
64+ {
65+ var falloff = Noise . GenerateFalloffPoint ( x , y , width , height , falloffA , falloffB , falloffOffset ) ;
66+ heightMap [ i ] = SimplexGradientNoise . FractalGradient2D ( x , y , ( uint ) seed , frequency , octaves , lacunarity , persistence ) . value ;
67+ heightMap [ i ] *= falloff ;
68+ }
69+ break ;
70+ case MapType . PerlinNoiseWithFalloff :
71+ {
72+ var falloff = Noise . GenerateFalloffPoint ( x , y , width , height , falloffA , falloffB , falloffOffset ) ;
73+ heightMap [ i ] = PerlinGradientNoise . Fractal2D ( x , y , ( uint ) seed , frequency , octaves , lacunarity , persistence ) ;
74+ heightMap [ i ] *= falloff ;
75+ }
76+ break ;
77+ case MapType . ValueNoiseWithFalloff :
78+ {
79+ var falloff = Noise . GenerateFalloffPoint ( x , y , width , height , falloffA , falloffB , falloffOffset ) ;
80+ heightMap [ i ] = ValueNoise . Fractal2D ( x , y , ( uint ) seed , frequency , octaves , lacunarity , persistence ) ;
81+ heightMap [ i ] *= falloff ;
82+ }
83+ break ;
84+ default :
85+ throw new ArgumentOutOfRangeException ( ) ;
86+ }
6487
6588 if ( step )
6689 {
67- val = Mathf . RoundToInt ( val * stepCount ) / ( float ) stepCount ;
90+ heightMap [ i ] = Mathf . RoundToInt ( heightMap [ i ] * stepCount ) / ( float ) stepCount ;
6891 }
69-
70- heightMap [ y * width + x ] = val ;
7192 }
7293 }
7394
0 commit comments