Shader works in scene space, but not screen-space canvas

I’m making a 2D game in Unity (2021.3.14f1). I’m using the Built-In Render Pipeline. I have this simple palette swap shader that works on anything in scene space (Sprite Renderers, Image/Text objects on world-space or camera-space canvases), but when I try to use it on an Image or Text object on a screen-space canvas, it just makes the object invisible.

I can’t just switch to a camera-space canvas, because this is for some UI stuff that uses UI masks, and UI masks don’t seem to work unless the canvas is in screen space.

I’m sure there’s a simple fix for this issue, but I can’t figure out what that might be. Any suggestions?

8703078–1174965–paletteSwap.shader (2.57 KB)

Hi! This is probably cause by ZTest mode us different in UI.
You can try to add this line code in your shader’s pass and check it work?

ZTest [unity_GUIZTestMode]

That did the trick! Thanks.