Search Unity

How to use Alpha from color?

Discussion in 'Shaders' started by Rachan, Sep 11, 2021.

  1. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    781
    Hi there!

    I have a Properties in my 2D sprite shader

    Properties{
    _Color ("Tint", Color) = (0, 0, 0, 1)
    _MainTex ("Texture", 2D) = "white" {}
    }

    you can see _Color for property just for change a color of object
    But how to use alpha value from this color?

    in frag shader

    fixed4 frag(v2f i) : SV_TARGET{
    fixed4 col = tex2D(_MainTex, i.uv);
    float blender = _Color.a; <---- I really want to use _Color.a add to float blender
    return col;
    }

    this is possible?
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,792
    Use it for what?

    You're already "using it", you're assigning it to the float blender and then doing nothing with it.
     
    Rachan likes this.
  3. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    781
    Ok Thanks you very much But I know how it work already!
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,792
    I'm confused on what the issue it then :) Or do you mean you figured it out?
     
  5. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @Rachan when you solve your problem it would be polite to tell here how you did it. This way others can benefit from the answer when they are searching a solution to a similar issue. After all, this is not a "work for free" forum where you get free consultation and delete the thread after your problem got sorted out.
     
  6. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    781
    Actually I just use that variable by just call
    float blender = i.color.a;

    I use alpha of a color and then it ok now