I'm trying to create a shader that creates a displacement on an object, slicing horizontally the sprite.
These is an example of the atlas I'm using and the effect I'm trying to achieve:
I tried to achieve this creating a fragment shader, that would read the Y coordinate of the texcoord, and depending on the height, displace it horizontally.
But I found two main problems:
1) If my atlas had more rows of sprites, I can't really tell at what height I'm drawing the sprite in the fragment shader. Since values of texcoord go from 0 to 1 relative to the atlas being use, the more rows I have, the smaller values should I choose to create the horizontal cut. Is there any way to know the position inside the drawn?
2) The problem is similar to the previous point. When displacing the pixels horizontally, if the displacement is too big, I end up sampling the sprite next to the one being rendered. The idea is for it to loop back the the begining of the sprite. If I had the width of the sprite, I could tell how to do so, but using texcoord alone is just not posible. How can I do this?