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.16 by root, Sat Apr 30 19:04:50 2011 UTC vs.
Revision 1.17 by root, Sun May 1 08:19:17 2011 UTC

628 return blend (a, b,border, U(0), W); 628 return blend (a, b,border, U(0), W);
629} 629}
630 630
631// highest mountains, deepest sea == 200 .. -200 631// highest mountains, deepest sea == 200 .. -200
632 632
633#define FANCY_GRAPHICS 1
634
633static void 635static void
634gen_height (int x, int y) 636gen_quadspace (int x, int y, int z)
635{ 637{
636 vec2d P = vec2d (x, y); 638 vec2d P = vec2d (x, y);
637 639
638 const int deep_sea_z = -200; 640 const int deep_sea_z = -200;
639 const int mountain_z = 200; 641 const int mountain_z = 200;
676 T_NONE, 678 T_NONE,
677 T_OCEAN, 679 T_OCEAN,
678 T_RIVER, 680 T_RIVER,
679 T_VALLEY, 681 T_VALLEY,
680 T_MOUNTAIN, 682 T_MOUNTAIN,
683 T_UNDERGROUND,
684 T_ACQUIFER,
681 } t = T_NONE; 685 } t = T_NONE;
682 686
683 vec3d c; 687 vec3d c;
684 int z = 1000000; 688 int h = 1000000; // height form heightmap
685 689
686 // the continent increases in height from 0 to ~700 levels in the absence of anything else 690 // the continent increases in height from 0 to ~700 levels in the absence of anything else
687 // thats about one step every 7 maps. 691 // thats about one step every 7 maps.
688 int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f); 692 int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f);
689 int river_height = base_height * 9 / 10; 693 int river_height = base_height * 9 / 10;
699 703
700 static frac2d mountain_gen (8, 2.14, 0.5); 704 static frac2d mountain_gen (8, 2.14, 0.5);
701 float mountain = mountain_gen.ridgedmultifractal (P * 0.004); 705 float mountain = mountain_gen.ridgedmultifractal (P * 0.004);
702 706
703 t = valley < 0 ? T_VALLEY : T_MOUNTAIN; 707 t = valley < 0 ? T_VALLEY : T_MOUNTAIN;
704 c = blend0 (vec3d (0.8, 0.8, 0), vec3d (0.8, 0, 0), valley, 0.1f); 708 c = blend0 (vec3d (0, 0.8, 0), vec3d (0.8, 0, 0), valley, 0.1f);
705 z = blend0 (base_height + continent * 300, base_height + mountain * xy_gradient * 400, valley, 0.1f); 709 h = blend0 (base_height + continent * 300, base_height + mountain * xy_gradient * 400, valley, 0.1f);
706 710
707 if (river1 < 0.01f) 711 if (river1 < 0.01f)
708 { 712 {
709 // main rivers - they cut deeply into the mountains (base_height * 0.9f) 713 // main rivers - they cut deeply into the mountains (base_height * 0.9f)
710 t = T_RIVER; 714 t = T_RIVER;
711 c = vec3d (0.2, 0.2, 1); 715 c = vec3d (0.2, 0.2, 1);
712 min_it (z, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1)); 716 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1));
713 } 717 }
714 718
715 if (river2 > 0) 719 if (river2 > 0)
716 { 720 {
717 t = T_RIVER; 721 t = T_RIVER;
718 c = vec3d (0.2, 0.2, 1); 722 c = vec3d (0.2, 0.2, 1);
719 min_it (z, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1)); 723 min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1));
720 } 724 }
721 725
722 if (continent < 0) 726 if (continent < 0)
723 { 727 {
724 t = T_OCEAN; 728 t = T_OCEAN;
725 min_it (z, min (continent * 200, -1)); 729 min_it (h, min (continent * 200, -1));
726 c = vec3d (0, 0, 1); 730 c = vec3d (0, 0, 1);
727 } 731 }
728 732
733 // now we have the base height, and base terrain
734
735#if FANCY_GRAPHICS
736 z = h; // show the surface, not the given z layer
737#endif
738
739 // everything below the surface is underground, or a variant
740 if (z < h)
741 {
742 t = T_UNDERGROUND;
743 }
744
745 // put acquifers a bit below the surface, to reduce them leaking out (will still happen)
746 if (z < h - 3)
747 {
748 static frac3d acquifer_gen (4);
749 float acquifer = acquifer_gen.ridgedmultifractal (vec3d (x * 0.001, y * 0.001, z * 0.01), 1.003, 2);
750
751 if (acquifer > 0.48)
752 {
753 t = T_ACQUIFER;
754 c = vec3d (1,1,1);
755 }
756 }
757
758 // TODO: caves
759 // TODO: chees areas
760 // TODO: minerals
761 // TODO: monsters
762
763#if FANCY_GRAPHICS
729 float v = clamp (lerp<float> (z, deep_sea_z, mountain_z*0+800, 0.f, 1.f), 0.f, 1.f); 764 float v = clamp (lerp<float> (h, deep_sea_z, mountain_z*0+800, 0.f, 1.f), 0.f, 1.f);
730 c *= v; 765 c *= v;
731 766
732 putc (clamp<int> (255 * c[0], 0, 255), stdout); 767 putc (clamp<int> (255 * c[0], 0, 255), stdout);
733 putc (clamp<int> (255 * c[1], 0, 255), stdout); 768 putc (clamp<int> (255 * c[1], 0, 255), stdout);
734 putc (clamp<int> (255 * c[2], 0, 255), stdout); 769 putc (clamp<int> (255 * c[2], 0, 255), stdout);
770#endif
735} 771}
736 772
737void noise_test (); 773void noise_test ();
738void noise_test () 774void noise_test ()
739{ 775{
740#if 1 776#if 0
741 int Nw = 700; 777 int Nw = 700;
742 778
743 printf ("P6 %d %d 255\n", Nw * 3, Nw * 2); 779 printf ("P6 %d %d 255\n", Nw * 3, Nw * 2);
744 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm 780 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
745 for (int y = 0; y < Nw; ++y) 781 for (int y = 0; y < Nw; ++y)
746 { 782 {
747 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D 783 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D
748 784
749 for (int x = 0; x < Nw; ++x) gen_height (x * 25000 / Nw, y * 25000 / Nw); 785 for (int x = 0; x < Nw; ++x) gen_quadspace (x * 25000 / Nw, y * 25000 / Nw, 0);
750 786
751 for (int x = 0; x < Nw; ++x) gen_height (x + 400, y); 787 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 400, y, 0);
752 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 2000); 788 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 22000, y + 2000, 0);
753 } 789 }
754 for (int y = 0; y < Nw; ++y) 790 for (int y = 0; y < Nw; ++y)
755 { 791 {
756 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D 792 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D
757 793
758 for (int x = 0; x < Nw; ++x) gen_height (x + 1000, y + 22000); 794 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 1000, y + 22000, 0);
759 for (int x = 0; x < Nw; ++x) gen_height (x + 12500, y + 12500); 795 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 12500, y + 12500, 0);
760 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 22000); 796 for (int x = 0; x < Nw; ++x) gen_quadspace (x + 22000, y + 22500, 0);
761 } 797 }
762 798
763 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout); 799 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout);
764 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout); 800 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);
765 //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout); 801 //putc (256 * gen.fBm (vec2d(x * 0.01, y * 0.01), 16), stdout);
767 //putc (256 * gen.heterofractal (vec2d (x * 0.008, y * 0.008), 8, 0.9), stdout); 803 //putc (256 * gen.heterofractal (vec2d (x * 0.008, y * 0.008), 8, 0.9), stdout);
768 //putc (256 * gen.hybridfractal (vec2d (x * 0.01, y * 0.01), 8, -.4, -4), stdout); 804 //putc (256 * gen.hybridfractal (vec2d (x * 0.01, y * 0.01), 8, -.4, -4), stdout);
769 //putc (256 * gen.fBm (vec2d (x * 0.002, y * 0.002), 2), stdout); 805 //putc (256 * gen.fBm (vec2d (x * 0.002, y * 0.002), 2), stdout);
770 //putc (127.49 * gen.billowfractal (vec2d (x * 0.01, y * 0.01), 9) + 128, stdout); 806 //putc (127.49 * gen.billowfractal (vec2d (x * 0.01, y * 0.01), 9) + 128, stdout);
771#else 807#else
772 int N = 128; 808 int N = 200;
773 809
774 //printf ("P6 %d %d 255\n", N, N); 810 //printf ("P6 %d %d 255\n", N, N);
775 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm 811 // pmake&&server/deliantra-server >x&&convert -depth 8 -size 512xx512 gray:x x.ppm&& cv x.ppm
776 frac3d gen3 (3);;
777 for (int z = 0; z < N; ++z) 812 for (int z = 0; z < N; ++z)
778 { 813 {
779 if (!(z&7))fprintf (stderr, "z %d\n", z);//D 814 if (!(z&7))fprintf (stderr, "z %d\n", z);//D
780 for (int y = 0; y < N; ++y) 815 for (int y = 0; y < N; ++y)
781 for (int x = 0; x < N; ++x) 816 for (int x = 0; x < N; ++x)
782 { 817 {
818#if 0
783 float v = gen3.ridgedmultifractal (vec3d (x * 0.001 + 0.2, y * 0.001 + 0.2, z * 0.01 + 0.2), 1.03, 2) * 2; 819 float v = gen3.ridgedmultifractal (vec3d (x * 0.001 + 0.2, y * 0.001 + 0.2, z * 0.01 + 0.2), 1.03, 2) * 2;
784 820
785#if 0
786 if (z < 64) 821 if (z < 64)
787 v = v * (z * z) / (64 * 64); 822 v = v * (z * z) / (64 * 64);
788#endif
789 823
790 if (v <= 0.9) 824 if (v <= 0.9)
791 continue; 825 continue;
826#endif
827 static frac3d gen3 (10);
828 //float v = gen3.turbulence (vec3d (x * 0.01, y * 0.01, z * 0.01));
829 float v = gen3.ridgedmultifractal (vec3d (x * 0.001, y * 0.001, z * 0.001), 1.003, 2);
830
831 if (v <= 0.48) continue;
792 832
793 float r[4]; 833 float r[4];
794 int i[4]; 834 int i[4];
795 835
796 r[0] = x; 836 r[0] = x;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines