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.2 by root, Fri Apr 22 02:03:10 2011 UTC vs.
Revision 1.3 by root, Fri Apr 22 07:56:46 2011 UTC

28{ 28{
29 seedable_rand_gen rng (seed); 29 seedable_rand_gen rng (seed);
30 30
31 for (int i = 0; i < 256; ++i) 31 for (int i = 0; i < 256; ++i)
32 { 32 {
33 for (int j = 0; j < 2; ++j) 33 vec2d rv;
34 rvec [i][j] = rng () - 0.5f; 34 rv[0] = rng () - 0.5f;
35 rv[1] = rng () - 0.5f;
35 36
36 // normalise 37 // normalise
37 float mag = 1.f / sqrtf (rvec [i][0] * rvec [i][0] + rvec [i][1] * rvec [i][1]); 38 float mag = 1.f / sqrtf (rv[0] * rv[0] + rv[1] * rv[1]);
38 39
39 rvec [i][0] *= mag; 40 rv[0] *= mag;
40 rvec [i][1] *= mag; 41 rv[1] *= mag;
41 }
42 42
43 rvec[i][0] = rv[0];
44 rvec[i][1] = rv[1];
45 }
46
43 rvmap [0].seed (rng); 47 rvmap[0].seed (rng);
44 rvmap [1].seed (rng); 48 rvmap[1].seed (rng);
45} 49}
46 50
47float 51float
48noise2d::noise (float x, float y) 52noise2d::noise (float x, float y)
49{ 53{
60 64
61 float d = Ax * Ax + Ay * Ay; 65 float d = Ax * Ax + Ay * Ay;
62 66
63 if (d < 4) 67 if (d < 4)
64 { 68 {
65 int h = rvmap [0](ix + i) ^ rvmap [1](iy + j);
66 float *G = rvec [h & 0xff];
67
68 float t1 = 1 - d / 4; 69 float t1 = 1 - d / 4;
69 float t2 = t1 * t1; 70 float t2 = t1 * t1;
70 float t4 = t2 * t2; 71 float t4 = t2 * t2;
71 72
72 float p = (4 * t1 - 3) * t4; 73 float p = (4 * t1 - 3) * t4;
74
75 int h = rvmap[0](ix + i) ^ rvmap[1](iy + j);
76 float G0 = rvec[h & 0xff][0];
77 float G1 = rvec[h & 0xff][1];
78 //vec2d G = rvec[h & 0xff];
79
73 v += (Ax * G[0] + Ay * G[1]) * p; 80 v += (Ax * G0 + Ay * G1) * p;
74 } 81 }
75 } 82 }
76 83
77 return clamp (v * 2, -.9999999f, .9999999f); 84 return clamp (v * 2, -.9999999f, .9999999f);
78} 85}
403 } 410 }
404 411
405 return clamp (v * 0.25f, 0.f, .9999999f); 412 return clamp (v * 0.25f, 0.f, .9999999f);
406} 413}
407 414
408#if 0 415#if 1
409void hack() 416void hack()
410{ 417{
411 frac_gen gen (0.5, 2); 418 frac_gen gen (0.5, 2);
412 noise3d n(0); 419 noise3d n(0);
413 420
414#if 0 421#if 1
415 int N = 1024; 422 int N = 1024;
416 423
417 printf ("P6 %d %d 255\n", N, N); 424 printf ("P5 %d %d 255\n", N, N);
418 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm 425 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
419 for (int y = 0; y < N; ++y) 426 for (int y = 0; y < N; ++y)
420 { 427 {
421 if (!(y&63))fprintf (stderr, "y %d\n", y);//D 428 if (!(y&63))fprintf (stderr, "y %d\n", y);//D
422 for (int x = 0; x < N; ++x) 429 for (int x = 0; x < N; ++x)
423 { 430 {
424 putc (128 + 128 * n.noise (x * 0.04 + 0.2, y * 0.04 + 0.2), stdout); 431 putc (127 * gen.noise (x * 0.04, y * 0.04) + 128, stdout);
425 putc (128 + 128 * n.noise (x * 0.04 + 0.2, y * 0.08 + 0.2), stdout);
426 putc (128 + 128 * n.noise (x * 0.08 + 0.2, y * 0.04 + 0.2), stdout);
427 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout); 432 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);
428 //putc (256 * gen.fBm (x * 0.001, y * 0.001, 3), stdout); 433 //putc (256 * gen.fBm (x * 0.01, y * 0.01, 7), stdout);
429 //putc (256 * gen.turbulence (x * 0.004 - 1, y * 0.004 - 1, 8), stdout); 434 //putc (256 * gen.turbulence (x * 0.004 - 1, y * 0.004 - 1, 8), stdout);
430 //putc (256 * gen.heterofractal (x * 0.008, y * 0.008, 8, -1.1, 2.0), stdout); 435 //putc (256 * gen.heterofractal (x * 0.008, y * 0.008, 8, -1.1, 2.0), stdout);
431 //putc (256 * gen.ridgedmultifractal (x * 0.001, y * 0.001, 32, 1.001, 32), stdout); 436 //putc (256 * gen.ridgedmultifractal (x * 0.001, y * 0.001, 32, 1.001, 32), stdout);
432 } 437 }
433 } 438 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines