1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
6 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
10 | * option) any later version. |
10 | * |
11 | * |
11 | * This program is distributed in the hope that it will be useful, |
12 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * GNU General Public License for more details. |
15 | * |
16 | * |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * You should have received a copy of the Affero GNU General Public License |
17 | * and the GNU General Public License along with this program. If not, see |
18 | * and the GNU General Public License along with this program. If not, see |
18 | * <http://www.gnu.org/licenses/>. |
19 | * <http://www.gnu.org/licenses/>. |
19 | * |
20 | * |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | */ |
22 | */ |
22 | |
23 | |
23 | #ifndef NOISE_H_ |
24 | #ifndef NOISE_H_ |
24 | #define NOISE_H_ |
25 | #define NOISE_H_ |
25 | |
26 | |
|
|
27 | #if 0 // blitz++0.09 |
|
|
28 | #include <string.h> // workaround for tinyvec using memcpy without including string.h |
|
|
29 | #include <cstdlib> // workaround for tinyvec using labs without including cstdlib |
26 | #include <blitz/tinyvec.h> |
30 | #include <blitz/tinyvec.h> |
27 | #include <blitz/tinyvec-et.h> |
31 | #include <blitz/tinyvec-et.h> |
28 | |
|
|
29 | #include "global.h" |
|
|
30 | |
|
|
31 | typedef blitz::TinyVector<float,2> vec2d; |
32 | typedef blitz::TinyVector<float,2> vec2d; |
32 | typedef blitz::TinyVector<float,3> vec3d; |
33 | typedef blitz::TinyVector<float,3> vec3d; |
|
|
34 | #else |
|
|
35 | |
|
|
36 | // blitz++ 0.10 - not working |
|
|
37 | #include <blitz/array.h> |
|
|
38 | #include <blitz/tinyvec2.h> |
|
|
39 | #include <blitz/tinyvec2.cc> |
|
|
40 | |
|
|
41 | template<typename T, int length> |
|
|
42 | struct vecnd |
|
|
43 | : blitz::TinyVector<T, length> |
|
|
44 | { |
|
|
45 | static const int numElements = length; |
|
|
46 | using blitz::TinyVector<T, length>::TinyVector; |
|
|
47 | }; |
|
|
48 | |
|
|
49 | typedef vecnd<float,2> vec2d; |
|
|
50 | typedef vecnd<float,3> vec3d; |
|
|
51 | |
|
|
52 | #endif |
|
|
53 | |
|
|
54 | #include "global.h" |
33 | |
55 | |
34 | vec2d |
56 | vec2d |
35 | inline floor (vec2d v) |
57 | inline floor (vec2d v) |
36 | { |
58 | { |
37 | return vec2d (fastfloor (v[0]), fastfloor (v[1])); |
59 | return vec2d (fastfloor (v[0]), fastfloor (v[1])); |
… | |
… | |
152 | { |
174 | { |
153 | T pmap[N]; |
175 | T pmap[N]; |
154 | |
176 | |
155 | void seed (seedable_rand_gen &rng); |
177 | void seed (seedable_rand_gen &rng); |
156 | |
178 | |
157 | T operator ()(T v) func_pure |
179 | ecb_pure T operator ()(T v) |
158 | { |
180 | { |
159 | return pmap[v & T(N - 1)]; |
181 | return pmap[v & T(N - 1)]; |
160 | } |
182 | } |
161 | }; |
183 | }; |
162 | |
184 | |
… | |
… | |
170 | typedef typename vec_t::T_numtype value_t; |
192 | typedef typename vec_t::T_numtype value_t; |
171 | |
193 | |
172 | void seed (seedable_rand_gen &rng); |
194 | void seed (seedable_rand_gen &rng); |
173 | void seed (seed_t seed); |
195 | void seed (seed_t seed); |
174 | |
196 | |
175 | value_t operator ()(vec_t P, uint32_t seed = 0) func_pure; |
197 | ecb_pure value_t operator ()(vec_t P, uint32_t seed = 0); |
176 | }; |
198 | }; |
177 | |
199 | |
178 | template<class vec_t> |
200 | template<class vec_t> |
179 | struct noise_gen; |
201 | struct noise_gen; |
180 | |
202 | |
… | |
… | |
193 | static vec3d::T_numtype abs_avg() { return 0.415; } // avg(abs(noise)) |
215 | static vec3d::T_numtype abs_avg() { return 0.415; } // avg(abs(noise)) |
194 | |
216 | |
195 | using noise_gen_base<vec3d>::operator (); |
217 | using noise_gen_base<vec3d>::operator (); |
196 | |
218 | |
197 | // noise projected on a surface with normal n |
219 | // noise projected on a surface with normal n |
198 | vec2d::T_numtype operator() (vec3d P, vec3d N, uint32_t seed = 0) func_pure; |
220 | ecb_pure vec2d::T_numtype operator() (vec3d P, vec3d N, uint32_t seed = 0); |
199 | }; |
221 | }; |
200 | |
222 | |
201 | typedef noise_gen<vec2d> noise2d; |
223 | typedef noise_gen<vec2d> noise2d; |
202 | typedef noise_gen<vec3d> noise3d; |
224 | typedef noise_gen<vec3d> noise3d; |
203 | |
225 | |
… | |
… | |
216 | value_t fbm_mul[MAX_OCTAVES]; |
238 | value_t fbm_mul[MAX_OCTAVES]; |
217 | rotate_xy<vec_t> rot[MAX_OCTAVES]; |
239 | rotate_xy<vec_t> rot[MAX_OCTAVES]; |
218 | |
240 | |
219 | frac_gen (int octaves = 3, value_t lacunarity = 2, value_t hurst_expo = .5, uint32_t seed = 0); |
241 | frac_gen (int octaves = 3, value_t lacunarity = 2, value_t hurst_expo = .5, uint32_t seed = 0); |
220 | |
242 | |
221 | value_t noise (vec_t P, uint32_t seed = 0) func_pure |
243 | ecb_pure value_t noise (vec_t P, uint32_t seed = 0) |
222 | { |
244 | { |
223 | return operator() (P, seed); |
245 | return this->operator() (P, seed); |
224 | } |
246 | } |
225 | |
247 | |
226 | value_t fBm (vec_t P) func_pure; |
248 | ecb_pure value_t fBm (vec_t P); |
227 | value_t turbulence (vec_t P) func_pure; |
249 | ecb_pure value_t turbulence (vec_t P); |
228 | value_t multifractal (vec_t P, value_t offset = 1) func_pure; |
250 | ecb_pure value_t multifractal (vec_t P, value_t offset = 1); |
229 | value_t heterofractal (vec_t P, value_t offset = 1) func_pure; |
251 | ecb_pure value_t heterofractal (vec_t P, value_t offset = 1); |
230 | value_t hybridfractal (vec_t P, value_t offset = 1, value_t gain = 1) func_pure; |
252 | ecb_pure value_t hybridfractal (vec_t P, value_t offset = 1, value_t gain = 1); |
231 | value_t ridgedmultifractal (vec_t P, value_t offset = 1, value_t gain = 8) func_pure; |
253 | ecb_pure value_t ridgedmultifractal (vec_t P, value_t offset = 1, value_t gain = 8); |
232 | value_t billowfractal (vec_t P, value_t offset = 1, value_t gain = 2) func_pure; |
254 | ecb_pure value_t billowfractal (vec_t P, value_t offset = 1, value_t gain = 2); |
233 | value_t terrain (vec_t P) func_pure; |
255 | ecb_pure value_t terrain (vec_t P); |
234 | value_t terrain2 (vec_t P) func_pure; |
256 | ecb_pure value_t terrain2 (vec_t P); |
235 | }; |
257 | }; |
236 | |
258 | |
237 | typedef frac_gen<vec2d> frac2d; |
259 | typedef frac_gen<vec2d> frac2d; |
238 | typedef frac_gen<vec3d> frac3d; |
260 | typedef frac_gen<vec3d> frac3d; |
239 | |
261 | |
240 | ///////////////////////////////////////////////////////////////////////////// |
262 | ///////////////////////////////////////////////////////////////////////////// |
241 | |
263 | |
242 | template<typename T, typename U> |
264 | template<typename T, typename U> |
243 | T |
265 | inline T |
244 | inline border_blend (T a, T b, vec2d P, U N, U W) |
266 | border_blend (T a, T b, vec2d P, U N, U W) |
245 | { |
267 | { |
246 | U border = W; // within n places of the border |
268 | U border = W; // within n places of the border |
247 | |
269 | |
248 | min_it (border, P [0]); |
270 | min_it (border, P [0]); |
249 | min_it (border, N - P [0]); |
271 | min_it (border, N - P [0]); |
250 | min_it (border, P [1]); |
272 | min_it (border, P [1]); |
251 | min_it (border, N - P [1]); |
273 | min_it (border, N - P [1]); |
252 | |
274 | |
253 | return blend (a, b,border, U(0), W); |
275 | return blend (a, b, border, U(0), W); |
254 | } |
276 | } |
255 | |
277 | |
256 | #endif |
278 | #endif |
257 | |
279 | |