private void CutHoles(Terrain terrain, float threshold) {
    var td = terrain.terrainData;
    bool[,] holes = new bool[td.holesResolution, td.holesResolution];
    int holeCount = 0;
    for (int x = 0; x < td.holesResolution; x++) {
        for (int y = 0; y < td.holesResolution; y++) {
            float height = td.GetInterpolatedHeight((float)x / td.holesResolution, (float)y / td.holesResolution);
            holes[x, y] = height < threshold;
            holeCount += holes[x, y] ? 1 : 0;
        }
    }

    td.SetHoles(0, 0, holes);
}