Objects in Motion

I’m trying to learn more about transforming objects in OptiX. I’m following the example from OptiX Advanced Samples, optixIntro_03.

Referrring to the sphere in Application.cpp (around line 924), I’ve changed the values in the transformation matrix to an arbitrary rotation value (say 90 deg), thinking that would cause the sphere to be rotated 90 deg when the program is run. But it isn’t.

So instead of the transform matrix looking like this:

float trafoSphere[16] = 
 1.0f, 0.0f, 0.0f, 0.0f,
 0.0f, 1.0f, 0.0f, 1.0f,
 0.0f, 0.0f, 1.0f, 0.0f,
 0.0f, 0.0f, 0.0f, 1.0f

I’m changing it to look like this (90 deg rotation around the y-axis):

float trafoSphere[16] = 
 <b>0.0f</b>, 0.0f, <b>-1.0f</b>, 0.0f,
 0.0f, 1.0f, 0.0f, 1.0f,
 <b>1.0f</b>, 0.0f, <b>0.0f</b>, 0.0f,
 0.0f, 0.0f, 0.0f, 1.0f

Am I going about this the wrong way? Can’t I simply modify the transformation matrix? Or should I look into rtGeometrySetMotionRange() & rtGeometrySetMotionSteps()?

So there were a few things that were causing this problem:

The first was that the Material is considered to be a static material in this case, meaning that even if the object rotated, the material/ texture wouldn’t change.

In addition, because the geometry is a sphere, it is even more difficult to notice a change in rotation. If I had used a cube or another geometry with distinguishable faces, a change in rotation would have been evident.

I also discovered the built in transformation functions in the Matrix4x4 files. At first I thought I could simply pass my matrix to these functions to be modified. However I realized that they are built for matrix multiplication instead. Just an FYI.

Now I’m trying to “animate” my sphere, but am unsure where this would be done, and am encountering an interesting bug.

I chose to implement the animation code in render(). The following is my initialization code:

optix::float3 b = {7.0f, 2.0f, 2.0f};

transMatrix = optix::Matrix4x4::translate(b);
matrixSphere2 = transMatrix;

trSphere2 = m_context->createTransform();
trSphere2->setMatrix(false, matrixSphere2.getData(), matrixSphere2.inverse().getData());

The following is my code in render():

trSphere2->getMatrix(false, transMatrix.getData(), transMatrix.inverse().getData());

optix::float3 b = {2.0f, 2.0f, 2.0f};
optix:: Matrix4x4 transMatrix2 = optix::Matrix4x4::translate(b);

trSphere2->setMatrix(false, transMatrix2.getData(), transMatrix.inverse().getData());


The bug is that 2 instances of these spheres are created in the scene but can only be seen at certain angles and only within what appears to be their bounding boxes.

did you also marked the root group dirty? any higher node above ggSphere needs to be marked dirty


from OptiX 5.1 docs page 32 http://raytracing-docs.nvidia.com/optix/guide/nvidia_optix_programming_guide.180814.A4.pdf
[…]For example, if the underlying geometry of a geometry group changes, the acceleration structure attached to the geometry group must be recreated.[…]Failure to mark acceleration structures as dirty when necessary may result in unexpected behavior — usually missing intersections or performance degradation.[…]