fCraft.Noise.PerlinNoise C# (CSharp) Method

PerlinNoise() public method

public PerlinNoise ( float x, float y, float z, int startOctave, int endOctave, float decay ) : float
x float
y float
z float
startOctave int
endOctave int
decay float
return float
        public float PerlinNoise( float x, float y, float z, int startOctave, int endOctave, float decay )
        {
            float total = 0;

            float frequency = ( float )Math.Pow( 2, startOctave );
            float amplitude = ( float )Math.Pow( decay, startOctave );

            for ( int n = startOctave; n <= endOctave; n++ ) {
                total +=
                    InterpolatedNoise( x * frequency + frequency, y * frequency + frequency, z * frequency + frequency ) *
                    amplitude;
                frequency *= 2;
                amplitude *= decay;
            }
            return total;
        }

Same methods

Noise::PerlinNoise ( float x, float y, int startOctave, int endOctave, float decay ) : float
Noise::PerlinNoise ( [ map, int startOctave, int endOctave, float decay, int offsetX, int offsetY ) : void
Noise::PerlinNoise ( [ map, int startOctave, int endOctave, float decay, int offsetX, int offsetY, int offsetZ ) : void

Usage Example

Example #1
0
        private void GenerateHeightmap()
        {
            ReportProgress(10, "Heightmap: Priming");
            heightmap = new float[args.MapWidth, args.MapLength];

            noise.PerlinNoise(heightmap, args.FeatureScale, args.DetailScale, args.Roughness, 0, 0);

            if (args.UseBias && !args.DelayBias)
            {
                ReportProgress(2, "Heightmap: Biasing");
                Noise.Normalize(heightmap);
                ApplyBias();
            }

            Noise.Normalize(heightmap);

            if (args.LayeredHeightmap)
            {
                ReportProgress(10, "Heightmap: Layering");

                // needs a new Noise object to randomize second map
                float[,] heightmap2 = new float[args.MapWidth, args.MapLength];
                new Noise(rand.Next(), NoiseInterpolationMode.Bicubic).PerlinNoise(heightmap2, 0, args.DetailScale,
                                                                                   args.Roughness, 0, 0);
                Noise.Normalize(heightmap2);

                // make a blendmap
                blendmap = new float[args.MapWidth, args.MapLength];
                int blendmapDetailSize = (int)Math.Log(Math.Max(args.MapWidth, args.MapLength), 2) - 2;
                new Noise(rand.Next(), NoiseInterpolationMode.Cosine).PerlinNoise(blendmap, 3, blendmapDetailSize, 0.5f,
                                                                                  0, 0);
                Noise.Normalize(blendmap);
                float cliffSteepness = Math.Max(args.MapWidth, args.MapLength) / 6f;
                Noise.ScaleAndClip(blendmap, cliffSteepness);

                Noise.Blend(heightmap, heightmap2, blendmap);
            }

            if (args.MarbledHeightmap)
            {
                ReportProgress(1, "Heightmap: Marbling");
                Noise.Marble(heightmap);
            }

            if (args.InvertHeightmap)
            {
                ReportProgress(1, "Heightmap: Inverting");
                Noise.Invert(heightmap);
            }

            if (args.UseBias && args.DelayBias)
            {
                ReportProgress(2, "Heightmap: Biasing");
                Noise.Normalize(heightmap);
                ApplyBias();
            }
            Noise.Normalize(heightmap);
        }