<p>With help from the Nvidia Forum and two very helpful and friendly Nvidia employees I found the perfect solution.</p>

<p>In OptiX there is a so called selector node. This is a special scene-graph node that utilizes a user specified program to select which child a ray should traverse and which not.</p>

<pre><code>#include &lt;optix.h&gt;

rtDeclareVariable(unsigned int, timestep, , );

RT_PROGRAM void animation_selector()
{
    rtIntersectChild(timestep);
}
</code></pre>

<p>This is a simple version of such a selection program. From the CPP-API side the current timestep will be set and can be used to make the animation. And then when the scene graph is traversed the program just says "Traverse only the child with index 'timestep'". This does not trigger a recompile or refit and therefore is nearly instant.</p>

<p>The selector node is simply created in following way:</p>

<pre><code>optix::Selector selector = context_-&gt;createSelector();

std::string path_to_ptx = VRTPtxFinder::GetPtxPath("VistaRayTracing_generated_animation_selector.cu.ptx");

optix::Program selection_program = context_-&gt;createProgramFromPTXFile(path_to_ptx, "animation_selector");
selector["timestep"]-&gt;setUint(0u);
selector-&gt;setVisitProgram(selection_program);

for(auto group : groups)
{
  selector-&gt;addChild(group);
}
</code></pre>

<p>The only cost is one additional method call for each traversal and thereby also a slightly bigger stack which caused me some problems with a stack overflow so when using this, keep an eye on the stack size.</p>

CC BY-SA 3.0
2016-05-13T11:34:19.540Z
2016-05-13T11:34:19.540Z
Dragonseel
<p>I have a Optix Raycasting renderer which loads and renders VTK files.
For a single static model this works fine.</p>

<p>But now my dataset consists of multiple timesteps which I want to display in a animated fashion.</p>

<p>Each couple of frames or seconds the displayed model has to be switched out with the next one.
If possible I want to refrain from rebuilding the acceleration structure each time this happens.</p>

<p>So my question: Can I just load all models at once, place them in the global acceleration structure and then just switch all off except the one currently displayed.
My hope is that this would be more efficient.</p>

<p>Edit 1:
I have now build a variant in which I create <em>optix::Acceleration</em> and <em>optix::Group</em> for each of the timesteps separate and each time the active timestep changes I just </p>

<pre><code>_context["top_object"]-&gt;set(mesh_group[timestep]);
</code></pre>

<p>But each this call takes nearly half a second. I think optix does quite some work in the background when I switch this object out.
This delay is not acceptable for me as it makes the playback of my "animation" stutter.</p>

<p>Has anyone a idea how to do this more efficient?</p>

CC BY-SA 3.0
2016-05-07T12:39:30.493Z
I'm not familiar with the framework, but wouldn't it be more efficient to create an acceleration structure for each model?
Rotem
CC BY-SA 3.0
2016-05-08T17:10:12.533Z
Okay. Yes, but then I have to switch out which mesh is the currently active one... I think that would be doable... switching just works by setting a variable in the graphics memory I think. I would have to try if this influences perfomance in a big way. Thank you for your suggestion.
Dragonseel
CC BY-SA 3.0
2016-05-09T11:41:06.550Z
@Rotem I tried to just create everything before displaying, and then only switching it out... It turns out each time tell Optix to use another model this takes nearly half a second and my "animation" looks really unsmooth.
Dragonseel
<vtk>
Optix: Rendering time-variant data
Dragonseel
# Optix: Rendering time-variant data

(Asked by: username_0 on 2016-05-07)

I have a Optix Raycasting renderer which loads and renders VTK files.
For a single static model this works fine.

But now my dataset consists of multiple timesteps which I want to display in a animated fashion.

Each couple of frames or seconds the displayed model has to be switched out with the next one.
If possible I want to refrain from rebuilding the acceleration structure each time this happens.

So my question: Can I just load all models at once, place them in the global acceleration structure and then just switch all off except the one currently displayed.
My hope is that this would be more efficient.

Edit 1:
I have now build a variant in which I create *optix::Acceleration* and *optix::Group* for each of the timesteps separate and each time the active timestep changes I just

```
_context["top_object"]->set(mesh_group[timestep]);

```

But each this call takes nearly half a second. I think optix does quite some work in the background when I switch this object out.
This delay is not acceptable for me as it makes the playback of my "animation" stutter.

Has anyone a idea how to do this more efficient?

**Tags:** vtk

> **Comments:**
> **username_1**: I'm not familiar with the framework, but wouldn't it be more efficient to create an acceleration structure for each model?  
> **username_0**: Okay. Yes, but then I have to switch out which mesh is the currently active one... I think that would be doable... switching just works by setting a variable in the graphics memory I think. I would have to try if this influences perfomance in a big way. Thank you for your suggestion.  
> **username_0**: @username_1 I tried to just create everything before displaying, and then only switching it out... It turns out each time tell Optix to use another model this takes nearly half a second and my "animation" looks really unsmooth.  

---

## 1 answers

### Answer by username_0 on 2016-05-13. Score: 3 | Accepted answer

With help from the Nvidia Forum and two very helpful and friendly Nvidia employees I found the perfect solution.

In OptiX there is a so called selector node. This is a special scene-graph node that utilizes a user specified program to select which child a ray should traverse and which not.

```
#include <optix.h>

rtDeclareVariable(unsigned int, timestep, , );

RT_PROGRAM void animation_selector()
{
    rtIntersectChild(timestep);
}

```

This is a simple version of such a selection program. From the CPP-API side the current timestep will be set and can be used to make the animation. And then when the scene graph is traversed the program just says "Traverse only the child with index 'timestep'". This does not trigger a recompile or refit and therefore is nearly instant.

The selector node is simply created in following way:

```
optix::Selector selector = context_->createSelector();

std::string path_to_ptx = VRTPtxFinder::GetPtxPath("VistaRayTracing_generated_animation_selector.cu.ptx");

optix::Program selection_program = context_->createProgramFromPTXFile(path_to_ptx, "animation_selector");
selector["timestep"]->setUint(0u);
selector->setVisitProgram(selection_program);

for(auto group : groups)
{
  selector->addChild(group);
}

```

The only cost is one additional method call for each traversal and thereby also a slightly bigger stack which caused me some problems with a stack overflow so when using this, keep an eye on the stack size.


---

