Search Unity

Resolved Shader issue with 2D sprites and background

Discussion in 'Shaders' started by xDayhawk, Jan 23, 2021.

  1. xDayhawk

    xDayhawk

    Joined:
    Jun 24, 2020
    Posts:
    57
    Hi,

    I'm kind of a newbie when it comes to Shaders, i'm pretty sure i'm missing something very simple but i cant seemt to find an answer in forums, i dont really know how to explain my issue so it makes it harder to search for solutions.

    I'm working on a simple 2D project, i want to add glow to different materials and i cant see to do it with URP.

    This is what i'm doing, i've created a simple "electric" line, very basic white, hard white, all background is transparent of course:
    upload_2021-1-23_10-50-14.png
    Its using the basic 2D lit default shader from URP:
    upload_2021-1-23_10-50-52.png

    Now, i tried creating a very basic Shader to add some glow to it before i turn on Bloom (the screenshots above are without bloom), i tried to keep it as simple as possible, just a different color, didnt even use a color param:
    upload_2021-1-23_10-51-33.png

    as soon as i apply this to my Material, this is what i'm getting:
    upload_2021-1-23_10-52-18.png

    I've tried a lot of settings, and it might be something very simple i'm missing, but its driving me crazy!!!

    I'm using:
    * Unity - 2020.2.0f1
    * Shader graph - 10.2.2

    All the guides and everything do not cover 10.2.2, or the new 2020.2.0f1 with all the changes it has, so its really hard to find solutions :(

    Thanks in advance,
    (please be gentle, i'm a shader newbie)
     
    Bumpty likes this.
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    Right now ShaderGraph has no way to get the MainTex and its alpha. That's why it looks like that.

    What you need to do is create a Texture2D on the Blackboard, name it "MainTex" and its Reference to "_MainTex". Unity uses this to pull the texture from the sprite. Then, you can add a Sample Texture2D and sample from your MainTex. Connect the sampler's alpha to the alpha of the Fragment output.
     
  3. xDayhawk

    xDayhawk

    Joined:
    Jun 24, 2020
    Posts:
    57
    Oh, Thank you!!!!
    That solved it :)

    Do i need to also use a multiply node for the color param i have, and the color from the texture?

    btw, do u know any good shader graph tutorials by any chance?
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    That's often what people want, but you don't have to in the case where you want a solid red color.
    There's lots of good stuff on YouTube. Find some neat effects you want. Follow along. Do that enough times and you'll develop an intuition for it to create your own.