I am experimenting with ray marching, and have been following Jamie Wong's tutorial.
When the moving the camera section comes, they use the function
mat4 viewMatrix(vec3 eye, vec3 center, vec3 up) {
vec3 f = normalize(center - eye);
vec3 s = normalize(cross(f, up));
vec3 u = cross(s, f);
return mat4(
vec4(s, 0.0),
vec4(u, 0.0),
vec4(-f, 0.0),
vec4(0.0, 0.0, 0.0, 1)
);
}
To generate a matrix that can be used to transform the direction vector so that the camera looks at the right object.
I wanted to move the matrix calculation out of the shader though, since it would be a better fit as a uniform, and so I did, but OpenTK's function Matrix4.LookAt()
produces very different results, and I'm not sure how to apply them to the ray with the simple multiplication that Jamie's function gave.
I have confirmed that the matrix is being loaded into the uniform correctly, it just doesn't apply to the direction vector in the same way.
Edit: I am aware that I can translate Jamie Wong's function from GLSL into C#, but I want to know the correct usage of Matrix4.LookAt.