GLSL shader that scroll texture

那年仲夏 提交于 2019-12-18 13:36:07

问题


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?


回答1:


  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) );
}


来源:https://stackoverflow.com/questions/10847985/glsl-shader-that-scroll-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!