fCraft.Noise.ScaleAndClip C# (CSharp) Method

ScaleAndClip() public static method

public static ScaleAndClip ( [ data, float steepness ) : void
data [
steepness float
return void
        public static unsafe void ScaleAndClip( [NotNull] float[,] data, float steepness )
        {
            if ( data == null )
                throw new ArgumentNullException( "data" );
            fixed ( float* ptr = data ) {
                for ( int i = 0; i < data.Length; i++ ) {
                    ptr[i] = Math.Min( 1, Math.Max( 0, ptr[i] * steepness * 2 - steepness ) );
                }
            }
        }

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);
        }