2D shader graph color problems

Hey so I’m making a shader graph in URP for a 2D sprite texture outline. I’ve got it mostly working but I’m having trouble changing the outline color.

So I used a multiply node shown here to change the color of the outline I have made and then I add it to the original sample texture.

Now this works with lighter, brighter colors BUT when I set the outline color to black or any other darker color, the outline just becomes transparent, which I don’t want.

Lighter colors like white + bright red show the outline (I have checked all of this in game just showing it on the shader graph for ease):


Darker colors like black + dark purple for example don’t show the outline??:


This has been giving me a headache all day now, please can someone help me out, thanks.

so have u tested the black outline with a sprite that doesnt have a black outline by default? Its easy to see on your sprite that you might just be confusing the already existing outline with the new

try your shader on a white square sprite for example and check the results ( u must leave transparent margins on the texture for outline space)

1 Like

none of my sprites have a black outline by default but I did try my shader on a white square sprite like you suggested and I got even stranger results.

The outline doesn’t show at all and I think this is to do with the sprite being completely white because when I change the tint color on the sprite renderer the outline faintly shows but only if the tint is around the same color as the color I have set for the outline? So it’s clear I need to change how I’m setting the color of the outline but I still don’t know how I’m going to be able to do that.

Outline on the white square doesn’t show when the outline color is set to bright red (it does show on other sprites that don’t contain only white, I think this maybe the issue?)
8938599--1225932--OnPaste.20230410-063844.png
8938599--1225938--OnPaste.20230410-064200.png

If I change the tint of the sprite renderer slightly to more to red the outline very faintly shows:
8938599--1225935--OnPaste.20230410-064050.png

Both are using the same material + shader graph, and the issue still applies to the sprites that show the bright colors (the ladder); that when the outline color is set to darker colors the outline just becomes transparent.

Thanks for the reply.

did you make the square with a lot of room to display the outline? Try out these sprites:

8938722--1225962--Untitled-1.png8938722--1225965--Untitled-2.png
if the outline still looks transparent the problem might be the operation that you are performing to mix the colors (multiply)

For one last check can you try reversing up your multiply node?

put the outline color on node A and the subtract out on node B

1 Like

yes I did make the square with a lot of room to display, and I tried your sprites and it gave these results when I set the outline color to a bright orange.
8938968--1226001--OnPaste.20230410-095502.png
It shows on the red, but not the white.

And I have tried many times reversing the multiply node hoping it would do something haha, but unfortunately no difference :frowning:

can you try to make the white square black, what happens then?

Hi anikataylor,

are you able to share the sample project and unity version?

thanks

Ive got to say that Im stumped aswell. It seems that the add node is not appropriate for this? For example with a blue square if you add a red color it turns pink. The addition of the alpha channels also turns out wonky. Theres something about these squares that completely breaks the shader. Its wacky because with a “normal” sprite it kinda works as expected but when you use a solid color square it becomes completely wacky.

1 Like

black square works fine:
8941746--1226652--OnPaste.20230411-210242.png

yeah it’s very confusing lol, I’m guessing it’s something to do with the alpha channel in the shader graph because the issues are concerning transparency of the outline when the color is set to darker colors (for “normal” sprites as you put it at least…), but I’m no expert I’m just getting the hang of shader graphs and I just want this silly outline to work.

unfortunately I won’t be able to share the sample project, the unity version is 2021.3.16f1 (so after the 2020 shader graph update that separated Alpha and Base Color in the master node if that means anything). Is there any other information I can provide for some help to get this working? Thanks for your response.

maybe something to give a try, try replacing all your “ADD” nodes with blend nodes, and on the dropdown of blend select “overwrite”

the idea is that the operation performed is not mixing colors

(wondering if this at least fixes the results on the white square)

thanks for the info, in that case are able to share just the shader graph file? It will help to reproduce issue on my side.

1 Like

thanks for the idea but when I did this my sprites either just completely disappear (this happens with all the squares) or only show small broken up parts of the sprite, so it is clear that this doesn’t work and only puts me backwards. I changed all the Add nodes to Blend nodes with the overwrite option.

can see what happens with the alternative options from the blend node? For example “Overlay”

yes of course, I put it in a Google drive link since it doesn’t allow me to add them here:
https://drive.google.com/drive/folders/1a0F17OF0PVbjySAxovAiyf7MtpigGsbd?usp=share_link

This will only work for a project using URP I believe so if it’s not working that may be the issue, also the outline thickness should probably be changed to a larger number if you can’t see the outline sometimes!

I’ve messed around with the blending options for a bit now and get very strange and weird behaviour, I did set all the options to Overlay as well and this caused all my sprites to turn black, so I believe a different approach is required.

If you like you can try it out yourself using the link I sent. Thanks anyways.

1 Like

has anyone got a fix for this problem yet, because I’ve been on this for days now and I still can’t find a fix…

There is this dirty fix was the best that i could do

you duplicate the object and place it as a child, and put the shader only on the child, then a normal shader on the original

8950881--1228848--Untitled.png

im sure there is a cleaner solution to add the outline directly on the original sprite and not have to use a duplicate maybe @MaxwellTan can show a way

I post the current outline only shader too:

8950881–1228845–outlineONLY.zip (12.9 KB)

1 Like

I’ve finally found a way to solve this problem by adding a few more extra nodes before adding both the original texture to the outline color if anyone is interested:


However for some reason most of my sprites end up having jaggedy pixelly edges, even when the outline thickness is set to 0, don’t know if this is an anti-aliasing problem or what. Please can someone help me out if they know thank you.

When outline thickness is set to 0.1 and color is set to black.
8953761--1229493--OnPaste.20230416-231944.png

When outline thickness is set to 0:
8953761--1229496--OnPaste.20230416-232041.png

(this happens with all colors btw)