I have VBOs to section off my world, kind of like in the game Diablo. I used to set the vertex data itself to the exact position within the world, but as the position grew, so did the floating point math errors.
I have now changed it so that the vertex data is relative to 0,0,0 and I am using glTranslatef to set each VBO to the correct location around the player.
glPushMatrix();
glTranslatef(m_X, m_Y, m_Z);
draw VBO
glPopMatrix();
This makes it so that the player's X and Z positions are always within the range 0-512(The physical size of 1 VBO) and as they leave it, the world shifts the opposite way. This works well and fixes the floating point errors, however it introduced a new error.
In my shader, I create a water waving like effect by taking the cos/sin of the X and Z positions of the vertex multiplied by the time variable and modify the Y position with them.
uniform float timeVar;
...
vec4 v = vec4(gl_Vertex);
v.y += (sin(v.x+timeVar*2)+cos(v.z+timeVar))*2-5;
...
gl_Position = gl_ModelViewProjectionMatrix * v;
This was working when the vertex positions were exact, but now I suspect they are within the range 0-512, as that is what they are all set to before I glTranslatef them to their actual positions. This makes the waves still appear, but now at the edges of the VBOs, the water is seperated since the cos(0) != cos(512).
Is there something I need to do in the shader to get the actual position of the vertex in the world?
Pass in the world position as a uniform.