How does optix::Transform and optix::Group supposed to work in rapidly changing scenes ?

So I’ve been working on procedural planets and I’ve implemented and verified a working system in OpenGL I’m now building a renderer using optix and I don’t understand how Transform and Group works exactly:

for each of my GeometryGroups I have a Transform and I update them with:

auto pos = glm::vec3(instance.e->calculate_position());
auto rot = glm::mat3(instance.e->calculate_rotation_matrix());
glm::mat4 mat = glm::mat4(rot);
mat[3] = glm::vec4(pos, 1.0);
optix::Matrix4x4 matrix(glm::value_ptr(mat));
instance.transform->setChild(geometry_groups[instance.geometry_id]);
instance.transform->setMatrix(false, matrix.getData(), matrix.inverse().getData());

I also use the bbox and intesection programs from the tutorials, they are atteched to the geometry inside the geometry group:

#include <optix.h>
#include <optixu/optixu_aabb_namespace.h>
#include <optixu/optixu_math_namespace.h>

rtBuffer<float3> vertexBuffer;
rtBuffer<float2> uvBuffer;
rtBuffer<uint3> indicesBuffer;

RT_PROGRAM void boundingbox_triangle_indexed(int primitiveIndex, float result[6])
{
  const uint3 indices = indicesBuffer[primitiveIndex];

  const float3 v0 = vertexBuffer[indices.x];
  const float3 v1 = vertexBuffer[indices.y];
  const float3 v2 = vertexBuffer[indices.z];

  const float area = optix::length(optix::cross(v1 - v0, v2 - v0));

  optix::Aabb *aabb = (optix::Aabb *) result;

  if (0.0f < area && !isinf(area))
  {
    aabb->m_min = fminf(fminf(v0, v1), v2);
    aabb->m_max = fmaxf(fmaxf(v0, v1), v2);
  }
  else
  {
    aabb->invalidate();
  }
}
#include <optix.h>
#include <optixu/optixu_math_namespace.h>

rtBuffer<float3> vertexBuffer;
rtBuffer<float2> uvBuffer;
rtBuffer<uint3> indicesBuffer;

rtDeclareVariable(optix::Ray, theRay, rtCurrentRay, );

rtDeclareVariable(optix::float3, varGeoNormal, attribute GEO_NORMAL, );
rtDeclareVariable(optix::float2, varTexCoord, attribute TEXCOORD, );

RT_PROGRAM void intersection_triangle_indexed(int primitiveIndex)
{
  const uint3 indices = indicesBuffer[primitiveIndex];

  const float3 v0 = vertexBuffer[indices.x];
  const float3 v1 = vertexBuffer[indices.y];
  const float3 v2 = vertexBuffer[indices.z];

  const float2 uv0 = uvBuffer[indices.x];
  const float2 uv1 = uvBuffer[indices.y];
  const float2 uv2 = uvBuffer[indices.z];

  float3 n;
  float  t;
  float  beta;
  float  gamma;

  if (intersect_triangle(theRay, v0, v1, v2, n, t, beta, gamma))
  {
    if (rtPotentialIntersection(t))
    {
		const float alpha = 1.0f - beta - gamma;
		varGeoNormal = n;
		varTexCoord = uv0 * alpha + uv1 * beta + uv2 * gamma;
		rtReportIntersection(0);
    }
  }
}

When I move an object I get weird fragments that look like bounding boxes. And also I don’t know how I can remove an object entirely from the scene. Setting the child count on the root group and adding the transforms as I iterate through objects seems extremely slow. Any ideas ?

Ok, I’ve found some answers;

When you change a transform on the top level structure you have to mart the top level structure as dirty. You can do that with

root_group->markDirty()
instance.transform->setMatrix(false, matrix.getData(), matrix.inverse().getData());

should be

instance.transform->setMatrix(true, matrix.getData(), matrix.inverse().getData());

I’ve also figured out how to interchange Transforms fast. Now I’m realizing that there is another issue, Whenever I write to the a freshly created or an old geometry and set the corresponding accell as dirty I get approximately 0.5 sec of freeze. Total size of the written data does not exceed 2 megabytes. I don’t know why it is so slow, my card is a 2080ti by the way.

Would I get better results if I used createBufferFromGLBO ?

When you touch the geometry or change your scene graph topology, OptiX needs to validate the changes and rebuild the acceleration structures for the changed geometry.

When using it for what? Changing geometry will always trigger the acceleration structure rebuild.

Use “Trbvh” as acceleration structure builder if you haven’t.

Here are some more OptiX forum links discussing Transform node and animation methods:
https://devtalk.nvidia.com/default/topic/1026659/optix/interactive-geometry-replacement/post/5221513/#5221513
https://devtalk.nvidia.com/default/topic/1045846/optix/single-geometry-lbs-animation/post/5306888/#5306888
https://devtalk.nvidia.com/default/topic/1045087/optix/applying-transforms-to-geometries/post/5303359/#5303359
https://devtalk.nvidia.com/default/topic/1038892/optix/geometry-gizmo-or-manipulating-geometry-from-mouse-input/post/5284292/#5284292
https://devtalk.nvidia.com/default/topic/1036173/optix/what-is-the-best-way-to-explicitly-descend-scene-graph-implement-sampling-of-arbitrary-mesh-lights-/post/5264628/#5264628
https://devtalk.nvidia.com/default/topic/1035513/optix/about-performance/post/5260558/#5260558

Ah I see, I was thinking that the memory transfer was the issue because I was getting the lag during a newly created geometry in my scene. After timing it it did turn out that it was from the launch command. Also I am using “Trbvh” in all of my accelerations but I guess this builder is not RTX. Any ideas when RTX functionality becomes available ?