OptiX - Motion blur with multiple key frames

Hi there, I am trying to use motion blur in Optix, working nicely for two key frames. Now, I’m trying to use it for multiple (non-uniformly sampled) key frames. Some thing s are not completely clear to me.
[1] I can set the time interval (e.g., [0,1]), but how can I set the time for a particular key frame?
[2] I set more than two transformations; however, it’s not working properly in my opinion. I tried three same transformations, but some artifacts appeared.
[3] I don’t understand why I have to set again the time interval and the number of key frames in OptixAccelBuildOptions as it is already set in OptixMatrixMotionTransform for individual nodes.

Thanks,

Now, I’m trying to use it for multiple (non-uniformly sampled) key frames.

That’s already the problem. OptiX doesn’t support non-uniform motion intervals.

Read the very first paragraph here: https://raytracing-docs.nvidia.com/optix7/guide/index.html#acceleration_structures#motion-blur

“Motion blur is supported by OptixMatrixMotionTransform, OptixSRTMotionTransform and acceleration structure traversables. Several motion blur options are specified in the OptixMotionOptions struct: the number of motion keys, flags, and the beginning and ending motion times corresponding to the first and last key. The remaining motion keys are evenly spaced between the beginning and ending times.

That links to the older OptiX 6.5 Programming Guide for more information about how the motion indices are assigned to times:
https://raytracing-docs.nvidia.com/optix6/guide_6_5/index.html#motion_blur_math#motion-blur

You would need to resample your animation steps into evenly spaced key frames.

[1] I can set the time interval (e.g., [0,1]), but how can I set the time for a particular key frame?

You can’t. They need to be evenly spaced.

[2] I set more than two transformations; however, it’s not working properly in my opinion. I tried three same transformations, but some artifacts appeared.

What kind of artifacts? (Screenshot?)

Please always provide your system configuration when asking about OptiX issues:
OS version, installed GPU(s), VRAM amount, display driver version, OptiX (major.minor.micro) version, CUDA toolkit version (major.minor) used to generate the input PTX, host compiler version.

There had been a bug when using more than two key frames which was solved in more recent drivers.
Please update to the newest available display driver for your configuration and try again.

What kind of motion did you apply? Linear, SRT, or geometry.
When using SRT, mind that rotations between two key frames must not exceed 180 degrees or the rotation will not be around continuous directions (means the rotation axis can flip).

When using OptiX versions before 7.2, you were responsible for providing AABBs covering that movement of your instances. Because OptiX 7.2 removed that requirement I would recommend using that when implementing motion blur. It makes things much easier.
See this comment in my intro_motion_blur example (which is using only two keys from animation frame to animation frame):
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/intro_motion_blur/src/Application.cpp#L1780

[3] I don’t understand why I have to set again the time interval and the number of key frames in OptixAccelBuildOptions as it is already set in OptixMatrixMotionTransform for individual nodes.

That’s required because each OptixMatrixMotionTransform could have a different setting and the builder needs to know how it should resample the underlying motion intervals if they differ.

Don’t overdo it with the number of key frames. That will require additional memory.

Thank you for the prompt reply!

[2] I didn’t copy the whole struct with additional matrices (third and so on). My bad. Now, it’s working properly.

[3] I still don’t understand. For example, if I have two nodes: one with 3 frames and one with 2 frames both in [0,1]. How should I set OptixAccelBuildOptions?

[3] For example, if I have two nodes: one with 3 frames and one with 2 frames both in [0,1]. How should I set OptixAccelBuildOptions?

Set it to 3 to keep the animation with 3 motion steps working.
The one with 2 will be interpolated to 3 key frames internally.

I have not tried what happens exactly if you set the build options to 2 frames only.
I don’t expect that to result in the expected motion since it won’t be able to handle the middle key frame correctly or maybe there is even a validation error.

You’re on the safe side when not mixing animations with different numbers of key frames.
For different numbers than 2 (begin end end key for identical intervals are always reached), the other exact key frame locations would only be interpolated perfectly when using the smallest multiple of the individual animation sub-interval numbers plus one.
I mean when you have an animation with 3 and 4 key frames, the interpolation would only hit all key frame locations exactly when using 7 keys in the builder (Edit: Corrected, see explanation below), and that’s why I said don’t overdo it.
I would try to keep these animations in the lowest number of key frames possible because that saves memory.

Depending on the use case, it might not make sense to encode the whole animation into the motion transforms at once, but like in my small example set them for the duration of one animation frame, e.g. 1/24 of a second, where you might get away with 2 or 3 key frames.

Explanation for the 7 key frames in the builder above:
In a time interval [0, 1] with 3 key frames, there are two sub-intervals of length 1/2 and key times are 0/2, 1/2, 2/2.
For 4 key frames the are thee sub-intervals of length 1/3 and key times are 0/3, 1/3, 2/3, 3/3.
Means you need 6 sub-intervals with length 1/6 to hit these and that gives 7 key frames at times
0/6, 1/6, 2/6 = 1/3, 3/6 = 1/2, 4/6 = 2/3, 5/6, 6/6
Or as formula with key frames n, m: numKeyframes = (n - 1) * (m - 1) + 1
With n = 3 and m= 4 that gives 7 for this case.
That also works for the 2 and 3 keyframe case which gives (2 - 1) * (3 - 1) + 1 = 3.
That’s obviously not necessary when the number of sub-intervals(!) are multiples of each other Then take the bigger one. For example , like 2 or 3 and 6 sub-intervals, means animations with 3 or 4 and 7 key frames where 7 is the necessary number of key frames covering all three already as shown above.