对使用数组着色的着色器进行动画处理
所以我有一种锯齿形图案,如下所示。,它是由以下片段着色器创建的
uniform float time;
varying vec2 texture_coord;
void main()
{
float wav[10] = float[10](0,.1,.2,.1,0,-.1,-.2,-.1,0,.1);
//gl_FragColor = gl_Color;
float mod_time = mod(time, 1);
float x_pos = mod(texture_coord.x, 1.1);
float x_pos2 = x_pos * 10;
int index = int(x_pos2);
if(texture_coord.y < .5 + wav[index])
gl_FragColor = vec4(.7,.3,.3,1.0);
else
gl_FragColor = vec4(.3,.3,.3,1.0);
}
:我想通过让之字形向上移动来制作动画。
我的问题是,考虑到我正在使用数组来创建与中位数的偏移量,我将如何做到这一点?我不太确定如何调整数组,以便在下一个动画步骤中,数组看起来像 (.1,.2,.1,0,-.1,-.2,-.1,0, .1)?
So I have a sort of zigzag pattern, as shown below., which is created by the following fragment shader:
uniform float time;
varying vec2 texture_coord;
void main()
{
float wav[10] = float[10](0,.1,.2,.1,0,-.1,-.2,-.1,0,.1);
//gl_FragColor = gl_Color;
float mod_time = mod(time, 1);
float x_pos = mod(texture_coord.x, 1.1);
float x_pos2 = x_pos * 10;
int index = int(x_pos2);
if(texture_coord.y < .5 + wav[index])
gl_FragColor = vec4(.7,.3,.3,1.0);
else
gl_FragColor = vec4(.3,.3,.3,1.0);
}
which I would like to animate by having the zigzag move upwards.
My question is, how would I do this, considering that I'm using an array to create the offset from the median? I'm not exactly sure how I would adjust the array so that in the next animation step, the array looks like (.1,.2,.1,0,-.1,-.2,-.1,0,.1)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种方法可以做到这一点。您可以为数组中的偏移设置动画(可能是最简单的),也可以为数组本身设置动画。您已经传入了一个时间参数,因此您可以使用它,如下所示:
或者您可以传入数组。要传入数组,您只需获取数组第一个元素的统一位置,然后将其递增以获取后面的值。因此,在源代码中,您可以执行以下操作:
片段着色器:
源代码:
There are 2 ways you could do it. You can either animate the offset into the array (probably the easiest) or you can animate the array itself. You're already passing in a time parameter, so you could use that, like so:
Or you could pass in the array. To pass in an array, you simply get the uniform location of the first element of the array, and increment it for later values. So in your source code, you could do this:
Fragment Shader:
Source Code: