How can I use OptiX6.5 to achieve dynamic model deformation and real-time ray tracing

Let’s say I have a ball in the scene, and I change the vertices of the ball through the code, and I have periodic deformations, like zoom in, zoom out, zoom out.
What should we do about this?
How does BVH refresh in real time when the vertices of the model change?
I wonder if there’s an API that can do that?
How to dynamically update bvh in a dynamically changing obj model in optix? and whether it affects performance?

The OptiX 6.5.0 SDK actually contains an example called optixDynamicGeometry showing how to do that.

Please read the OptiX Programming Guide on accelerations structure builds:
Note the acceleration structure “refit” property.

Please also have a look into these threads:

I would not do that in OptiX 6.5.0 anymore. The host API to change data and update transforms is simply not modern enough.
OptiX 7 (with version 7.1.0 released two days ago) has a much better interface to do these dynamic updates directly in CUDA, where you could calculate the animation directly or simply update the data with a simple host-to-device CUDA memcpy if you have the animation available on the host.
For rigid animations you could even update all instance transform matrices via CUDA before the acceleration rebuild. In OptiX 6 that would require as many API calls as there are instances.

So I have two questions right now, the first is can we load a 3D model in OptiX, and then dynamically deform the model by changing the vertices of its model?
The second question is can the OptiX engine perform ray tracing computation in this case?
Please do not recommend OptiX7.0 or later, I am using OptiX6.5.
The graphics card is RTX2060.

Hi there, the answer to both questions is yes, and Detlef shared some resources for achieving your goals with OptiX 6.5. The optixDynamicGeometry sample in the OptiX 6.5 SDK demonstrates moving instances around. Updating a mesh is the same idea, you need to first upload the new mesh to the GPU (or better yet update the verts directly in a GPU buffer using CUDA-interop), and then rebuild or refit the acceleration structure associated with that mesh as well as update the parent acceleration structure if the outer bounds of the mesh changed.

There are several other old threads here on the forum about how to achieve fast enough updates for real time using OptiX 6.5. The first link here in particular has some information about how to minimize your update times.

Please do not recommend OptiX7.0 or later, I am using OptiX6.5.

We understand that OptiX 7 is a big change for you. Please also understand that OptiX 7 is by far the best answer to your question, and we would not be doing our jobs if we didn’t recommend it. OptiX 6.5 was not designed for real-time use, and OptiX 7 is designed for real-time. OptiX 7 will give you complete control over memory transfers to the GPU and partial scene updates, which are the most important factors in a real-time design.

If you are just starting a new real-time project from scratch, it is likely to take you a long time anyway, and you are likely to have difficulty optimizing (as you can see in the threads Detlef and I have linked to). We want to give you the best advice possible, which is why we advise re-considering the use of OptiX 7. I apologize for doing exactly what you requested we don’t do, so please forgive me, and please understand the entire reason for OptiX 7’s existence and backward-incompatible design choices is to answer the very question you are asking. Many people before you have asked the same question. It is difficult in OptiX 6.5 and earlier to achieve real-time updates with scenes of medium to high complexity, and we worked hard to fix this exact problem with OptiX 7. Please consider that you may end up spending more time trying to achieve real-time updates in OptiX 6.5 and being frustrated than it would take to learn and build your project with OptiX 7.

Please don’t be mad at me. :) Think about it, and if OptiX 6.5 remains your choice we will be here and continue to do our best to help you achieve real-time updates.


Ok, thank you very much for your reply.
I now know that OptiX7 might be a better fit for my needs.
However, according to the requirements of the task, it is impossible to transfer the whole project to OptiX7 in a short time, because the gap between 7 and the old version is too large, and OptiX’s learning resources are too few and not well-documented (I think this is a serious problem).
I’m running the DynamicGeometry Sample, but I don’t see any Dynamic change in this Sample application. Why is that?

The optixDynamicGeometry example actually contains code to show both affine transform matrix updates and geometry vertex position updates.
Please have a look into the functions SeparateAccelsLayout::updateGeometry() resp. RebuildLayout::updateGeometry().

Please use --help on all OptiX SDK examples to get their command line options and additional usage hints.
In this case the SPACE key triggers the animation “space Translate a randomly chosen mesh” and key “r Reset scene”.

The default command line option is to animate the transforms and rebuild the top-level acceleration structure.
You can also load own OBJ models and print the time to update acceleration structure.

Looks like the vertex buffer update path is currently not working in that example.
That complained about an rtGeometryInstanceGetGeometry call done not on a Geometry. I’ll file a bug about that.
Anyway, something like shown in RebuildLayout::updateGeometry() is what you need to do when updating vertex positions dynamically in a geometry.

For information about OptiX 7, there are a similar number of SDK examples ported from the previous API and there are more examples showing how to use OptiX 7 step-by-step or port OptiX 5/6 API programs to OptiX 7 inside the sticky posts of this forum which also point to the online ray tracing documentation hub containing links to the programming guide and the API reference for both OptiX 6.5.0 and 7.1.0.

Porting to OptiX 7 can reuse most of the existing device code.