Shader program is not behaving properly

I created a shader that loops an image on itself. It responds properly in the editor. But when running in real time, it does perform properly for like 1 loop. The image scrolls downward immediately looping to the bottom part of the atlas image.

See the attached video for ref.
I have included the GUI shader fp code. Hopefully someone can find the issue as my eyes are tired. Thank you.

varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;

uniform lowp sampler2D texture_sampler;
varying mediump float var_strip_position;

void main()
{    
    //lowp vec2 uv = vec2(var_texcoord0.x, var_texcoord0.y - var_strip_position);   // Vertical 
    //uv = vec2(uv.x, mod(uv.y, 0.9375)); // Repeating vertically
    
    lowp vec2 uv = vec2(var_texcoord0.x - var_strip_position, var_texcoord0.y);     // Horizontal   
    uv = vec2(mod(uv.x, 0.9375), uv.y);   // Repeating horizontally 
    //uv = vec2(uv.x, uv.y);   // Repeating horizontally 
    gl_FragColor = texture2D(texture_sampler, uv) * var_color;
}

I think it would help if you could share a bare minimum project where this can be tested.

I can do that. I will post here shortly. Thanks.

1 Like

Her
My Project.zip (178.6 KB)
e is the project

I think I fixed it.

uniform highp mat4 view_proj;

// positions are in world space
attribute mediump vec3 position;
attribute mediump vec2 texcoord0;
attribute lowp vec4 color;

varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;
varying lowp vec2 var_strip;

void main()
{
    var_texcoord0 = texcoord0;
    var_color = vec4(color.rgb * color.a, color.a);
    var_strip = vec2(position.z, 0.0);
    gl_Position = view_proj * vec4(position.xy, 0, 1.0);
}

This line was causing the problem. I kept ā€œZā€ active in positioning when it should have been removed / omitted.

gl_Position = view_proj * vec4(position.xyz, 1.0);
3 Likes