Search Unity

UV's animation vertex program

Discussion in 'Shaders' started by AviB, Dec 22, 2019.

  1. AviB

    AviB

    Joined:
    Jan 28, 2014
    Posts:
    22
    Hi,

    I'm experiencing weird issues related to texture sampling of animated uvs.
    Basically I have a simple frame based animation for the uvs which I have done many times before
    on the vertex program. Recently, I have noticed a visual issues when using this kind of shader.

    Here is the animation code:

    v.texcoord /= NUM_FRAMES_PER_ROW;
    float2 vAnimXY = floor(_Time.yy*float2(NUM_FRAMES, NUM_FRAMES_PER_ROW)) * RAME_UV_SIZE;
    v.texcoord.xy += vAnimXY;

    When I move the uvs animation code from the vertex to the fragment program, the results are correct ,please advise.

    Vertex animation:


    Fragment animation:


    I'm using Unity 2019.2.16f1

    Thank you very much.
     

    Attached Files:

  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    Does that happen in the editor? What precision are the UVs you are passing to frag?
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Try this:
    v.texcoord.xy += frac(vAnimXY);


    I suspect it’s an issue with the UV range getting large enough you’re starting to see floating point errors in the interpolated UVs. This isn’t an issue when doing it in the fragment since the floating point error is constant.
     
  4. AviB

    AviB

    Joined:
    Jan 28, 2014
    Posts:
    22
    Hi,

    Thank you very much.
    the frac command did the trick!