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:
    139
    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:
    139
    Bump? Any info? Please? :(
     
  3. Przemyslaw_Zaworski

    Przemyslaw_Zaworski

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

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

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,172
    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).
     
    LwHappyGame, Noisecrime and Lex-DRL like this.
  5. Lex-DRL

    Lex-DRL

    Joined:
    Oct 10, 2011
    Posts:
    139
    @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:
    2,172
    > this info could be added to official docs
    I'll put it on my todo list :)
     
unityunity