GLSL shader that scrolls the texture

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

+5
source share
1 answer
  • Setting the texture wrapping mode with

    glTexParameteri(TextureID, L_TEXTURE_WRAP_S, GL_REPEAT)

  • Add a floating shape with a name Timeto your texture shader

  • Use something like this texture2D(sampler, u + Time, v)when extracting a texture sample.

  • Update the formula Timeusing some timer in your code.

Here's the 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) );
}
+10
source

All Articles