Question by
z0code0z · Mar 09, 2019 at 02:39 AM ·
colortexture2dcolor changesetpixel
texture.setpixel is making a blend of colors instead of solid colors (help) (examples provided)
So i found a code from some other forum and i got it work on my own project (im going to use a slightly complex version of it but just for simplicity ill be showing that one)
It should be generating a solid SOMETIMES white and SOMETIMES black color on each pixel but instead it actually has a blend between black and white (along with some black and some white)
ive tested this with many other colors and the same happens with any color and any combination of colors (including more than 2 colors!)
im not sure what is causing this blend of colors but if someone could please help me, it would be greatly appreciated
CODE:
void ColorChanger()
{
Renderer rend = GetComponent<Renderer>();
Texture2D texture = new Texture2D(128 , 128);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
rend.material.mainTexture = texture;
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
Color pixelColour;
if (Random.Range(0, 2) == 1)
{
pixelColour = new Color(0, 0, 0, 1);
}
else
{
pixelColour = new Color(1, 1, 1, 1);
}
texture.SetPixel(x, y, pixelColour);
}
}
texture.Apply();
}
Comment