I'm trying to create a modelview projection matrix for my shader like this:
I'm getting the matrix for the camera translation:
public Matrix4 GetMatrix()
{
return Matrix4.LookAt(Position, LookingAt, Vector3.UnitY);
}
Postition is the current position of the camera, LookingAt is the target of the camera.
Now I'm assmbling the final matrix for the shader and passing it:
Matrix4 cameraMatrix = camera.GetMatrix();
Matrix4 mvprojectionMatrix = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, 16f / 9f, 1f, 30f) * cameraMatrix;
GL.UniformMatrix4(mvprojectionMatrixAttribute, false, ref mvprojectionMatrix);
This is the vertex shader (pass through)
[Shader vertex]
#version 150 core
in vec3 pos;
in vec3 color;
uniform float time;
uniform vec3 offset;
uniform mat4 cameraView;
uniform mat4 projection;
out float vTime;
out vec3 vColor;
out mat4 vProjection;
void main() {
gl_Position = vec4(pos, 1.0);
vColor = color;
vTime = time;
vProjection = projection;
}
I'm passing this to the geometry shader where I'm using them to position my vertices:
void makeVertex(vec3 shift, mat4 rotation)
{
gl_Position = (gl_in[0].gl_Position + vec4(shift, 0.0) * rotation) * vProjection[0];
EmitVertex();
}
the rotation matrix is simply a local rotation of the vertex. vProjection[0] comes from the vertex shader...
Somehow if the camera moves, stuff will quickly leave the view frustum, but the actual view does not move. So I assume the modelview matrix is wrong ( does not translate from camera to world space ). But I'm not sure how to create the correct matrix.
Any tips ? Thanks.