Search Unity

Is mat.GetTexture() bugged? It gives me a blurry image.

Discussion in 'Scripting' started by Deleted User, Apr 27, 2018.

  1. Deleted User

    Deleted User

    Guest

    I have a material with a 32x32 image of white and black pixels only, and nothing but white and black. The image is set to filtermode = Point, so each pixel appears nice and crisp in the image, when viewed in the material.

    But when I use Texture2D tex = mat.GetTexture("_MainTex") as Texture2D;

    ...and then attempt to examine the pixels using tex.GetPixels(), the pixels are blurry, they are not crisp.

    In other words, when I'm reading a pixel that close to a spot where both a white and a black pixel are nearby, it will often give me a pixel that's neither black nor white, but some shade of grey. Again, because the image is blurry, it's not using point filter anymore for some reason.

    I've tried setting tex.filtermode to point before reading the pixels, but that doesn't seem to change anything, it's still blurry.

    What's the matter, is this a bug? Where exactly is it forgetting that my texture is point filtered, and giving me a blurry picture instead? :(
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    Sounds like you might have mipmaps enabled on the texture, that's about the whole thing that would cause that I think (although GetPixels should return mipmap level 0). Maybe you've set the texture to be compressed too?