Search Unity

What does _TextureSampleAdd do?

Discussion in 'Shaders' started by Lex-DRL, May 14, 2018.

  1. Lex-DRL

    Lex-DRL

    Joined:
    Oct 10, 2011
    Posts:
    140
    The question is in the title.
    There's already a similar thread with no replies, but it's in a wrong forum section and is obviously dead.

    I can't find a meaning of the "_TextureSampleAdd" shader variable. It's documented nowhere.
    I see that in the default UI shaders it's a 4d vector and that it simply offsets a texure's RGBA values.
    But why is it used in the 1st place? What is it used for? What does it do when it's added?

    It's very important to understand it's purpose for any non-Alpha-blended UI shaders. E.g., for additive or multiply blend modes.
    I'm really confused at which stage I need to use _TextureSampleAdd and how exactly.
     
    Last edited: May 14, 2018
  2. Lex-DRL

    Lex-DRL

    Joined:
    Oct 10, 2011
    Posts:
    140
    Bump? Any info? Please? :(
     
  3. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

    Joined:
    Jun 9, 2017
    Posts:
    328
    Code line from some UI shaders:

    fixed4 _TextureSampleAdd; //Added for font color support
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    Hi!
    This is set automatically by the engine based on whether the texture being used for the UI is in Alpha8 format or not. If it is, it's set to (1,1,1,0), otherwise it's (0,0,0,0).
     
  5. Lex-DRL

    Lex-DRL

    Joined:
    Oct 10, 2011
    Posts:
    140
    @aleksandrk Thanks a lot!
    In other words, if I handle Alpha8 texture myself, I don't need it at all.

    I was woindering it's purpose since it appeared (like, since 5.x). And now I can safely remove it.

    I guess, this info could be added to official docs.
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,025
    > this info could be added to official docs
    I'll put it on my todo list :)
     
  7. hiwarp

    hiwarp

    Joined:
    Oct 26, 2016
    Posts:
    8
    Hello there.
    Sometimes after build all my UI texts becomes black. Other UI components (like images) using the same materials works fine, so I ended up since '_TextureSampleAdd' seems the only variant. Recompiling shaders solve the problem but is not a very straight forward solution. Is there any permanent fix? I'm on 2019.4, but this issue was present over the years and several editor versions.