Outline shader "cropped" and material not editable

Hii, I’m a beginner so please bear with me.
I’m making a shader that makes an outline on my sprites, I finally got almost everything working but can’t figure out these last few issues.


Firstly, the outline gets cropped off past the orange selection line. I don’t really know how to fix this, I’ve tried making the transparent space around the image bigger in my image file but the selection line stays the same size.




Secondly, when I created the shader graph, it came with a material attached that I can’t uncouple. Despite the strength and color being editable, and showing up in the inspector, I can’t actually edit them. I can only go back into the shader graph editor and edit them in there…

I was also under the impression that _MainTex would allow this shader to apply to any sprite, and take the sprite it was applied to as its main texture, but if I put the material on any other sprites, it just puts this heart arrow sprite in its place. Not sure where I missed a step or if I just have to duplicate and change the image input for every sprite I have.

https://www.youtube.com/watch?v=Tvsom00IAOs < here is the tutorial I followed.
I’m on version 2022.3.46f1

Any help would be much appreciated!

Regarding your second issue, this is the normal behavior of the Shader Graph asset. The associated material just shows the default values of the exposed parameters for your shader. If you intend to change the defaults, you should right click on the Shader Graph asset and select Create->Material. That will create a material asset that you can then assign to your mesh and edit the parameters.

Regarding your first issue, try setting your sprite mesh type to rect instead of tight in the inspector.

Hi ! Unfortunately, it doesn’t seem to change anything. Do you have any other suggestions? (Or am I doing something wrong?)


Ah thank you! I didn’t realise it was just showing the default.

Does the sprite have transparent pixels around every edge?

No, it’s currently cropped right to the edge of the sprite.

Ideally no pixels should be touching the edges. It should work if that’s the case. Otherwise, I did manage to make an outline shader graph that was able to support edge pixels, I can go through the basic logic of it in a bit when I have my project open on my PC

1 Like

So the way I did it roughly is something like this:

I scaled the vertex up by a factor of 2 and then scaled the UV down by the same factor of 2. This basically adds more space around the edges of the sprite rect so that you can draw the outline pixels in that space. For the UV, the offset value is just 0.5, but for the position, it depends on the resolution of the sprite.

To scale up and down, you will first need to offset both the position and the UV, so that 0 is the mid-point, and then do the reverse offset after multiplying / dividing. You may also need to handle scaled UVs that are <0.25 and >0.75 if you do this, by always outputting 0 alpha, but I’m not sure if that’s necessary.

Ah, I thought I tried it before, but giving some space around the edges did work this time! Thank you so much!

1 Like

You’re welcome! You probably tried it before when the mesh type was still set to tight, which is why it didn’t work. Tight mesh type basically crops out unnecessary transparent areas automatically.