public void ApplyTerrain()
        {
            //build arrays for shader
            int n = data.Length;

            Color[] colours         = new Color[n];
            float[] colourStrengths = new float[n];
            float[] startHeights    = new float[n];
            float[] blendStrengths  = new float[n];
            float[] textureScales   = new float[n];
            for (int i = 0; i < n; i++)
            {
                colours[i]         = data[i].tint;
                colourStrengths[i] = data[i].drawAsColour ? 1 : data[i].tintStrength;
                startHeights[i]    = data[i].startHeight;
                blendStrengths[i]  = !data[i].blendEnabled ? 0 : data[i].blendStrength;
                textureScales[i]   = data[i].textureScale;
            }

            TerrainMat.SetInt("_DataCount", n);

            TerrainMat.SetColorArray("_DataColours", colours);
            TerrainMat.SetFloatArray("_DataColourStrengths", colourStrengths);
            TerrainMat.SetFloatArray("_DataStartHeights", startHeights);
            TerrainMat.SetFloatArray("_DataBlendStrengths", blendStrengths);
            TerrainMat.SetFloatArray("_DataTextureScales", textureScales);
            TerrainMat.SetFloat("_MaxHeight", TerrainGenerator.Instance.heightMultiplier);

            ApplyDesaturation();

            ApplyWater();
        }
        private void ApplyDesaturation()
        {
            var maxDist = Mathf.Max(TerrainGenerator.Instance.mapSize.x, TerrainGenerator.Instance.mapSize.y) * desaturationDistance;

            TerrainMat.SetFloat("_MaxDistance", maxDist);
            TerrainMat.SetFloat("_MaxDesaturation", desaturationStrength);

            var propHandler = FindObjectOfType <PropPopulator>();

            if (propHandler == null)
            {
                return;
            }

            foreach (var prop in propHandler.props)
            {
                foreach (var mat in prop.prefab.GetComponent <MeshRenderer>().sharedMaterials)
                {
                    mat.SetFloat("_MaxDistance", maxDist);
                    mat.SetFloat("_MaxDesaturation", desaturationStrength);
                }
            }
        }