Hey all,
I’m trying to change the alpha values of a grayscale texture based on some conditions. Essentially if the color value is within some min and max threshold, set the alpha to 0.8, and if it is not within the thresholds, set it to 0 (unable to see) alpha.
Here’s my code so far:
Texture2D UpdateThresholdTexture(Texture2D tex)
{
Texture2D texture = new Texture2D(tex.width, tex.height);
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
Color color = tex.GetPixel(x, y);
bool min = color.grayscale >= minThresh;
bool max = color.grayscale <= maxThresh;
if (min && max)
{
color.a = 0.8f;
texture.SetPixel(x, y, color);
}
else
{
color.a = 0f;
texture.SetPixel(x, y, color);
}
}
}
texture.Apply();
return texture;
}
At the moment it’s just returning the original texture. Could someone point me in the right direction?