I’m trying to achieve this result :

It’s all about filling part of a texture, and I had met two problems:
First is modifying a texture pixels alpha, which i achieved with texture.SetPixel but it was just too slow, that’s when I did it with a shader, who receives the mouse position and changes the alpha of the pixels around.
This leads us to the second problem, i can’t find a way to save the modified pixels alpha (The drawn parts).
here’s my current shader:
Shader "Custom/DrawPainting"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_MousePos ("MousePos", Vector) = (-1,-10,-1,-1)
_Radius ("HoleRadius", Range(0.1,5)) = 2
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
CGPROGRAM
#pragma surface surf Lambert alpha:blend
#pragma target 3.0
sampler2D _MainTex;
float4 _MousePos;
float _Radius;
struct Input
{
float2 uv_MainTex;
float3 worldPos;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
float dx = length(_MousePos.x-IN.worldPos.x);
float dy = length(_MousePos.y-IN.worldPos.y);
float dz = length(_MousePos.z-IN.worldPos.z);
float alpha = (dx*dx+dy*dy+dz*dz) / _Radius;
alpha = clamp(alpha,0,1);
if(alpha == 1)
alpha = 0;
else
alpha = 1;
o.Albedo = c.rgb;
o.Alpha = c.a * alpha;
}
ENDCG
}
}
I would be very grateful if anyone has any suggestions.