Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question In 2D, how to give sprite a different texture transparency?

Discussion in 'Shader Graph' started by devildev00, Apr 26, 2023.

  1. devildev00

    devildev00

    Joined:
    Mar 28, 2023
    Posts:
    5
    I am using URP 2D. Currently if I use UV node then it can make the sprite transparent like this image A. However, if I use my own texture, in the preview it looks like it's suppose to but then in editor or during runtime, it doesn't work, like in image B. How do I use my own texture as the alpha for any sprite?

    Image A
    faded.png


    Image B
    not.png
     
  2. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    57
    This setup works for me, make sure the transparent texture you are feeding has the proper R value, because it is the one setting the alpha in your second shader graph. If you want to use the alpha channel of the transparency texture, feed in the A channel instead.
     
  3. devildev00

    devildev00

    Joined:
    Mar 28, 2023
    Posts:
    5
    feeding A channel will do nothing and make the preview a full yellow block, same with in editor. Are you saying my image B setup works for you in your editor? I'm on unity 2021.3.21f1. Do you know why it works in preview but not in editor for me? What does proper R value mean?
     
  4. rob11

    rob11

    Joined:
    Mar 7, 2017
    Posts:
    57
    Yes, setup B works for me. What I mean by proper R value is that you are feeding a Vector4 (RGBA) in a float node. So it takes the R channel only. So the alpha will be based on the Red value of the texture. Which should be fine with a black and white texture. in 2021.3.0
     
  5. devildev00

    devildev00

    Joined:
    Mar 28, 2023
    Posts:
    5
    The real reason is I did not drag the texture2d into it in editor. I did not understand that inside shader graph, what it simulates is the "default" texture you choose for that property. That's why it never affect the change in editor. In editor, you need to drag it in. The only texture that it automatically knows is the MainTex. Also what tripped me up was UV node made it work but not otherwise making me think it was simply me doing the nodes wrong. I think the fact that you told me it works for you made me think it must be my settings somehow. Thank you for taking the time to set it up on your side to try it.
     
    rob11 likes this.