Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Completely confused - color values 254 and 255 map to 1.0?

Discussion in 'Shaders' started by diablo, Dec 9, 2012.

  1. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    I figured the color value 255 = 1.0, 0 = 0.0, and all other values fall somewhere in between. For testing purposes I created a simple gradient texture that ranges from 0,0,0,0 to 255,255,255,255 (RGBA). In my shader (using strumpy editor) I Tex2D the sample texture, Split the RGBA out to separate components, and then I Step (ie. compare) the X to the value 1.0 (255) and output that to emission. What this does is simply check the red channel to see if it is a 1.0 (255) and if it is then render it, otherwise render black. I expect to see every part of my gradient rendered black *except* for the last portion of the gradient which is 255,255,255,255. Instead, I see both 255 AND 254 portions of my gradient showing up! What the funk???!!! Do both values 254 and 255 map to 1.0????

    edit : I just did more testing and it seems as if every 2 color values (ie. 0 1, 2 3, ... , 254 255) map to the same floating point range! This can't be right so either I must be doing something very wrong or Strumpy has a bug.
    .
     
    Last edited: Dec 9, 2012
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    What precision of data types are you using, float, half, fixed?
     
  3. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    I'm using Strumpy's Float4Const, so I presume it's float.
     
  4. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    Ok I found out that the compression settings on the texture affected the rendering. When I have my png set to automatic compressed I was getting the nonsense i wrote about above, but when I set manually to ARGB32 it worked fine.