How to texture paint with brush texture alpha value in runtime

Does anyone know how to paint with a texture brush? My code works but only in a square shape…I would like to add different brush textures like the terrain script. But I don’t know how to filter the alpha value of a brush texture.

var plane : GameObject; //original color   
    var spraytest : GameObject; //Target color
    function Start () {
    var texture : Texture2D = Instantiate(plane.renderer.material.mainTexture); 
    plane.renderer.material.mainTexture = texture;

    var spraytexture : Texture2D = Instantiate(spraytest.renderer.material.mainTexture);
    var TargetColor : Color[]=spraytexture.GetPixels(0,0,spraytexture.width/2, spraytexture.height);
texture.SetPixels (0, 0, spraytexture.width/2, spraytexture.height, TargetColor, 0);
texture.Apply( );


TexturePaint on the asset store will do what you want. If you have a special case, you could also use the source code from it for your needs. texture paint will work on the gpu or cpu.