How to find the position of a sprite inside a sprite atlas? [Shader graph] [sprite atlas]

I wrote a gradient shader using shader graph. It works fine when the sprite is on its own. But when the sprite gets packed into a sprite atlas, the shader will try to color the entire atlas instead of just the sprite, thus breaks at run time. I have found a texture size node, but I can’t position the gradient to the right position inside the sprite atlas if i don’t know where the sprite is located inside the sprite atlas.

My thoughts was to find the sprite assigned to [_MainTex] of an ui element, inside the sprite atlas its packed into, then off set my gradient to match position and size of the sprit inside the sprite atlas.


can someone help me solve this problem? Is my logic wrong? is there a better way to make gradient work in this context?

any help will be much apricated.

Here is my shader so far. It works for a stand alone sprite.

anyone has any ideas? help please?