Procedurality.Channel.silt C# (CSharp) Method

silt() public method

Smooths below-water surfaces and, optionally, adds beaches.
public silt ( float waterlevel, bool beaches ) : Channel
waterlevel float /// A ///
beaches bool /// A ///
return Channel
		public Channel silt(float waterlevel,bool beaches)
		{
			// 1. Copy Image
			// 2. Apply gauss blur to lower layer
			// 3. Bring back unblurred terrain from above the water level.
			
			// Copy heightmap
			Channel orig,newh,blurred;
			orig=newh=blurred=this;
			
			float wl=(beaches) ? waterlevel+5f:waterlevel;
			wl=wl/256f;
		
			// Gaussian blur for silt and beaches.	
			float[][] gaussian_matrix=new float[3][]{
				new float[3]{1f,2f,1f},
				new float[3]{2f,4f,2f},
				new float[3]{1f,2f,1f}
			};
			blurred=this.convolution(gaussian_matrix,32f,waterlevel/2f);
			blurred=blurred.HeightClamp(waterlevel-(0.1f/256f));
	
			for(int x=0; x < this.getWidth(); x++)
			{
				for(int y=0; y < this.getHeight(); y++)
				{
					// If > WL: use unblurred image.
					// If <=WL: Use blurred image.
					if(newh.getPixel(x,y)>wl)
						newh.putPixel(x,y,newh.getPixel(x,y));
					else
						newh.putPixel(x,y,blurred.getPixel(x,y));
				}
			}
			return newh;
		}