I have a problem that I believe is due to floating point errors on the CPU.
I'm currently working on shadowmaps and at first I had the MVP calculations on the GPU e.g
layout(location = 0) in vec3 inPos;
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
void main(void)
{
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(inPos, 1.0);
}
This is not all the shader code obviously, but these calculations got the following result:
Then I wanted to optimize the code a bit and move the MVP calculations to the CPU and pass it to the shaders as a uniform like so:
uniform mat4 MVP;
layout(location = 0) in vec3 inPos;
void main(void)
{
gl_Position = MVP * vec4(inPos, 1.0);
}
These are the results:
I have been looking at my CPU matrix multiplications for a few hours now so I'm >90% certain that everything is correct there.
I give a container class the matrices with set-functions and retrieve them with a single getter.
void setModelMatrix(const glm::mat4& inModelMatrix){mModelMatrix = inModelMatrix;};
void setViewMatrix(const glm::mat4& inVewMatrix) {mViewMatrix = inVewMatrix;};
void setProjectionMatrix(const glm::mat4& inProjectionMatrix){mProjectionMatrix = inProjectionMatrix;};
//Calculates the MVP matrix and returns it
glm::mat4 getMVPMatrix() {
return (mProjectionMatrix * mViewMatrix * mModelMatrix);
}
So.. any ideas on what might be the problem? Could it be floating point errors? Thanks for any and all replies!