I've gotten back to making lwjgl games, and I'm trying to make a sort of wave type vertex shader. I call this to make it wave:

    // t is a float that gets updated every frame.

    fac = sin(t+gl_VertexID);

    gl_Position = gl_ModelViewProjectionMatrix * ( gl_Vertex + vec4(0.0, fac/10, 0.0, 0.0)  );

When I run the program, though, it outputs like this:

enter image description here

The individual vertices are moving, which is great, what I want, but they aren't connected to eachother, so each triangle is separated from one another. How do I fix this without changing the GL11.glBegin(GL11.GL_TRIANGLES) to GL11.glBegin(GL11.GL_TRIANGLE_STRIP)? Or do I have to?

  • \$\begingroup\$ If you want this to behave as a wave, would you not want to use the vertex position as the offset to the sine function's phase, rather than its ID? \$\endgroup\$
    – DMGregory
    Sep 16 at 1:38
  • \$\begingroup\$ @DMGregory if I use gl_Vertex.y, it controls all y values of the vertices, but only changes it by one singular value, which is the sine functions value in the phase \$\endgroup\$
    – Pale_Gray
    Sep 16 at 3:38
  • \$\begingroup\$ Right, and then you add time to make the wave move. If that's not your desired outcome, you may want to explain what output you want in more detail than "wave type vertex shader" \$\endgroup\$
    – DMGregory
    Sep 16 at 10:57
  • \$\begingroup\$ @DMGregory I don't want it to wave like that, but rather wave like a vertex displacement, move the vertices in a way where it will look like this. Do I have to use GL_TRIANGLE_STRIP instead of GL_TRIANGLES? \$\endgroup\$
    – Pale_Gray
    Sep 16 at 18:17
  • \$\begingroup\$ No, that will not make different vertices share the same ID. Vertex ID is not what you want here. You might instead be looking for some type of noise function acting on the vertex position in world space. That way all vertices that coincide at a specific location get the same noise value output. \$\endgroup\$
    – DMGregory
    Sep 16 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.