Hi,
I’m trying to do a simple thing: take an original texture put on a Quad and then draw new pixels at certain positions.
The problem is that when I do this the texture becomes all grey and the pixels drawn seem to have a strange blurring effect.
The code is the following:
MeshRenderer meshRenderer = quad.GetComponent<MeshRenderer>();
texture = new Texture2D(meshRenderer.material.mainTexture.width, meshRenderer.material.mainTexture.height);
meshRenderer.material.mainTexture = texture;
texture.SetPixel(0, 0, Color.red);
texture.SetPixel(1, 0, Color.red);
texture.SetPixel(2, 0, Color.red);
texture.Apply();
Look at images:
Original 800x600
After set pixels:
I don’t understand the problem! Please help.
Thanks.
rarac
2
you need to change the settings on the texture, set it to filtermode point, no compression ettc
amiga4K
3
Yes, this is the problem but I also missed getting the original pixels… 
Below the code:
MeshRenderer meshRenderer = quad.GetComponent<MeshRenderer>();
texture = new Texture2D(meshRenderer.material.mainTexture.width, meshRenderer.material.mainTexture.height, TextureFormat.RGBA32, false);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
texture.SetPixels(((Texture2D)meshRenderer.material.mainTexture).GetPixels());
texture.Apply();
meshRenderer.material.mainTexture = texture;
for (int y = 0; y < 200; y++)
{
for (int x = 0; x < 800; x++)
{
texture.SetPixel(x, y, Color.clear);
}
}
texture.SetPixel(0, 0, Color.red);
texture.SetPixel(1, 0, Color.red);
texture.SetPixel(2, 0, Color.red);
texture.Apply();
And below the results:
Many thanks for your help!!!