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)?
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: