I’m a little confused when using the vertex shader. I’m trying to displace each vertex point of my mesh from the vertex shader program using cos(rad), but when I do, all vertices are moved at the same time. I’m guessing this is because the GPU processes all vertex points in parallel?
How am I able to move individual vertex points so I can create something like a 2D or 3D Sinewave? Eventually I’m aiming to make something like this, but I just can’t figure out how to move individual vertices from the shader:
Thanks very much in advance and sorry for such a newbie question. I’ll also share my vertex shader code so you know what I’ve tried:
By the way, I know the following code won’t generate that sombrero looking pattern, I was just testing
glDrawArrays(GL_POINTS, 0, 100 * 100); will invoke the program 100 x 100 times
int x = gl_VertexID % 100;
int y = gl_VertexID / 100;
so you can define the 2D position at the ground
glDrawArrays(GL_POINTS, 0, 100 * 100); will invoke the program 100 x 100 times
int x = gl_VertexID % 100;
int y = gl_VertexID / 100;
so you can define the 2D position at the ground[/QUOTE]
John, I’m pretty sure this is what I’m looking for, is this feature available in WebGL/GLSL1.0? I tried the modulo % operator but unfortunately it doesn’t work in glsl 1.0 only GLSL 3.0 and >. So I might have to use the mod function according to some articles on Stack Overflow when using WebGL.
Update:
Nevermind, I found gl_VertexID You can’t use it with WebGL 1.0, but it’s definitely in WebGL 2.0. I found it on the 2.0 spec reference card. Sadly though, WebGL 2.0 is still not in every browser, only 28.71% global reach, compared to WebGL 1.0’s 92.07%. I’ll try coming up with a WebGL 1.0 alternative.