2D Outline ShaderGraph Help

Hey everyone. I’ve been trying to follow this Brackeys tutorial on sprite outlining and I have been getting some really strange results despite following the beginning part of the tutorial exactly.

While I understand the basics of shaders I’m more or less a complete beginner to them so it’s very possible I’m doing something wrong. I also notice that in the Brackeys tutorial they are using an older version of shader graph so it’s possible Unity changed some things in the interim which is causing things to no longer work the way they should. The biggest change I can see is the new shader graph master node.

Essentially here are my issues.

  • I’m getting a strange darker portion to the right of my texture when I try to add the outline (only 1 side at this point) to the original texture.
  • The color I’m setting for my outline looks to change when I’m adding it back to the original texture.

Any help would be greatly appreciated! Thanks in advance!

P.S. My Unity version is 2020.3.12f1 & URP version is 10.5.0

ShaderGraph

What I Expect To See

Your first problem is caused by something that is actually not noticable in his video - when you subtract alpha values, the range of values is not [0…1], but [-1…1], however node preview is clamping values between 0 and 1 and it cannot be seen (you can put the result of substraction into remap and you will notice what I mean). Later you add this value to the image, and you get the outline where you wanted, but at the same time on the other side there are negative values and this is why you get this darker area.

The second problem was actually mentioned later in video, as you can see the texture has blue color around green land, this is because texture has color set to something even if alpha is zero. If green area had black background everywhere around then it would work, becuase it would mean you add black (zero) to your color, so the result is your color, but in this case you added orange and blue.

The first problem can be fixed by clamping value to 01, before you add it to something else (clamp or saturate node), and the other one by premultiplying color by alpha (like he did later) or you can lerp between outline and the image color, or you can prepare texture in the way it has black where alpha is zero