I am trying to use SetPixel with a brush image that has a round brush shape with a transparent background. The code is below. When I run this, the brush shape displays but with a white background. The output values for the first pixel are listed below, which should be transparent(?) since a=0.0, but it appears white when rendered. Or am I misunderstanding something?
function testAlpha(){
var tex=Instantiate(renderer.material.mainTexture);
var pixels=brushTexture.GetPixels(0,0,brushTexture.width, brushTexture.height,0);
var outputString="";
for (var y : int = 0; y < brushTexture.height; ++y) {
for (var x : int = 0; x < brushTexture.width; ++x) {
var brushColor=brushTexture.GetPixel(x,y);
if(x==0){outputString+="brush color: "+brushColor+",";}
if(x==0){outputString+="old text color: "+tex.GetPixel(x, y)+",";}
tex.SetPixel (x, y, brushColor);
if(x==0){outputString+="new tex color: "+tex.GetPixel(x, y)+"|";}
}
}
Debug.Log(outputString);
renderer.material.mainTexture=tex;
tex.Apply();
}
brush color: RGBA(1.000, 1.000, 1.000, 0.000),old text color: RGBA(0.227, 0.459, 0.773, 1.000),new tex color: RGBA(1.000, 1.000, 1.000, 0.000)
I think there is a mistake here: newImage.SetPixel (cx+x, cx+y, newColor); it has to be newImage.SetPixel (cx+x, cy+y, newColor);
– brainoidgames