--- deliantra/server/common/noise.C 2011/04/30 11:02:25 1.14 +++ deliantra/server/common/noise.C 2016/11/16 23:41:59 1.21 @@ -1,22 +1,22 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. - * - * Copyright (©) 2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * + * + * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the Affero GNU General Public License * and the GNU General Public License along with this program. If not, see * . - * + * * The authors can be reached via e-mail to */ @@ -612,182 +612,3 @@ template class frac_gen; template class frac_gen; -///////////////////////////////////////////////////////////////////////////// - -template -T -inline border_blend (T a, T b, vec2d P, U N, U W) -{ - U border = W; // within n places of the border - - min_it (border, P [0]); - min_it (border, N - P [0]); - min_it (border, P [1]); - min_it (border, N - P [1]); - - return blend (a, b,border, U(0), W); -} - -static void -gen_height (int x, int y) -{ - vec2d P = vec2d (x, y); - - static frac2d gen(13); - - static frac2d vec_gen1 (6, 2, 0.5, 1); - static frac2d vec_gen2 (6, 2, 0.5, 2); - - const float continent_scale = 0.00008; - - vec2d perturb_pos = pow (P, 1.4) * 1e-5; - - vec2d perturb ( - vec_gen1.fBm (perturb_pos), - vec_gen2.fBm (perturb_pos) - ); - - float perturb_perturb = 1 - (P[1] - P[0]) * (1. / 25000 / 2); - perturb_perturb = perturb_perturb * perturb_perturb * 0.4; - perturb *= perturb_perturb; - - vec2d P_continent = P * continent_scale + perturb; - - static frac2d continent_gen (13, 2.13, 0.5); - float continent = continent_gen.fBm (P_continent) + 0.05f; - - float land_gradient = sigmoid1 (P[0] * (1. / 25000)); - - const float W = 1000 * continent_scale; - const float N = (25000 - 1) * continent_scale; - - continent = border_blend (-1.f, continent, P_continent , N, 400 * continent_scale); - continent = border_blend (-1.f, continent, P * continent_scale + perturb * 0.1, N, 100 * continent_scale); - - vec3d c; - float v; - - if (continent < 0) - { - // ocean - - v = min (continent * 10, -0.2f); - c = vec3d (0, 0, 1); - } - else - { - // continent - - // big rivers - static frac2d river_gen (1); - float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)); - float river2 = river_gen.ridgedmultifractal (P * 0.04 + vec2d (3, 5), 0.8, 10) - (P[1] / 25000) * 0.1; - - if (river1 < 0.03f) - { - v = min (-0.1f, -river1); - c = vec3d (0.2, 0.2, 1); - } - else if (river1 < 0.2f && river2 > 0.1f) - { - v = -0.05f; - c = vec3d (0.4, 0.4, 1); - } - else - { - river1 += 0.07f; - - //c = river1 > 0 ? vec3d (0.8, 0.8, 0) : vec3d (0.8, 0, 0); - c = blend0 (vec3d (0.8, 0, 0), vec3d (0.8, 0.8, 0), 0.01f, river1);; - - static frac2d mountain_gen (8, 2.14, 0.5); - float mountain = mountain_gen.ridgedmultifractal (P * 0.004); - v = blend0 (mountain * 3 - 1, continent, 0.05f, river1); - } - } - - c *= v * 0.5 + 0.5; - - putc (clamp (255 * c[0], 0, 255), stdout); - putc (clamp (255 * c[1], 0, 255), stdout); - putc (clamp (255 * c[2], 0, 255), stdout); -} - -void noise_test (); -void noise_test () -{ -#if 1 - int Nw = 700; - - printf ("P6 %d %d 255\n", Nw * 3, Nw * 2); - // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm - for (int y = 0; y < Nw; ++y) - { - if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D - - for (int x = 0; x < Nw; ++x) gen_height (x * 25000 / Nw, y * 25000 / Nw); - - for (int x = 0; x < Nw; ++x) gen_height (x, y); - for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 2000); - } - for (int y = 0; y < Nw; ++y) - { - if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D - - for (int x = 0; x < Nw; ++x) gen_height (x + 1000, y + 22000); - for (int x = 0; x < Nw; ++x) gen_height (x + 12000, y + 12000); - for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 22000); - } - - //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout); - //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout); - //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout); - //putc (256 * gen.turbulence (vec2d (x * 0.004 - 1, y * 0.004 - 1), 10), stdout); - //putc (256 * gen.heterofractal (vec2d (x * 0.008, y * 0.008), 8, 0.9), stdout); - //putc (256 * gen.hybridfractal (vec2d (x * 0.01, y * 0.01), 8, -.4, -4), stdout); - //putc (256 * gen.fBm (vec2d (x * 0.002, y * 0.002), 2), stdout); - //putc (127.49 * gen.billowfractal (vec2d (x * 0.01, y * 0.01), 9) + 128, stdout); -#else - int N = 128; - - //printf ("P6 %d %d 255\n", N, N); - // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm - frac3d gen3 (3);; - for (int z = 0; z < N; ++z) - { - if (!(z&7))fprintf (stderr, "z %d\n", z);//D - for (int y = 0; y < N; ++y) - for (int x = 0; x < N; ++x) - { - float v = gen3.ridgedmultifractal (vec3d (x * 0.001 + 0.2, y * 0.001 + 0.2, z * 0.01 + 0.2), 1.03, 2) * 2; - -#if 0 - if (z < 64) - v = v * (z * z) / (64 * 64); -#endif - - if (v <= 0.9) - continue; - - float r[4]; - int i[4]; - - r[0] = x; - r[1] = y; - r[2] = z; - r[3] = v; - - memcpy (i, r, 16); - - i[0] = htonl (i[0]); - i[1] = htonl (i[1]); - i[2] = htonl (i[2]); - i[3] = htonl (i[3]); - - fwrite (i, 4*4, 1, stdout); - } - } -#endif - - exit (0); -}