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.16 by root, Sat Apr 30 19:04:50 2011 UTC

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
631static void 633static void
632gen_height (int x, int y) 634gen_height (int x, int y)
633{ 635{
634 vec2d P = vec2d (x, y); 636 vec2d P = vec2d (x, y);
637
638 const int deep_sea_z = -200;
639 const int mountain_z = 200;
635 640
636 static frac2d gen(13); 641 static frac2d gen(13);
637 642
638 static frac2d vec_gen1 (6, 2, 0.5, 1); 643 static frac2d vec_gen1 (6, 2, 0.5, 1);
639 static frac2d vec_gen2 (6, 2, 0.5, 2); 644 static frac2d vec_gen2 (6, 2, 0.5, 2);
654 vec2d P_continent = P * continent_scale + perturb; 659 vec2d P_continent = P * continent_scale + perturb;
655 660
656 static frac2d continent_gen (13, 2.13, 0.5); 661 static frac2d continent_gen (13, 2.13, 0.5);
657 float continent = continent_gen.fBm (P_continent) + 0.05f; 662 float continent = continent_gen.fBm (P_continent) + 0.05f;
658 663
659 float land_gradient = sigmoid1 (P[0] * (1. / 25000)); 664 float x_gradient = P[0] * (1. / 25000);
665 float y_gradient = P[1] * (1. / 25000);
666 float xy_gradient = (P[0] + P[1]) * (0.5 / 25000);
660 667
661 const float W = 1000 * continent_scale;
662 const float N = (25000 - 1) * continent_scale; 668 const float N = (25000 - 1) * continent_scale;
663 669
670 // we clip a large border on the perturbed shape, to get irregular coastline
671 // and then clip a smaller border around the real shape
664 continent = border_blend (-1.f, continent, P_continent , N, 400 * continent_scale); 672 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); 673 continent = border_blend (-1.f, continent, P * continent_scale + perturb * 0.1, N, 100 * continent_scale);
666 674
675 enum {
676 T_NONE,
677 T_OCEAN,
678 T_RIVER,
679 T_VALLEY,
680 T_MOUNTAIN,
681 } t = T_NONE;
682
667 vec3d c; 683 vec3d c;
668 float v; 684 int z = 1000000;
685
686 // the continent increases in height from 0 to ~700 levels in the absence of anything else
687 // thats about one step every 7 maps.
688 int base_height = blend (0, 300, xy_gradient, 0.2f, 0.9f);
689 int river_height = base_height * 9 / 10;
690
691 // add this to rivers to "dry them out"
692 float dry_out = max (0.f, lerp (xy_gradient, 0.7f, 1.f, 0.f, 0.3f));
693
694 static frac2d river_gen (2);
695 float river1 = abs (river_gen.fBm (P * 0.001 + perturb * 4)) + dry_out;
696 float river2 = river_gen.ridgedmultifractal (P * 0.04, 0.8, 10) - y_gradient * 0.2 - 0.16 - dry_out;
697
698 float valley = river1 - 0.2f;
699
700 static frac2d mountain_gen (8, 2.14, 0.5);
701 float mountain = mountain_gen.ridgedmultifractal (P * 0.004);
702
703 t = valley < 0 ? T_VALLEY : T_MOUNTAIN;
704 c = blend0 (vec3d (0.8, 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);
706
707 if (river1 < 0.01f)
708 {
709 // main rivers - they cut deeply into the mountains (base_height * 0.9f)
710 t = T_RIVER;
711 c = vec3d (0.2, 0.2, 1);
712 min_it (z, river_height + lerp<float> (river1, 0.f, 0.01f, -20, -1));
713 }
714
715 if (river2 > 0)
716 {
717 t = T_RIVER;
718 c = vec3d (0.2, 0.2, 1);
719 min_it (z, river_height + lerp<float> (river1, 0.f, 0.01f, -5, -1));
720 }
669 721
670 if (continent < 0) 722 if (continent < 0)
671 { 723 {
672 // ocean 724 t = T_OCEAN;
673 725 min_it (z, min (continent * 200, -1));
674 v = min (continent * 10, -0.2f);
675 c = vec3d (0, 0, 1); 726 c = vec3d (0, 0, 1);
676 } 727 }
677 else
678 {
679 // continent
680 728
681 // big rivers 729 float v = clamp (lerp<float> (z, deep_sea_z, mountain_z*0+800, 0.f, 1.f), 0.f, 1.f);
682 static frac2d river_gen (1); 730 c *= v;
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 731
709 putc (clamp<int> (255 * c[0], 0, 255), stdout); 732 putc (clamp<int> (255 * c[0], 0, 255), stdout);
710 putc (clamp<int> (255 * c[1], 0, 255), stdout); 733 putc (clamp<int> (255 * c[1], 0, 255), stdout);
711 putc (clamp<int> (255 * c[2], 0, 255), stdout); 734 putc (clamp<int> (255 * c[2], 0, 255), stdout);
712} 735}
723 { 746 {
724 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D 747 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw);//D
725 748
726 for (int x = 0; x < Nw; ++x) gen_height (x * 25000 / Nw, y * 25000 / Nw); 749 for (int x = 0; x < Nw; ++x) gen_height (x * 25000 / Nw, y * 25000 / Nw);
727 750
728 for (int x = 0; x < Nw; ++x) gen_height (x, y); 751 for (int x = 0; x < Nw; ++x) gen_height (x + 400, y);
729 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 2000); 752 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 2000);
730 } 753 }
731 for (int y = 0; y < Nw; ++y) 754 for (int y = 0; y < Nw; ++y)
732 { 755 {
733 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D 756 if (!(y&63))fprintf (stderr, "y %d\n", y * 50 / Nw+50);//D
734 757
735 for (int x = 0; x < Nw; ++x) gen_height (x + 1000, y + 22000); 758 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); 759 for (int x = 0; x < Nw; ++x) gen_height (x + 12500, y + 12500);
737 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 22000); 760 for (int x = 0; x < Nw; ++x) gen_height (x + 22000, y + 22000);
738 } 761 }
739 762
740 //putc (127 * gen.noise (vec2d (x * 0.01, y * 0.01)) + 128, stdout); 763 //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); 764 //putc (256 * gen.terrain2 (x * 0.004, y * 0.004, 8), stdout);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines