Search Unity

Shader stop working when using packed texture

Discussion in 'Shaders' started by bali33, Dec 3, 2019.

  1. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    139
    Hello,

    I have this Sprite shader that works great. I decided to packed the texture inside a SpriteAtlas in order to enjoy better format/compression. But even with "CanUseSpriteAtlas"="True" the shader has stopped working.

    Is there something special I should do ?

    Thanks
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,694
    If your shader makes use of the 0.0 to 1.0 UV range for something, expecting those values to be the corners of the sprite mesh, then it won't work with an atlased sprite. When using a SpriteAtlas, the sprite is packed into a larger texture, which means the sprite mesh's UVs are no longer guaranteed to be in that nice 0.0 to 1.0 range from one edge to the other. The only real solution is not to use a sprite atlas for shaders that need that strict UV range.
     
  3. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    139
    Hello,

    Thanks for the explanation, at least I have a beginning of understanding of what is going on. Is there a way to know/compute the actual range and then maybe compute a scale factor to applied in the shader ?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,694
    Sadly, no.