Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL shader that scroll texture

How to scrolling a texture on a plane? So I have a plane with a texture, can I use a shader to scroll left from right (infinite) the texture on it?

like image 738
lacas Avatar asked Jun 01 '12 09:06

lacas


1 Answers

  1. Setup the texture wrapping mode using

    glTexParameteri(TextureID, L_TEXTURE_WRAP_S, GL_REPEAT)

  2. Add the float uniform named Time to your texturing shader

  3. Use something like texture2D(sampler, u + Time, v) while fetching texture sample.

  4. Update the Time uniform using some timer in your code.

Here's a GLSL shader:

/*VERTEX_PROGRAM*/

in vec4 in_Vertex;
in vec4 in_TexCoord;

uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix;

out vec2 TexCoord;

void main()
{
     gl_Position = ProjectionMatrix * ModelViewMatrix * in_Vertex;

     TexCoord = vec2( in_TexCoord );
}

/*FRAGMENT_PROGRAM*/

in vec2 TexCoord;

uniform sampler2D Texture0;

/// Updated in external code
uniform float Time;

out vec4 out_FragColor;

void main()
{
   /// "u" coordinate is altered
   out_FragColor = texture( Texture0, vec2(TexCoord.x + Time, TexCoord.y) );
}
like image 136
Viktor Latypov Avatar answered Oct 09 '22 11:10

Viktor Latypov