Terrain and place trees by black and white mask?

How can i use unity3d terrain and place trees by black and white mask?

I made script that create instantiate of tree and place it by using ray cast and mask. But when i scatter all terrain by trees, i have huge amount of object and it load the scene so long. I tried to use TerrainData.SetTreeInstance but i cant chage the position of TreeInstance.

can you show us the code?

normaly it should work with Terrain.AddTreeInstance