… | |
… | |
626 | min_it (border, N - P [1]); |
626 | min_it (border, N - P [1]); |
627 | |
627 | |
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 |
|
|
632 | |
|
|
633 | #define FANCY_GRAPHICS 1 |
|
|
634 | |
631 | static void |
635 | static void |
632 | gen_height (int x, int y) |
636 | gen_quadspace (int x, int y, int z) |
633 | { |
637 | { |
634 | vec2d P = vec2d (x, y); |
638 | vec2d P = vec2d (x, y); |
|
|
639 | |
|
|
640 | const int deep_sea_z = -200; |
|
|
641 | const int mountain_z = 200; |
635 | |
642 | |
636 | static frac2d gen(13); |
643 | static frac2d gen(13); |
637 | |
644 | |
638 | static frac2d vec_gen1 (6, 2, 0.5, 1); |
645 | static frac2d vec_gen1 (6, 2, 0.5, 1); |
639 | static frac2d vec_gen2 (6, 2, 0.5, 2); |
646 | static frac2d vec_gen2 (6, 2, 0.5, 2); |
… | |
… | |
654 | vec2d P_continent = P * continent_scale + perturb; |
661 | vec2d P_continent = P * continent_scale + perturb; |
655 | |
662 | |
656 | static frac2d continent_gen (13, 2.13, 0.5); |
663 | static frac2d continent_gen (13, 2.13, 0.5); |
657 | float continent = continent_gen.fBm (P_continent) + 0.05f; |
664 | float continent = continent_gen.fBm (P_continent) + 0.05f; |
658 | |
665 | |
659 | float land_gradient = sigmoid1 (P[0] * (1. / 25000)); |
666 | float x_gradient = P[0] * (1. / 25000); |
|
|
667 | float y_gradient = P[1] * (1. / 25000); |
|
|
668 | float xy_gradient = (P[0] + P[1]) * (0.5 / 25000); |
660 | |
669 | |
661 | const float W = 1000 * continent_scale; |
|
|
662 | const float N = (25000 - 1) * continent_scale; |
670 | const float N = (25000 - 1) * continent_scale; |
663 | |
671 | |
|
|
672 | // we clip a large border on the perturbed shape, to get irregular coastline |
|
|
673 | // and then clip a smaller border around the real shape |
664 | continent = border_blend (-1.f, continent, P_continent , N, 400 * continent_scale); |
674 | 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); |
675 | continent = border_blend (-1.f, continent, P * continent_scale + perturb * 0.1, N, 100 * continent_scale); |
666 | |
676 | |
|
|
677 | enum { |
|
|
678 | T_NONE, |
|
|
679 | T_OCEAN, |
|
|
680 | T_RIVER, |
|
|
681 | T_VALLEY, |
|
|
682 | T_MOUNTAIN, |
|
|
683 | T_UNDERGROUND, |
|
|
684 | T_ACQUIFER, |
|
|
685 | } t = T_NONE; |
|
|
686 | |
667 | vec3d c; |
687 | vec3d c; |
668 | float v; |
688 | int h = 1000000; // height form heightmap |
|
|
689 | |
|
|
690 | // the continent increases in height from 0 to ~700 levels in the absence of anything else |
|
|
691 | // thats about one step every 7 maps. |
|
|
692 | int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f); |
|
|
693 | int river_height = base_height * 9 / 10; |
|
|
694 | |
|
|
695 | // add this to rivers to "dry them out" |
|
|
696 | float dry_out = max (0.f, lerp (xy_gradient, 0.7f, 1.f, 0.f, 0.3f)); |
|
|
697 | |
|
|
698 | static frac2d river_gen (2); |
|
|
699 | float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)) + dry_out; |
|
|
700 | float river2 = river_gen.ridgedmultifractal (P * 0.04, 0.8, 10) - y_gradient * 0.2 - 0.16 - dry_out; |
|
|
701 | |
|
|
702 | float valley = river1 - 0.2f; |
|
|
703 | |
|
|
704 | static frac2d mountain_gen (8, 2.14, 0.5); |
|
|
705 | float mountain = mountain_gen.ridgedmultifractal (P * 0.004); |
|
|
706 | |
|
|
707 | t = valley < 0 ? T_VALLEY : T_MOUNTAIN; |
|
|
708 | c = blend0 (vec3d (0, 0.8, 0), vec3d (0.8, 0, 0), valley, 0.1f); |
|
|
709 | h = blend0 (base_height + continent * 300, base_height + mountain * xy_gradient * 400, valley, 0.1f); |
|
|
710 | |
|
|
711 | if (river1 < 0.01f) |
|
|
712 | { |
|
|
713 | // main rivers - they cut deeply into the mountains (base_height * 0.9f) |
|
|
714 | t = T_RIVER; |
|
|
715 | c = vec3d (0.2, 0.2, 1); |
|
|
716 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1)); |
|
|
717 | } |
|
|
718 | |
|
|
719 | if (river2 > 0) |
|
|
720 | { |
|
|
721 | t = T_RIVER; |
|
|
722 | c = vec3d (0.2, 0.2, 1); |
|
|
723 | min_it (h, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1)); |
|
|
724 | } |
669 | |
725 | |
670 | if (continent < 0) |
726 | if (continent < 0) |
671 | { |
727 | { |
672 | // ocean |
728 | t = T_OCEAN; |
673 | |
729 | min_it (h, min (continent * 200, -1)); |
674 | v = min (continent * 10, -0.2f); |
|
|
675 | c = vec3d (0, 0, 1); |
730 | c = vec3d (0, 0, 1); |
676 | } |
731 | } |
677 | else |
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; |
678 | { |
743 | } |
679 | // continent |
|
|
680 | |
744 | |
681 | // big rivers |
745 | // put acquifers a bit below the surface, to reduce them leaking out (will still happen) |
|
|
746 | if (z < h - 3) |
|
|
747 | { |
682 | static frac2d river_gen (1); |
748 | static frac3d acquifer_gen (4); |
683 | float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)); |
749 | float acquifer = acquifer_gen.ridgedmultifractal (vec3d (x * 0.001, y * 0.001, z * 0.01), 1.003, 2); |
684 | float river2 = river_gen.ridgedmultifractal (P * 0.04 + vec2d (3, 5), 0.8, 10) - (P[1] / 25000) * 0.1; |
|
|
685 | |
750 | |
686 | if (river1 < 0.03f) |
751 | if (acquifer > 0.48) |
687 | { |
752 | { |
688 | v = min (-0.1f, -river1); |
753 | t = T_ACQUIFER; |
689 | c = vec3d (0.2, 0.2, 1); |
754 | c = vec3d (1,1,1); |
690 | } |
755 | } |
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 | } |
756 | } |
708 | |
757 | |
709 | c *= v * 0.5 + 0.5; |
758 | // TODO: caves |
|
|
759 | // TODO: chees areas |
|
|
760 | // TODO: minerals |
|
|
761 | // TODO: monsters |
|
|
762 | |
|
|
763 | #if FANCY_GRAPHICS |
|
|
764 | float v = clamp (lerp<float> (h, deep_sea_z, mountain_z*0+800, 0.f, 1.f), 0.f, 1.f); |
|
|
765 | c *= v; |
710 | |
766 | |
711 | putc (clamp<int> (255 * c[0], 0, 255), stdout); |
767 | putc (clamp<int> (255 * c[0], 0, 255), stdout); |
712 | putc (clamp<int> (255 * c[1], 0, 255), stdout); |
768 | putc (clamp<int> (255 * c[1], 0, 255), stdout); |
713 | putc (clamp<int> (255 * c[2], 0, 255), stdout); |
769 | putc (clamp<int> (255 * c[2], 0, 255), stdout); |
|
|
770 | #endif |
714 | } |
771 | } |
715 | |
772 | |
716 | void noise_test (); |
773 | void noise_test (); |
717 | void noise_test () |
774 | void noise_test () |
718 | { |
775 | { |
719 | #if 1 |
776 | #if 0 |
720 | int Nw = 700; |
777 | int Nw = 700; |
721 | |
778 | |
722 | printf ("P6 %d %d 255\n", Nw * 3, Nw * 2); |
779 | 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 |
780 | // 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) |
781 | for (int y = 0; y < Nw; ++y) |
725 | { |
782 | { |
726 | 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 |
727 | |
784 | |
728 | 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); |
729 | |
786 | |
730 | for (int x = 0; x < Nw; ++x) gen_height (x, y); |
787 | for (int x = 0; x < Nw; ++x) gen_quadspace (x + 400, y, 0); |
731 | 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); |
732 | } |
789 | } |
733 | for (int y = 0; y < Nw; ++y) |
790 | for (int y = 0; y < Nw; ++y) |
734 | { |
791 | { |
735 | 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 |
736 | |
793 | |
737 | 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); |
738 | for (int x = 0; x < Nw; ++x) gen_height (x + 12000, y + 12000); |
795 | for (int x = 0; x < Nw; ++x) gen_quadspace (x + 12500, y + 12500, 0); |
739 | 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); |
740 | } |
797 | } |
741 | |
798 | |
742 | //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); |
743 | //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); |
744 | //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); |
… | |
… | |
746 | //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); |
747 | //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); |
748 | //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); |
749 | //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); |
750 | #else |
807 | #else |
751 | int N = 128; |
808 | int N = 200; |
752 | |
809 | |
753 | //printf ("P6 %d %d 255\n", N, N); |
810 | //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 |
811 | // 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) |
812 | for (int z = 0; z < N; ++z) |
757 | { |
813 | { |
758 | if (!(z&7))fprintf (stderr, "z %d\n", z);//D |
814 | if (!(z&7))fprintf (stderr, "z %d\n", z);//D |
759 | for (int y = 0; y < N; ++y) |
815 | for (int y = 0; y < N; ++y) |
760 | for (int x = 0; x < N; ++x) |
816 | for (int x = 0; x < N; ++x) |
761 | { |
817 | { |
|
|
818 | #if 0 |
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; |
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; |
763 | |
820 | |
764 | #if 0 |
|
|
765 | if (z < 64) |
821 | if (z < 64) |
766 | v = v * (z * z) / (64 * 64); |
822 | v = v * (z * z) / (64 * 64); |
767 | #endif |
|
|
768 | |
823 | |
769 | if (v <= 0.9) |
824 | if (v <= 0.9) |
770 | 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; |
771 | |
832 | |
772 | float r[4]; |
833 | float r[4]; |
773 | int i[4]; |
834 | int i[4]; |
774 | |
835 | |
775 | r[0] = x; |
836 | r[0] = x; |