From f45655bcca57e3e9ee62b3b81443b5c8fe229889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 31 Jan 2024 11:04:06 +0100 Subject: [PATCH] Fix quaternion slerp in camera paths --- dependencies/tiny-cuda-nn | 2 +- include/neural-graphics-primitives/camera_path.h | 2 +- include/neural-graphics-primitives/common_device.cuh | 3 +-- src/camera_path.cu | 10 ++++++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dependencies/tiny-cuda-nn b/dependencies/tiny-cuda-nn index 6f018a9cd..235d1fde9 160000 --- a/dependencies/tiny-cuda-nn +++ b/dependencies/tiny-cuda-nn @@ -1 +1 @@ -Subproject commit 6f018a9cd1b369bcb247e1d539968db8e48b2b3f +Subproject commit 235d1fde956dc04966940f9d1bec66aa3bdb705a diff --git a/include/neural-graphics-primitives/camera_path.h b/include/neural-graphics-primitives/camera_path.h index c3530e912..a151f98f3 100644 --- a/include/neural-graphics-primitives/camera_path.h +++ b/include/neural-graphics-primitives/camera_path.h @@ -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); } diff --git a/include/neural-graphics-primitives/common_device.cuh b/include/neural-graphics-primitives/common_device.cuh index 88c56c599..c082edc61 100644 --- a/include/neural-graphics-primitives/common_device.cuh +++ b/include/neural-graphics-primitives/common_device.cuh @@ -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) { diff --git a/src/camera_path.cu b/src/camera_path.cu index 02e33a57d..159f0fabc 100644 --- a/src/camera_path.cu +++ b/src/camera_path.cu @@ -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, @@ -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 @@ -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); } }