Search Unity

simple shader to scroll a texture produces odd line

Discussion in 'Shaders' started by blueskied, Dec 7, 2016.

  1. blueskied

    blueskied

    Joined:
    Dec 7, 2016
    Posts:
    12
    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;

     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    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.
     
    blueskied likes this.
  3. blueskied

    blueskied

    Joined:
    Dec 7, 2016
    Posts:
    12
    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.
     
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    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.
     
    blueskied likes this.