LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_perlin_noise.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_PERLIN_NOISE_H
7 #define LG_PERLIN_NOISE_H
8 
9 // === NOTE: FOLLOWING CODE IS COPYRIGHT(C) 2023 JORDAN PECK ===
10 
11 /*
12  * Fast Noise Lite
13  * Copyright(c) 2023 Jordan Peck ([email protected])
14  * Copyright(c) 2023 Contributors
15  * MIT License
16  */
17 
18 // Switch between using floats or doubles for input position
19 typedef float FNLfloat;
20 //typedef double FNLfloat;
21 
22 // Enums
23 typedef enum
24 {
25  FNL_NOISE_OPENSIMPLEX2,
26  FNL_NOISE_OPENSIMPLEX2S,
27  FNL_NOISE_CELLULAR,
28  FNL_NOISE_PERLIN,
29  FNL_NOISE_VALUE_CUBIC,
30  FNL_NOISE_VALUE
31 } fnl_noise_type;
32 
33 typedef enum
34 {
35  FNL_ROTATION_NONE,
36  FNL_ROTATION_IMPROVE_XY_PLANES,
37  FNL_ROTATION_IMPROVE_XZ_PLANES
38 } fnl_rotation_type_3d;
39 
40 typedef enum
41 {
42  FNL_FRACTAL_NONE,
43  FNL_FRACTAL_FBM,
44  FNL_FRACTAL_RIDGED,
45  FNL_FRACTAL_PINGPONG,
46  FNL_FRACTAL_DOMAIN_WARP_PROGRESSIVE,
47  FNL_FRACTAL_DOMAIN_WARP_INDEPENDENT
48 } fnl_fractal_type;
49 
50 typedef enum
51 {
52  FNL_CELLULAR_DISTANCE_EUCLIDEAN,
53  FNL_CELLULAR_DISTANCE_EUCLIDEANSQ,
54  FNL_CELLULAR_DISTANCE_MANHATTAN,
55  FNL_CELLULAR_DISTANCE_HYBRID
56 } fnl_cellular_distance_func;
57 
58 typedef enum
59 {
60  FNL_CELLULAR_RETURN_TYPE_CELLVALUE,
61  FNL_CELLULAR_RETURN_TYPE_DISTANCE,
62  FNL_CELLULAR_RETURN_TYPE_DISTANCE2,
63  FNL_CELLULAR_RETURN_TYPE_DISTANCE2ADD,
64  FNL_CELLULAR_RETURN_TYPE_DISTANCE2SUB,
65  FNL_CELLULAR_RETURN_TYPE_DISTANCE2MUL,
66  FNL_CELLULAR_RETURN_TYPE_DISTANCE2DIV,
67 } fnl_cellular_return_type;
68 
69 typedef enum
70 {
71  FNL_DOMAIN_WARP_OPENSIMPLEX2,
72  FNL_DOMAIN_WARP_OPENSIMPLEX2_REDUCED,
73  FNL_DOMAIN_WARP_BASICGRID
74 } fnl_domain_warp_type;
75 
80 typedef struct fnl_state
81 {
86  int seed;
87 
92  float frequency;
93 
98  fnl_noise_type noise_type;
99 
104  fnl_rotation_type_3d rotation_type_3d;
105 
111  fnl_fractal_type fractal_type;
112 
117  int octaves;
118 
123  float lacunarity;
124 
129  float gain;
130 
137 
143 
148  fnl_cellular_distance_func cellular_distance_func;
149 
154  fnl_cellular_return_type cellular_return_type;
155 
162 
167  fnl_domain_warp_type domain_warp_type;
168 
174 } fnl_state;
175 
177 
178 float fnlGetNoise2D(fnl_state *, FNLfloat, FNLfloat);
179 
180 float fnlGetNoise3D(fnl_state *, FNLfloat, FNLfloat, FNLfloat);
181 
182 void fnlDomainWarp2D(fnl_state *, FNLfloat *, FNLfloat *);
183 
184 void fnlDomainWarp3D(fnl_state *, FNLfloat *, FNLfloat *, FNLfloat *);
185 
186 #endif /* LG_PERLIN_NOISE_H */
fnl_state::cellular_return_type
fnl_cellular_return_type cellular_return_type
Definition: lg_perlin_noise.h:154
fnl_state::ping_pong_strength
float ping_pong_strength
Definition: lg_perlin_noise.h:142
fnl_state::rotation_type_3d
fnl_rotation_type_3d rotation_type_3d
Definition: lg_perlin_noise.h:104
fnl_state::domain_warp_amp
float domain_warp_amp
Definition: lg_perlin_noise.h:173
fnl_state::weighted_strength
float weighted_strength
Definition: lg_perlin_noise.h:136
fnl_state::octaves
int octaves
Definition: lg_perlin_noise.h:117
fnl_state::gain
float gain
Definition: lg_perlin_noise.h:129
fnl_state::lacunarity
float lacunarity
Definition: lg_perlin_noise.h:123
fnlDomainWarp2D
void fnlDomainWarp2D(fnl_state *state, FNLfloat *x, FNLfloat *y)
Definition: lg_perlin_noise.c:2121
fnl_state::noise_type
fnl_noise_type noise_type
Definition: lg_perlin_noise.h:98
fnl_state::domain_warp_type
fnl_domain_warp_type domain_warp_type
Definition: lg_perlin_noise.h:167
fnl_state::frequency
float frequency
Definition: lg_perlin_noise.h:92
fnlGetNoise3D
float fnlGetNoise3D(fnl_state *state, FNLfloat x, FNLfloat y, FNLfloat z)
Definition: lg_perlin_noise.c:2104
fnlDomainWarp3D
void fnlDomainWarp3D(fnl_state *state, FNLfloat *x, FNLfloat *y, FNLfloat *z)
Definition: lg_perlin_noise.c:2136
fnl_state::cellular_jitter_mod
float cellular_jitter_mod
Definition: lg_perlin_noise.h:161
fnlGetNoise2D
float fnlGetNoise2D(fnl_state *state, FNLfloat x, FNLfloat y)
Definition: lg_perlin_noise.c:2088
fnl_state::fractal_type
fnl_fractal_type fractal_type
Definition: lg_perlin_noise.h:111
fnlCreateState
fnl_state fnlCreateState()
Definition: lg_perlin_noise.c:2067
fnl_state::cellular_distance_func
fnl_cellular_distance_func cellular_distance_func
Definition: lg_perlin_noise.h:148
fnl_state
Definition: lg_perlin_noise.h:80
fnl_state::seed
int seed
Definition: lg_perlin_noise.h:86