How can I make this shader not consider neighboring sprites?

Godot Version

4.2.1

Question

I am trying to make a simple outline shader to add black outlines around the sprites in my project. My sprites are all 8x8 in actual pixels, and come from sheets where they are packed together. I have been able to find shaders online that are made for this, but all of them have the issue of considering neighboring sprites from the sheet. This causes unwanted effects, as shown in the provided screenshots. The gray feet from the above sprite are visible at the top of the skeleton sprite’s head.



Here are a few shaders I’ve found that produce the same incorrect result:

I don’t have much experience with shaders, so I’m not sure what I should do. It seems that the solutions would either be edit the shader so it pretends the surrounding pixels are blank, or convince godot to treat the sprite as a standalone image before the shader is applied. I’m not sure how to accomplish either of these, though. The same issue happens whether using sprite frames with an AnimatedSprite2D (screenshot above) or an atlas texture with a regular Sprite2D. All of my textures are packed closely together this way, so manually separating them would involve many hours of work.

Simplest (but inefficient) way to do this is to put your sprite under a canvas group and apply the stock outline shader to the canvas group

Having trouble trying this solution on account of the following (from CanvasGroup — Godot Engine (stable) documentation in English):


I’ve tried to combine the outline shader’s code with the code provided by that screenshot, but it doesn’t work. I can only produce the following:

The outline shader needs to go on the canvas group

Putting the outline shader as the canvas group’s material does not work, as described and shown above. It overrides the canvas group’s built in shader, effectively removing any rendering of its children. Is there something else you mean by “go on”?

Sorry, in the screenshot you sent it’s unclear how you combined your shader with the outline shader and put it on the canvas group.