public static float[,] BoxBlur( [NotNull] float[,] heightmap )
{
if ( heightmap == null )
throw new ArgumentNullException( "heightmap" );
float[,] output = new float[heightmap.GetLength( 0 ), heightmap.GetLength( 1 )];
for ( int x = heightmap.GetLength( 0 ) - 1; x >= 0; x-- ) {
for ( int y = heightmap.GetLength( 1 ) - 1; y >= 0; y-- ) {
if ( ( x == 0 ) || ( y == 0 ) || ( x == heightmap.GetLength( 0 ) - 1 ) || ( y == heightmap.GetLength( 1 ) - 1 ) ) {
output[x, y] = heightmap[x, y];
} else {
output[x, y] = ( heightmap[x - 1, y - 1] * 2 + heightmap[x - 1, y] * 3 + heightmap[x - 1, y + 1] * 2 +
heightmap[x, y - 1] * 3 + heightmap[x, y] * 3 + heightmap[x, y + 1] * 3 +
heightmap[x + 1, y - 1] * 2 + heightmap[x + 1, y] * 3 + heightmap[x + 1, y + 1] * 2 ) * BoxBlurDivisor;
}
}
}
return output;
}