Convolution() public method

Convolution matrices!
public Convolution ( double filter, double divisor, double offset, int X, int Z ) : void
filter double
divisor double
offset double
X int
Z int
return void
Example #1
0
        /// <summary>
        /// Smooths below-water surfaces and, optionally, adds beaches.
        /// </summary>
        /// <param name="waterlevel">
        /// A <see cref="System.Single"/>
        /// </param>
        /// <param name="beaches">
        /// A <see cref="System.Boolean"/>
        /// </param>
        /// <returns>
        /// A <see cref="Channel"/>
        /// </returns>
        public void Silt(double waterlevel, bool beaches, int X, int Z)
        {
            // 1. Copy Image
            // 2. Apply gauss blur to lower layer
            // 3. Bring back unblurred terrain from above the water level.

            int x_o = X * (int)ChunkScale.X;
            int z_o = Z * (int)ChunkScale.Z;

            double wl = (beaches) ? waterlevel + 6d : waterlevel;

            wl = wl / 256f;

            // Gaussian blur for silt and beaches.
            double[][] gaussian_matrix = new double[3][] {
                new double[3] {
                    1, 2, 1
                },
                new double[3] {
                    2, 4, 2
                },
                new double[3] {
                    1, 2, 1
                }
            };
            IMapHandler Blurred = this;

            Blurred.Convolution(gaussian_matrix, 32f, waterlevel / 2d, X, Z);

            for (int x = 0; x < ChunkScale.X; x++)
            {
                for (int z = 0; z < ChunkScale.Z; z++)
                {
                    // If > WL: use unblurred image.
                    // If <=WL: Use blurred image.
                    if (GetPrelimHeightAt(x + x_o, z + z_o) <= wl)
                    {
                        SetPrelimHeightAt(x + x_o, z + z_o, Blurred.GetPrelimHeightAt(x + x_o, z + z_o));
                    }
                }
            }
        }