Skip to content

Commit

Permalink
Fix quaternion slerp in camera paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom94 committed Jan 31, 2024
1 parent be449a7 commit f45655b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/neural-graphics-primitives/camera_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct CameraKeyframe {
int glow_mode;
float glow_y_cutoff;
mat4x3 m() const {
auto rot = to_mat3(normalize(quat(R)));
auto rot = to_mat3(normalize(R));
return mat4x3(rot[0], rot[1], rot[2], T);
}

Expand Down
3 changes: 1 addition & 2 deletions include/neural-graphics-primitives/common_device.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ inline NGP_HOST_DEVICE mat4x3 camera_slerp(const mat4x3& a, const mat4x3& b, flo

inline NGP_HOST_DEVICE mat4x3 get_xform_given_rolling_shutter(const TrainingXForm& training_xform, const vec4& rolling_shutter, const vec2& uv, float motionblur_time) {
float pixel_t = rolling_shutter.x + rolling_shutter.y * uv.x + rolling_shutter.z * uv.y + rolling_shutter.w * motionblur_time;
return camera_log_lerp(training_xform.start, training_xform.end, pixel_t);
// return camera_slerp(training_xform.start, training_xform.end, pixel_t);
return camera_slerp(training_xform.start, training_xform.end, pixel_t);
}

inline NGP_HOST_DEVICE void apply_quilting(uint32_t* x, uint32_t* y, const ivec2& resolution, vec3& parallax_shift, const ivec2& quilting_dims) {
Expand Down
10 changes: 8 additions & 2 deletions src/camera_path.cu
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CameraKeyframe lerp(const CameraKeyframe& p0, const CameraKeyframe& p1, float t,
}

return {
slerp(p0.R, R1, t),
normalize(slerp(p0.R, R1, t)),
p0.T + (p1.T - p0.T) * t,
p0.slice + (p1.slice - p0.slice) * t,
p0.scale + (p1.scale - p0.scale) * t,
Expand All @@ -50,6 +50,12 @@ CameraKeyframe lerp(const CameraKeyframe& p0, const CameraKeyframe& p1, float t,
};
}

CameraKeyframe normalize(const CameraKeyframe& p0) {
CameraKeyframe result = p0;
result.R = normalize(result.R);
return result;
}

CameraKeyframe spline(float t, const CameraKeyframe& p0, const CameraKeyframe& p1, const CameraKeyframe& p2, const CameraKeyframe& p3) {
if (0) {
// catmull rom spline
Expand All @@ -67,7 +73,7 @@ CameraKeyframe spline(float t, const CameraKeyframe& p0, const CameraKeyframe& p
float b = (3.f*ttt-6.f*tt+4.f)*(1.f/6.f);
float c = (-3.f*ttt+3.f*tt+3.f*t+1.f)*(1.f/6.f);
float d = ttt*(1.f/6.f);
return p0 * a + p1 * b + p2 * c + p3 * d;
return normalize(p0 * a + p1 * b + p2 * c + p3 * d);
}
}

Expand Down

0 comments on commit f45655b

Please sign in to comment.