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.15 by root, Sat Apr 30 11:03:46 2011 UTC vs.
Revision 1.21 by root, Wed Nov 16 23:41:59 2016 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
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 //c = river1 > 0 ? vec3d (0.8, 0.8, 0) : vec3d (0.8, 0, 0);
699 c = blend0 (vec3d (0.8, 0, 0), vec3d (0.8, 0.8, 0), 0.01f, river1);
700
701 static frac2d mountain_gen (8, 2.14, 0.5);
702 float mountain = mountain_gen.ridgedmultifractal (P * 0.004);
703 v = blend0 (mountain * 3 - 1, continent, 0.05f, river1);
704 }
705 }
706
707 c *= v * 0.5 + 0.5;
708
709 putc (clamp<int> (255 * c[0], 0, 255), stdout);
710 putc (clamp<int> (255 * c[1], 0, 255), stdout);
711 putc (clamp<int> (255 * c[2], 0, 255), stdout);
712}
713
714void noise_test ();
715void noise_test ()
716{
717#if 1
718 int Nw = 700;
719
720 printf ("P6 %d %d 255\n", Nw * 3, Nw * 2);
721 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
722 for (int y = 0; y < Nw; ++y)
723 {
724 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D
725
726 for (int x = 0; x < Nw; ++x) gen_height (x * 25000 / Nw, y * 25000 / Nw);
727
728 for (int x = 0; x < Nw; ++x) gen_height (x, y);
729 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 2000);
730 }
731 for (int y = 0; y < Nw; ++y)
732 {
733 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D
734
735 for (int x = 0; x < Nw; ++x) gen_height (x + 1000, y + 22000);
736 for (int x = 0; x < Nw; ++x) gen_height (x + 12000, y + 12000);
737 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 22000);
738 }
739
740 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout);
741 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);
742 //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout);
743 //putc (256 * gen.turbulence (vec2d (x * 0.004 - 1, y * 0.004 - 1), 10), stdout);
744 //putc (256 * gen.heterofractal (vec2d (x * 0.008, y * 0.008), 8, 0.9), stdout);
745 //putc (256 * gen.hybridfractal (vec2d (x * 0.01, y * 0.01), 8, -.4, -4), stdout);
746 //putc (256 * gen.fBm (vec2d (x * 0.002, y * 0.002), 2), stdout);
747 //putc (127.49 * gen.billowfractal (vec2d (x * 0.01, y * 0.01), 9) + 128, stdout);
748#else
749 int N = 128;
750
751 //printf ("P6 %d %d 255\n", N, N);
752 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
753 frac3d gen3 (3);;
754 for (int z = 0; z < N; ++z)
755 {
756 if (!(z&7))fprintf (stderr, "z %d\n", z);//D
757 for (int y = 0; y < N; ++y)
758 for (int x = 0; x < N; ++x)
759 {
760 float v = gen3.ridgedmultifractal (vec3d (x * 0.001 + 0.2, y * 0.001 + 0.2, z * 0.01 + 0.2), 1.03, 2) * 2;
761
762#if 0
763 if (z < 64)
764 v = v * (z * z) / (64 * 64);
765#endif
766
767 if (v <= 0.9)
768 continue;
769
770 float r[4];
771 int i[4];
772
773 r[0] = x;
774 r[1] = y;
775 r[2] = z;
776 r[3] = v;
777
778 memcpy (i, r, 16);
779
780 i[0] = htonl (i[0]);
781 i[1] = htonl (i[1]);
782 i[2] = htonl (i[2]);
783 i[3] = htonl (i[3]);
784
785 fwrite (i, 4*4, 1, stdout);
786 }
787 }
788#endif
789
790 exit (0);
791}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines