ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/noise.C
(Generate patch)

Comparing deliantra/server/common/noise.C (file contents):
Revision 1.8 by root, Tue Apr 26 03:18:06 2011 UTC vs.
Revision 1.23 by root, Sat Nov 17 23:40:00 2018 UTC

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#include "noise.h" 24#include "noise.h"
24 25
226}; 227};
227 228
228///////////////////////////////////////////////////////////////////////////// 229/////////////////////////////////////////////////////////////////////////////
229 230
230template<int N, typename T> 231template<int N, typename T>
231template<class random_generator>
232void 232void
233permutation<N,T>::seed (random_generator &rng) 233permutation<N,T>::seed (seedable_rand_gen &rng)
234{ 234{
235 for (int i = 0; i < N; ++i) 235 for (int i = 0; i < N; ++i)
236 pmap[i] = i; 236 pmap[i] = i;
237 237
238 // fisher-yates to randomly perturb 238 // fisher-yates to randomly perturb
242 242
243template class permutation<256, uint8_t>; 243template class permutation<256, uint8_t>;
244 244
245///////////////////////////////////////////////////////////////////////////// 245/////////////////////////////////////////////////////////////////////////////
246 246
247static vec2d 247template<class vec_t>
248floor (vec2d v) 248void
249noise_gen_base<vec_t>::seed (seedable_rand_gen &rng)
249{ 250{
250 return vec2d (std::floor (v[0]), std::floor (v[1])); 251 for (int i = 0; i < array_length (rvmap); ++i)
252 rvmap[i].seed (rng);
251} 253}
252 254
253static vec3d 255template<class vec_t>
254floor (vec3d v) 256void
255{ 257noise_gen_base<vec_t>::seed (seed_t seed)
256 return vec3d (std::floor (v[0]), std::floor (v[1]), std::floor (v[2]));
257}
258
259noise_gen<vec2d>::noise_gen (uint32_t seed)
260{ 258{
261 seedable_rand_gen rng (seed); 259 seedable_rand_gen rng (seed);
262 260
263 rvmap[0].seed (rng); 261 this->seed (rng);
264 rvmap[1].seed (rng);
265} 262}
266 263
264template<>
267vec2d::T_numtype 265vec2d::T_numtype
268noise_gen<vec2d>::operator() (vec2d P) 266noise_gen_base<vec2d>::operator() (vec2d P, uint32_t seed)
269{ 267{
270 vec2d I = floor (P); 268 vec2d I = floor (P);
271 vec2d F = P - I; 269 vec2d F = P - I;
272 270
273 float v = 0; 271 value_t v = 0;
272
273 seed *= 3039177861;
274 uint8_t i1 = uint8_t (I[1]) + (seed >> 16);
275 uint8_t i0 = uint8_t (I[0]) + (seed >> 8);
276
277 uint8_t h2 = rvmap[2](seed);
274 278
275 for (int j = -1; j <= 2; ++j) 279 for (int j = -1; j <= 2; ++j)
280 {
281 uint8_t h1 = rvmap[1](i1 + j) ^ h2;
282
276 for (int i = -1; i <= 2; ++i) 283 for (int i = -1; i <= 2; ++i)
277 { 284 {
278 vec2d A = F - vec2d (i, j); 285 vec2d A = F - vec2d (i, j);
279
280 float d = dot (A, A); 286 value_t d = dot (A, A);
281 287
282 if (d < 4) 288 if (d < 4)
283 { 289 {
284 float t1 = 1 - d / 4; 290 value_t t1 = 1 - d / 4;
285 float t2 = t1 * t1; 291 value_t t2 = t1 * t1;
286 float t4 = t2 * t2; 292 value_t t4 = t2 * t2;
287 293
288 float p = (4 * t1 - 3) * t4; 294 value_t p = (4 * t1 - 3) * t4;
289 295
290 int h = rvmap[0](I[0] + i) ^ rvmap[1](I[1] + j); 296 uint8_t h = rvmap[0](i0 + i) ^ h1;
291 vec2d G = charges2[h & 0xff]; 297 vec2d G = charges2[h & 0xff];
292 298
293 v += dot (A, G) * p; 299 v += dot (A, G) * p;
294 } 300 }
295 } 301 }
302 }
296 303
297 return clamp (v, -.9999999, .9999999); 304 return v;
298} 305}
299 306
300///////////////////////////////////////////////////////////////////////////// 307/////////////////////////////////////////////////////////////////////////////
301 308
302noise_gen<vec3d>::noise_gen (uint32_t seed) 309template<>
303{
304 seedable_rand_gen rng (seed);
305
306 rvmap [0].seed (rng);
307 rvmap [1].seed (rng);
308 rvmap [2].seed (rng);
309}
310
311vec3d::T_numtype 310vec3d::T_numtype
312noise_gen<vec3d>::operator() (vec3d P) 311noise_gen_base<vec3d>::operator() (vec3d P, uint32_t seed)
313{ 312{
314 vec3d I = floor (P); 313 vec3d I = floor (P);
315 vec3d F = P - I; 314 vec3d F = P - I;
316 315
317 float v = 0; 316 seed *= 3039177861;
317 uint8_t i2 = uint8_t (I[2]) + (seed >> 24);
318 uint8_t i1 = uint8_t (I[1]) + (seed >> 16);
319 uint8_t i0 = uint8_t (I[0]) + (seed >> 8);
318 320
319 for (int j = -1; j <= 2; ++j) 321 uint8_t h3 = rvmap[3](seed);
320 for (int i = -1; i <= 2; ++i) 322
323 value_t v = 0;
324
321 for (int k = -1; k <= 2; ++k) 325 for (int k = -1; k <= 2; ++k)
326 {
327 uint8_t h2 = rvmap[2](i2 + k) ^ h3;
328
329 for (int j = -1; j <= 2; ++j)
322 { 330 {
323 vec3d A = F - vec3d (i, j, k); 331 uint8_t h1 = rvmap[1](i1 + j) ^ h2;
324 float d = dot (A, A);
325 332
326 if (d < 4) 333 for (int i = -1; i <= 2; ++i)
327 { 334 {
328 float t1 = 1 - d / 4;
329 float t2 = t1 * t1;
330 float t4 = t2 * t2;
331
332 // (4t⁵ - 3t⁴)
333 float p = (4 * t1 - 3) * t4;
334
335 int h = rvmap[0](I[0] + i) ^ rvmap[1](I[1] + j) ^ rvmap[2](I[2] + k);
336 const float *G = charges3[h & 0xff];
337
338 v += dot (A, vec3d (G[0], G[1], G[2])) * p;
339 }
340 }
341
342 return clamp (v * 2, -.9999999, .9999999);
343}
344
345vec3d::T_numtype
346noise_gen<vec3d>::operator() (vec3d P, vec3d N)
347{
348 vec3d I = floor (P);
349 vec3d F = P - I;
350
351 float v = 0;
352
353 for (int j = -1; j <= 2; ++j)
354 for (int i = -1; i <= 2; ++i)
355 for (int k = -1; k <= 2; ++k)
356 {
357 vec3d D = F - vec3d (i, j, k); 335 vec3d A = F - vec3d (i, j, k);
358 float e = dot (D, N);
359 float o = 1 - abs (e);
360
361 if (o > 0)
362 {
363 vec3d A = D - e * N;
364 float d = dot (A, A); 336 value_t d = dot (A, A);
365 337
366 if (d < 4) 338 if (d < 4)
367 { 339 {
368 float t1 = 1 - d / 4; 340 value_t t1 = 1 - d / 4;
369 float t2 = t1 * t1; 341 value_t t2 = t1 * t1;
370 float t4 = t2 * t2; 342 value_t t4 = t2 * t2;
371 343
372 float o2 = o * o;
373
374 // (4t⁵ - 3t⁴) * (3o³ - 2o²) 344 // (4t⁵ - 3t⁴)
375 // alternative? ((o * 6 - 15) * o + 10) * o³ 345 value_t p = (4 * t1 - 3) * t4;
376 float p = (4 * t1 - 3) * t4 * (3 * o2 - 2 * o2 * o);
377 346
378 int h = rvmap[0](I[0] + i) ^ rvmap[1](I[1] + j) ^ rvmap[2](I[2] + k); 347 uint8_t h = rvmap[0](i0 + i) ^ h1;
379 const float *G = charges3[h & 0xff]; 348 const value_t *G = charges3[h & 0xff];
380 349
381 v += dot (A, vec3d (G[0], G[1], G[2])) * p; 350 v += dot (A, vec3d (G[0], G[1], G[2])) * p;
382 } 351 }
383 } 352 }
384 } 353 }
354 }
385 355
386 return clamp (v, -.9999999, .9999999); 356 return v * 2;
357}
358
359vec3d::T_numtype
360noise_gen<vec3d>::operator() (vec3d P, vec3d N, uint32_t seed)
361{
362 vec3d I = floor (P);
363 vec3d F = P - I;
364
365 seed *= 3039177861;
366 uint8_t i2 = uint8_t (I[2]) + (seed >> 24);
367 uint8_t i1 = uint8_t (I[1]) + (seed >> 16);
368 uint8_t i0 = uint8_t (I[0]) + (seed >> 8);
369
370 uint8_t h3 = rvmap[3](seed);
371
372 value_t v = 0;
373
374 for (int k = -1; k <= 2; ++k)
375 {
376 uint8_t h2 = rvmap[2](i2 + k) ^ h3;
377
378 for (int j = -1; j <= 2; ++j)
379 {
380 uint8_t h1 = rvmap[1](i1 + j) ^ h2;
381
382 for (int i = -1; i <= 2; ++i)
383 {
384 vec3d D = F - vec3d (i, j, k);
385 value_t e = dot (D, N);
386 value_t o = 1 - abs (e);
387
388 if (o > 0)
389 {
390 vec3d A = D - e * N;
391 value_t d = dot (A, A);
392
393 if (d < 4)
394 {
395 value_t t1 = 1 - d / 4;
396 value_t t2 = t1 * t1;
397 value_t t4 = t2 * t2;
398
399 value_t o2 = o * o;
400
401 // (4t⁵ - 3t⁴) * (3o³ - 2o²)
402 // alternative? ((o * 6 - 15) * o + 10) * o³
403 value_t p = (4 * t1 - 3) * t4 * (3 * o2 - 2 * o2 * o);
404
405 uint8_t h = rvmap[0](i0 + i) ^ h1;
406 const value_t *G = charges3[h & 0xff];
407
408 v += dot (A, vec3d (G[0], G[1], G[2])) * p;
409 }
410 }
411 }
412 }
413 }
414
415 return v;
387} 416}
388 417
389template class noise_gen<vec2d>; 418template class noise_gen<vec2d>;
390template class noise_gen<vec3d>; 419template class noise_gen<vec3d>;
391 420
392///////////////////////////////////////////////////////////////////////////// 421/////////////////////////////////////////////////////////////////////////////
393 422
394// find some uncorrelated spot - we assume that noise 2 units away
395// is completely uncorrelated - this is not true for other coordinates,
396// but generally works well.
397template<class vec_t> 423template<class vec_t>
398static vec_t 424frac_gen<vec_t>::frac_gen (int octaves, value_t lacunarity, value_t hurst_expo, seed_t seed)
399ith_octave (vec_t P, int i) 425: octaves (octaves), lac (lacunarity), h (hurst_expo)
400{ 426{
401 vec_t r = P; 427 this->seed (seed);
402 r[0] += i;
403 r[1] += i * 2;
404 return r;
405}
406 428
407template<class vec_t>
408frac_gen<vec_t>::frac_gen (value_t hurst_expo, value_t lacunarity)
409: h (hurst_expo), lac (lacunarity), noise_gen<vec_t> (0)
410{
411 value_t exsum = 0; 429 value_t exsum = 0;
412 value_t phi = noise (vec_t (value_t (0))) * 0.5 + 1; 430 value_t phi = noise (vec_t (value_t (0))) * 0.5 + 1;
413 431
414 for (int i = 0; i < MAX_OCTAVES; ++i) 432 for (int i = 0; i < octaves; ++i)
415 { 433 {
416 ex [i] = pow (lac, -h * i); 434 ex [i] = pow (lac, -h * i);
417 exsum += ex [i]; 435 exsum += ex [i];
418 fbm_mul [i] = 0.5 / (exsum * 0.75); // .75 is a heuristic 436 fbm_mul [i] = 0.5 / (exsum * 0.75); // .75 is a heuristic
419 rot [i].set (phi * i + 1); 437 rot [i].set (phi * i + 1);
420 } 438 }
421} 439}
422 440
423template<class vec_t> 441template<class vec_t>
424typename frac_gen<vec_t>::value_t 442typename frac_gen<vec_t>::value_t
425frac_gen<vec_t>::fBm (vec_t P, int octaves) 443frac_gen<vec_t>::fBm (vec_t P)
426{ 444{
427 value_t v = 0; 445 value_t v = 0;
428 446
429 for (int i = 0; i < octaves; ++i) 447 for (int i = 0; i < octaves; ++i)
430 { 448 {
431 rot [i](P); 449 rot [i](P);
432 v += noise (ith_octave (P, i)) * ex [i]; 450 v += noise (P, i) * ex [i];
433 P *= lac; 451 P *= lac;
434 } 452 }
435 453
436 return clamp<value_t> (v * fbm_mul [octaves - 1] + 0.5, 0, .9999999); 454 return v * fbm_mul [octaves - 1];
437} 455}
438 456
439template<class vec_t> 457template<class vec_t>
440typename frac_gen<vec_t>::value_t 458typename frac_gen<vec_t>::value_t
441frac_gen<vec_t>::turbulence (vec_t P, int octaves) 459frac_gen<vec_t>::turbulence (vec_t P)
442{ 460{
443 value_t v = 0; 461 value_t v = 0;
444 462
445 for (int i = 0; i < octaves; ++i) 463 for (int i = 0; i < octaves; ++i)
446 { 464 {
447 rot [i](P); 465 rot [i](P);
448 v += abs (noise (ith_octave (P, i))) * ex [i]; 466 v += abs (noise (P, i)) * ex [i];
449 P *= lac; 467 P *= lac;
450 } 468 }
451 469
452 return clamp<value_t> (v * fbm_mul [octaves - 1] * (0.5 / noise_gen<vec_t>::abs_avg ()), 0, .9999999); 470 return v * fbm_mul [octaves - 1] * (0.5 / noise_gen<vec_t>::abs_avg ());
453} 471}
454 472
455template<class vec_t> 473template<class vec_t>
456typename frac_gen<vec_t>::value_t 474typename frac_gen<vec_t>::value_t
457frac_gen<vec_t>::multifractal (vec_t P, int octaves, value_t offset) 475frac_gen<vec_t>::multifractal (vec_t P, value_t offset)
458{ 476{
459 value_t v = 1; 477 value_t v = 1;
460 478
461 for (int i = 0; i < octaves; ++i) 479 for (int i = 0; i < octaves; ++i)
462 { 480 {
463 rot [i](P); 481 rot [i](P);
464 v *= noise (P) * ex [i] + offset; 482 v *= noise (P) * ex [i] + offset;
465 P *= lac; 483 P *= lac;
466 } 484 }
467 485
468 return clamp<value_t> (v * 0.5, 0, .9999999); 486 return v * value_t (0.5);
469} 487}
470 488
471template<class vec_t> 489template<class vec_t>
472typename frac_gen<vec_t>::value_t 490typename frac_gen<vec_t>::value_t
473frac_gen<vec_t>::heterofractal (vec_t P, int octaves, value_t offset) 491frac_gen<vec_t>::heterofractal (vec_t P, value_t offset)
474{ 492{
475 value_t v = noise (P) + offset; 493 value_t v = noise (P) + offset;
476 494
477 for (int i = 1; i < octaves; ++i) 495 for (int i = 1; i < octaves; ++i)
478 { 496 {
484 return v / (1 << octaves); 502 return v / (1 << octaves);
485} 503}
486 504
487template<class vec_t> 505template<class vec_t>
488typename frac_gen<vec_t>::value_t 506typename frac_gen<vec_t>::value_t
489frac_gen<vec_t>::hybridfractal (vec_t P, int octaves, value_t offset, value_t gain) 507frac_gen<vec_t>::hybridfractal (vec_t P, value_t offset, value_t gain)
490{ 508{
491 value_t v = (noise (P) + offset) * ex [0]; 509 value_t v = (noise (P) + offset) * ex [0];
492 value_t weight = v; 510 value_t weight = v;
493 511
494 for (int i = 1; i < octaves; ++i) 512 for (int i = 1; i < octaves; ++i)
501 value_t sig = (noise (P) + offset) * ex [i]; 519 value_t sig = (noise (P) + offset) * ex [i];
502 v += weight * sig; 520 v += weight * sig;
503 weight *= gain * sig; 521 weight *= gain * sig;
504 } 522 }
505 523
506 return clamp<value_t> (v * 0.5 + 0.5, 0, .9999999); 524 return v * value_t (0.5) + value_t (0.5);
507} 525}
508 526
509template<class vec_t> 527template<class vec_t>
510typename frac_gen<vec_t>::value_t 528typename frac_gen<vec_t>::value_t
511frac_gen<vec_t>::ridgedmultifractal (vec_t P, int octaves, value_t offset, value_t gain) 529frac_gen<vec_t>::ridgedmultifractal (vec_t P, value_t offset, value_t gain)
512{ 530{
513 value_t sig = offset - abs (noise (P)); 531 value_t sig = offset - abs (noise (P));
514 sig *= sig; 532 sig *= sig;
515 value_t v = sig; 533 value_t v = sig;
516 534
517 for (int i = 1; i < octaves; ++i) 535 for (int i = 1; i < octaves; ++i)
518 { 536 {
519 rot [i](P); 537 rot [i](P);
520 P *= lac; 538 P *= lac;
521 539
540 // weight higher octaves by previous signal
522 value_t w = clamp (sig * gain, 0, 1); 541 value_t w = clamp (sig * gain, 0, 1);
523 542
524 sig = offset - abs (noise (P)); 543 sig = offset - abs (noise (P));
525 sig *= sig; 544 sig *= sig;
526 sig *= w; 545 sig *= w;
527 546
528 v += sig * ex [i]; 547 v += sig * ex [i];
529 } 548 }
530 549
531 return clamp<value_t> (v * 0.25, 0, .9999999); 550 return v * value_t (0.25);
532} 551}
533 552
534template<class vec_t> 553template<class vec_t>
535typename frac_gen<vec_t>::value_t 554typename frac_gen<vec_t>::value_t
536frac_gen<vec_t>::billowfractal (vec_t P, int octaves, value_t offset, value_t gain) 555frac_gen<vec_t>::billowfractal (vec_t P, value_t offset, value_t gain)
537{ 556{
538 value_t v = 0; 557 value_t v = 0;
539 558
540 offset += 2 * noise_gen<vec_t>::abs_avg () - 1; 559 offset += 2 * noise_gen<vec_t>::abs_avg () - 1;
541 560
542 for (int i = 0; i < octaves; ++i) 561 for (int i = 0; i < octaves; ++i)
543 { 562 {
544 rot [i](P); 563 rot [i](P);
545 v += (abs (noise (ith_octave (P, i))) * gain - offset) * ex [i]; 564 v += (abs (noise (P, i)) * gain - offset) * ex [i];
546 P *= lac; 565 P *= lac;
547 } 566 }
548 567
549 return clamp<value_t> (v, -.9999999, .9999999); 568 return v;
550} 569}
551 570
552// http://www.gamasutra.com/view/feature/3098/a_realtime_procedural_universe_.php?page=2 571// http://www.gamasutra.com/view/feature/3098/a_realtime_procedural_universe_.php?page=2
553template<class vec_t> 572template<class vec_t>
554typename frac_gen<vec_t>::value_t 573typename frac_gen<vec_t>::value_t
555frac_gen<vec_t>::terrain (vec_t P, int octaves) 574frac_gen<vec_t>::terrain (vec_t P)
556{ 575{
557 value_t v = 0; 576 value_t v = 0;
558 577
559 for (int i = 0; i < octaves; ++i) 578 for (int i = 0; i < octaves; ++i)
560 { 579 {
568 return v <= 0 ? - pow (-v, 0.7) : pow (v, 1 + noise (P) * v); 587 return v <= 0 ? - pow (-v, 0.7) : pow (v, 1 + noise (P) * v);
569} 588}
570 589
571template<class vec_t> 590template<class vec_t>
572typename frac_gen<vec_t>::value_t 591typename frac_gen<vec_t>::value_t
573frac_gen<vec_t>::terrain2 (vec_t P, int octaves) 592frac_gen<vec_t>::terrain2 (vec_t P)
574{ 593{
575 value_t a = fBm (P, octaves); 594 value_t a = fBm (P);
576 value_t b = ridgedmultifractal (P, octaves, 1, 8); 595 value_t b = ridgedmultifractal (P, 1, 8);
577 value_t fade = fBm (P + vec_t(10.3), octaves); 596 value_t fade = fBm (P + vec_t(10.3));
578 597
579 const value_t width = 0.05; 598 const value_t width = 0.05;
580 599
581 if (fade > 0.5 + width) 600 if (fade > 0.5 + width)
582 return a; 601 return a;
592} 611}
593 612
594template class frac_gen<vec2d>; 613template class frac_gen<vec2d>;
595template class frac_gen<vec3d>; 614template class frac_gen<vec3d>;
596 615
597/////////////////////////////////////////////////////////////////////////////
598
599void noise_test ();
600void noise_test ()
601{
602 frac_gen<vec2d> gen (0.5, 1.9);
603 frac_gen<vec3d> gen3;
604
605#if 1
606 int N = 1024;
607
608 printf ("P5 %d %d 255\n", N, N);
609 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
610 for (int y = 0; y < N; ++y)
611 {
612 if (!(y&63))fprintf (stderr, "y %d\n", y);//D
613 for (int x = 0; x < N; ++x)
614 {
615 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout);
616 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);
617 //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout);
618 putc (256 * gen.turbulence (vec2d (x * 0.004 - 1, y * 0.004 - 1), 10), stdout);
619 //putc (256 * gen.heterofractal (vec2d (x * 0.008, y * 0.008), 8, 0.9), stdout);
620
621 // mountais or somesuch(?)
622 //putc (256 * gen.hybridfractal (vec2d (x * 0.01, y * 0.01), 8, -.4, -4), stdout);
623
624 // temperature
625 //putc (256 * gen.fBm (vec2d (x * 0.002, y * 0.002), 2), stdout);
626 // rain
627
628 //cells
629 //putc (127.49 * gen.billowfractal (vec2d (x * 0.01, y * 0.01), 9) + 128, stdout);
630 }
631 }
632#else
633 int N = 512;
634
635 //printf ("P6 %d %d 255\n", N, N);
636 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
637 for (int z = 0; z < N; ++z)
638 {
639 if (!(z&7))fprintf (stderr, "z %d\n", z);//D
640 for (int y = 0; y < N; ++y)
641 for (int x = 0; x < N; ++x)
642 {
643 float v = gen3.ridgedmultifractal (vec3d (x * 0.01 + 0.2, y * 0.01 + 0.2, z * 0.01 + 0.2), 3, 1.03, 2) * 2;
644
645#if 0
646 if (z < 64)
647 v = v * (z * z) / (64 * 64);
648#endif
649
650 if (v <= 0.9999)
651 continue;
652
653 float r[4];
654 int i[4];
655
656 r[0] = x;
657 r[1] = y;
658 r[2] = z;
659 r[3] = v;
660
661 memcpy (i, r, 16);
662
663 i[0] = htonl (i[0]);
664 i[1] = htonl (i[1]);
665 i[2] = htonl (i[2]);
666 i[3] = htonl (i[3]);
667
668 fwrite (i, 4*4, 1, stdout);
669 }
670 }
671#endif
672
673 exit (0);
674}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines