滚动纹理的 GLSL 着色器 [英] GLSL shader that scroll texture
本文介绍了滚动纹理的 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?
推荐答案
使用设置纹理环绕模式
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 着色器:
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) );
}
这篇关于滚动纹理的 GLSL 着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文