simple shader to scroll a texture produces odd line

Hi! New to shader programming. Trying to scroll a sprites texture (up - down).
It works but there’s this odd line artifact appearing at the place where the texture flips over to beginning (Y=0).
The code: OffSetY = 0 to 1

fixed4 frag(v2f IN) : SV_Target
{
float xpos = IN.texcoord[0];
float ypos = IN.texcoord[1] - OffSetY;
if (ypos < 0) {
ypos += 1;
}
fixed4 c = SampleSpriteTexture(float2(xpos,ypos)) * IN.color;
c.rgb *= c.a;
return c;

I’m guessing that’s because the sprite is packed with other sprites and the filtering shows pixels from the next sprite.

If you use a simple texture instead that is set to repeat, you can just sample it with tex2D without this artifact.

1 Like

Thanks for the hint. It’s just a single sprite. I found out that setting filtering to Point (no filter) instead of Bilinear solved the problem.

Setting filtering to point also always works in these case. Even though it’s a single sprite, it probably still gets packed into a sprite sheet. If only to make it power of two in size.

1 Like