Motion blur with pbrt
I added a new blurred camera to pbrt to implement motion blur. I used two algorithms to interpolate the camera from timestep 0 at camera shutter open to timestep 1 at camera shutter close. Camera positions are defined at timestep 0 and 1. The camera position at 0 is retrieved from the scene file in the normal way, but the position at 1 is hardcoded for right now. The module could be easily extended to get a matrix or three LookAt vectors from the camera definition in the scene file.
The two algorithms I used to interpolate the camera are linear interpolation of the elements of the two transformation matricies and quaternions. The linear interpolation is a naive approach, since it does not take into account the geometry involved in the matrices. The second method I implemented was spherical linear interpolation using quaternions. This produced better results, but for camera positions that are close to eachother, the difference is not very significant.
The spherical linear interpolation code itself is pretty easy. The challenging part of the lab was converting the rotation matrix into a quaternion and converting the slerped quaternion back into a rotation matrix form that pbrt could understand. After looking through different references with slightly different conversion formulas, I finally found a combination that worked. A bizzare bug fix in my code involved the third row of my converted matrix being the wrong sign. I couldn't find the reason for this and ended up just flipping the signs for that row afterward.
Quaternion slerp(float t, const Quaternion &q1,
const Quaternion &q2) {
float cos_o = dot(q1, q2);
float o = acos(cos_o);
return (sin( (1-t)*o )/sin(o))*q1
+ (sin( t *o )/sin(o))*q2;
}
I also needed to add a hack to get the matrix information out of the Transform object. There is probably a more elegant way to do this, but I got frustrated with pbrt and added this member function to the Transform class:
inline const float* getMatrix() const {
return (float*)(m->m);
}
Here is a link to my blurred camera class.