Search Unity

GetPixel not getting correct color for PSD and PNG. TARGA ok

Discussion in 'Scripting' started by friken, Jul 14, 2009.

  1. friken

    friken

    Joined:
    May 1, 2009
    Posts:
    84
    Context: iphone unity though I'm pretty sure this would affect non iphone as well. 2D engine using texture mapped planes, no lighting, particle-alphablended.

    I am using GetPixel() for a 2d pixel perfect collision and using different colors to denote different collision types. It works really well but I'm having an issue with Unity not returning the correct RGB. As a test I created a texture in photoshop of rgb 128,128,128. A quick calculator of it 128/255=0.5019 (Unity 0-1 float for color). The getpixel returns 0.42 or 109 in 0-255 notation. I get this result if the file is PSD or PNG. I tried a targa thinking maybe it is the file itself and it worked Unity returns 128 (0.5019).

    Any idea why this would be? How to fix it? I can't use taga as I need 32bit with alpha. Ideally I'd like to use png as it maintains a better AA for transparancy (aas against edge color instead of white like psds do.