No need for a custom shader to do this. Set the texture itself to use Wrap Mode > Mirror and set the x Tiling on a material using the Standard shader to 2.
@codenamed52 did you figure it out? I’m trying to achieve the same result with UI Image. I have this shader but it doesn’t work with sprite atlas (it’s also better to replace if statements with clever math but I’m trying to get it to work first):
Depending on the sprite you’re using with the UI Image component, it might not be possible to (easily) solve with a shader. For example if your sprite is packed in an atlas (either by you importing an atlas manually, or setting the texture to be combined into an atlas by Unity), there’s absolutely nothing in the shader can do here without a lot of manual help from you. The UV position within an atlas are now completely arbitrary, and Unity doesn’t pass any of that information to the shader automatically, so you can’t rely on 0.0 being the left side of the texture, or 1.0 being the right, or 0.5 to be the center of the UI Image mesh. You have to pass all of that information to the shader yourself, which in the case of the automatic atlasing means having to extract the Sprite’s UV range at runtime with a custom script and pass those values to the shader.
The easiest solution to this is to not atlas any sprite you want to do this with, and to make sure it takes up the full range of the texture, no transparent edge at least where you want to mirror. And once you do that you can set the texture’s wrap mode to mirror and avoid needing a custom shader, though setting the UV scaling on UI materials is a bit of a pain since it’s hidden by default, but is possible.