示例#1
0
        public static byte PerlinNoise(Vector3 pos, double densityDivisor, int seed)
        {
            PerlinNoise perlinNoise = new PerlinNoise(seed);

            //Vector3 warp;
            //warp.X = (float)perlinNoise.Noise(pos.X * 0.004, pos.X * 0.004, pos.X * 0.004);
            //warp.Y = (float)perlinNoise.Noise(pos.Y * 0.004, pos.Y * 0.004, pos.Y * 0.004);
            //warp.Z = (float)perlinNoise.Noise(pos.Z * 0.004, pos.Z * 0.004, pos.Z * 0.004);
            //pos += warp * 8;

            double widthDivisor = 1 / (double)densityDivisor / 2;
            double heightDivisor = 1 / (double)densityDivisor * 3;
            double depthDivisor = 1 / (double)densityDivisor / 2;
            double v =
                // First octave
                (perlinNoise.Noise(2 * pos.X * widthDivisor, 2 * pos.Y * heightDivisor, -2 * pos.Z * depthDivisor) + 1) / 2 * 0.7 +
                // Second octave
                (perlinNoise.Noise(-8 * pos.X * widthDivisor, 4 * pos.Y * heightDivisor, 8 * pos.Z * depthDivisor) + 1) / 2 * 0.2 +
                // Third octave
                (perlinNoise.Noise(16 * pos.X * widthDivisor, 8 * pos.Y * heightDivisor, -16 * pos.Z * depthDivisor) + 1) / 2 * 0.1;

            // generate a sphere
            //float rad = 30;
            //float dist = rad - (pos - new Vector3(0, rad, 0)).Length();
            //dist = dist.Scale(0, rad, 0, 0.5f);
            //v = dist + v;

            // clamp to 0 - 1
            //v = Math.Min(1, Math.Max(0, v));
            v = MathHelper.Clamp((float)v, 0, 1);
            byte density = (byte)(v * 255);

            return density;
        }
示例#2
0
        public static byte PerlinNoise(Vector3 pos, double densityDivisor, int seed)
        {
            PerlinNoise perlinNoise = new PerlinNoise(seed);
            double widthDivisor = 1 / (double)densityDivisor;
            double heightDivisor = 1 / (double)densityDivisor;
            double depthDivisor = 1 / (double)densityDivisor;
            double v =
                // First octave
                (perlinNoise.Noise(2 * pos.X * widthDivisor, 2 * pos.Y * heightDivisor, -2 * pos.Z * depthDivisor) + 1) / 2 * 0.7 +
                // Second octave
                (perlinNoise.Noise(4 * pos.X * widthDivisor, 4 * pos.Y * heightDivisor, 2 * pos.Z * depthDivisor) + 1) / 2 * 0.2;
                // Third octave
                //(perlinNoise.Noise(8 * pos.X * widthDivisor, 8 * pos.Y * heightDivisor, 2 * pos.Z * depthDivisor) + 1) / 2 * 0.1;

            // clamp to 0 - 1
            v = Math.Min(1, Math.Max(0, v));
            byte density = (byte)(v * 255);
            return density;
        }