I am trying to model my scene in light space as preperation of my shadow mapping, however I am massively confused.
The line that calculates the position in my shader: gl_Position = light_projection_matrix * light_view_matrix * light_model_matrix * position;
, where position is a model coordinate (equal to world coordinate in my case) given by 3 floats, I am reading it as vec4
and that part has proven to be working.
Now I use the following, coded in Java, for my matrices:
lightModelMatrix.identity().multiply(modelMatrix);
lightViewMatrix.identity().lookAt(new Vector3f(-20f, 7.5f, -20f), Vector3f.O, Vector3f.Y);
lightProjectionMatrix.identity().frustum(-1f, 1f, -1f, 1f, -200f, 200f);
Where modelMatrix
is identity()
I think that the issue is that the lookAt
matrix is changing the .w
component of my vector, I am not sure if that should be happening, I only know that the projection matrix must calculate a .w
component.
So this is the code for my lookAt
:
public Matrix4f lookAt(final Vector3f eye, final Vector3f at, final Vector3f up) {
Vector3f zAxis = at.subtract(eye).normalized();
Vector3f xAxis = up.cross(zAxis).normalized();
Vector3f yAxis = zAxis.cross(xAxis);
return multiply(
xAxis.getX(), xAxis.getY(), xAxis.getZ(), -xAxis.dot(eye), //X column
yAxis.getX(), yAxis.getY(), yAxis.getZ(), -yAxis.dot(eye), //Y column
zAxis.getX(), zAxis.getY(), zAxis.getZ(), -zAxis.dot(eye), //Z column
0.0f, 0.0f, 0.0f, 1.0f //W column
);
}
All matrices in my code are defined in column major order.
Also, what is a good way to debug the gl_Position
that gets calculated in the Vertex Shader to see if an issue is there?