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.14 by root, Sat Apr 30 11:02:25 2011 UTC vs.
Revision 1.22 by root, Sun Jan 29 02:47:04 2017 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 (©) 2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * 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 7 * 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 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * 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 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "noise.h" 23#include "noise.h"
24 24
299 } 299 }
300 } 300 }
301 } 301 }
302 302
303 return v; 303 return v;
304} 304}
305 305
306///////////////////////////////////////////////////////////////////////////// 306/////////////////////////////////////////////////////////////////////////////
307 307
308template<> 308template<>
309vec3d::T_numtype 309vec3d::T_numtype
610} 610}
611 611
612template class frac_gen<vec2d>; 612template class frac_gen<vec2d>;
613template class frac_gen<vec3d>; 613template class frac_gen<vec3d>;
614 614
615/////////////////////////////////////////////////////////////////////////////
616
617template<typename T, typename U>
618T
619inline border_blend (T a, T b, vec2d P, U N, U W)
620{
621 U border = W; // within n places of the border
622
623 min_it (border, P [0]);
624 min_it (border, N - P [0]);
625 min_it (border, P [1]);
626 min_it (border, N - P [1]);
627
628 return blend (a, b,border, U(0), W);
629}
630
631static void
632gen_height (int x, int y)
633{
634 vec2d P = vec2d (x, y);
635
636 static frac2d gen(13);
637
638 static frac2d vec_gen1 (6, 2, 0.5, 1);
639 static frac2d vec_gen2 (6, 2, 0.5, 2);
640
641 const float continent_scale = 0.00008;
642
643 vec2d perturb_pos = pow (P, 1.4) * 1e-5;
644
645 vec2d perturb (
646 vec_gen1.fBm (perturb_pos),
647 vec_gen2.fBm (perturb_pos)
648 );
649
650 float perturb_perturb = 1 - (P[1] - P[0]) * (1. / 25000 / 2);
651 perturb_perturb = perturb_perturb * perturb_perturb * 0.4;
652 perturb *= perturb_perturb;
653
654 vec2d P_continent = P * continent_scale + perturb;
655
656 static frac2d continent_gen (13, 2.13, 0.5);
657 float continent = continent_gen.fBm (P_continent) + 0.05f;
658
659 float land_gradient = sigmoid1 (P[0] * (1. / 25000));
660
661 const float W = 1000 * continent_scale;
662 const float N = (25000 - 1) * continent_scale;
663
664 continent = border_blend (-1.f, continent, P_continent , N, 400 * continent_scale);
665 continent = border_blend (-1.f, continent, P * continent_scale + perturb * 0.1, N, 100 * continent_scale);
666
667 vec3d c;
668 float v;
669
670 if (continent < 0)
671 {
672 // ocean
673
674 v = min (continent * 10, -0.2f);
675 c = vec3d (0, 0, 1);
676 }
677 else
678 {
679 // continent
680
681 // big rivers
682 static frac2d river_gen (1);
683 float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4));
684 float river2 = river_gen.ridgedmultifractal (P * 0.04 + vec2d (3, 5), 0.8, 10) - (P[1] / 25000) * 0.1;
685
686 if (river1 < 0.03f)
687 {
688 v = min (-0.1f, -river1);
689 c = vec3d (0.2, 0.2, 1);
690 }
691 else if (river1 < 0.2f && river2 > 0.1f)
692 {
693 v = -0.05f;
694 c = vec3d (0.4, 0.4, 1);
695 }
696 else
697 {
698 river1 += 0.07f;
699
700 //c = river1 > 0 ? vec3d (0.8, 0.8, 0) : vec3d (0.8, 0, 0);
701 c = blend0 (vec3d (0.8, 0, 0), vec3d (0.8, 0.8, 0), 0.01f, river1);;
702
703 static frac2d mountain_gen (8, 2.14, 0.5);
704 float mountain = mountain_gen.ridgedmultifractal (P * 0.004);
705 v = blend0 (mountain * 3 - 1, continent, 0.05f, river1);
706 }
707 }
708
709 c *= v * 0.5 + 0.5;
710
711 putc (clamp<int> (255 * c[0], 0, 255), stdout);
712 putc (clamp<int> (255 * c[1], 0, 255), stdout);
713 putc (clamp<int> (255 * c[2], 0, 255), stdout);
714}
715
716void noise_test ();
717void noise_test ()
718{
719#if 1
720 int Nw = 700;
721
722 printf ("P6 %d %d 255\n", Nw * 3, Nw * 2);
723 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
724 for (int y = 0; y < Nw; ++y)
725 {
726 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D
727
728 for (int x = 0; x < Nw; ++x) gen_height (x * 25000 / Nw, y * 25000 / Nw);
729
730 for (int x = 0; x < Nw; ++x) gen_height (x, y);
731 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 2000);
732 }
733 for (int y = 0; y < Nw; ++y)
734 {
735 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D
736
737 for (int x = 0; x < Nw; ++x) gen_height (x + 1000, y + 22000);
738 for (int x = 0; x < Nw; ++x) gen_height (x + 12000, y + 12000);
739 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 22000);
740 }
741
742 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout);
743 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);
744 //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout);
745 //putc (256 * gen.turbulence (vec2d (x * 0.004 - 1, y * 0.004 - 1), 10), stdout);
746 //putc (256 * gen.heterofractal (vec2d (x * 0.008, y * 0.008), 8, 0.9), stdout);
747 //putc (256 * gen.hybridfractal (vec2d (x * 0.01, y * 0.01), 8, -.4, -4), stdout);
748 //putc (256 * gen.fBm (vec2d (x * 0.002, y * 0.002), 2), stdout);
749 //putc (127.49 * gen.billowfractal (vec2d (x * 0.01, y * 0.01), 9) + 128, stdout);
750#else
751 int N = 128;
752
753 //printf ("P6 %d %d 255\n", N, N);
754 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
755 frac3d gen3 (3);;
756 for (int z = 0; z < N; ++z)
757 {
758 if (!(z&7))fprintf (stderr, "z %d\n", z);//D
759 for (int y = 0; y < N; ++y)
760 for (int x = 0; x < N; ++x)
761 {
762 float v = gen3.ridgedmultifractal (vec3d (x * 0.001 + 0.2, y * 0.001 + 0.2, z * 0.01 + 0.2), 1.03, 2) * 2;
763
764#if 0
765 if (z < 64)
766 v = v * (z * z) / (64 * 64);
767#endif
768
769 if (v <= 0.9)
770 continue;
771
772 float r[4];
773 int i[4];
774
775 r[0] = x;
776 r[1] = y;
777 r[2] = z;
778 r[3] = v;
779
780 memcpy (i, r, 16);
781
782 i[0] = htonl (i[0]);
783 i[1] = htonl (i[1]);
784 i[2] = htonl (i[2]);
785 i[3] = htonl (i[3]);
786
787 fwrite (i, 4*4, 1, stdout);
788 }
789 }
790#endif
791
792 exit (0);
793}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines