I have a LWJGL project and ran into a problem with a vertex shader I wrote. In my scene I am rendering a map whose ground consists of rectangular tiles. On top of that there are other objects (I used tiny white balls here). Here is a screenshot of my scene:
You can also click here to see the image.
Each of the four larger rectangles at the bottom is one huge quad drawn in one piece. Every one of them contains four coordinates (the corners: top-left, top-right, bottom-right, bottom-left). Their interior is filled with a texture.
The small white balls on top are single game objects each drawn by itself. Note that I aligned them with the vertical edges of the underlying rectangles.
I used the following vertex shader to render the scene:
/* default shader */
#version 120
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Now imagine the scene getting covered with water. I modified the shader adding a little water effect:
/* water shader */
#version 120
uniform float amplitude;
uniform float phase;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
// transform x
vec4 a_position = gl_Vertex;
a_position.x = a_position.x + amplitude * sin(phase + a_position.x);
gl_Position = gl_ModelViewProjectionMatrix * a_position;
}
An animated image of my scene can be found here or here.
You can see that the borders of the rectangles keep aligned with the white balls on top of them. However, vertices inside the rectangles (I marked the most distinct areas red) suffer a displacement relative to the white balls. In the last rectangle you can even see the balls cross the white line in the middle.
I need the interior of my textured rectangles to be transformed exactly like the white balls on top and move uniformly when being animated by my shader. Please let me know if my problem is clear and if any other information is needed.
Thank you very much for your help. Greetings Xoric