滚动纹理的GLSL着色器 [英] GLSL shader that scroll texture

查看:97
本文介绍了滚动纹理的GLSL着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在平面上滚动纹理? 因此,我有一个带有纹理的平面,可以使用着色器从其上的纹理(从右到右)(无限)向左滚动吗?

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)

将名为Time的浮动制服添加到纹理着色器中

Add the float uniform named Time to your texturing shader

在获取纹理样本时使用texture2D(sampler, u + Time, v)之类的东西.

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

使用代码中的某些计时器更新Time制服.

Update the Time uniform using some timer in your code.

这是GLSL着色器:

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

这篇关于滚动纹理的GLSL着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆