Hello,
that actually seems to be what I want.
I have build a version of this and the switching does indeed no longer add a delay.
But now somehow the closest_hit program does not get called nearly as often as needed.
Program selection_program = context_->createProgramFromPTXFile(path_to_ptx, "animation_selector");
selection_program["flipbookIndex"]->setUint(0u);
selector->setVisitProgram(selection_program);
selector->addChild(mesh_group_);
selector->validate();
context_["top_object"]->set(selector);
context_["top_shadower"]->set(selector);
The snippet shows my creation of the selector node and adding a single child to it.
If I directly set top_object and shadower to the mesh_group_ everything works fine.
My visit/selection program is exactly as you have posted.
But now instead seeing the full mesh I only see a small number of dark pixels that enable me to roughly guess the object shape is correct, but 90% of where the mesh should be shows just the background color.
I tried rtPrintf in the intersection program and with the selector only maybe a hundred prints are made, and with directly the mesh_group many thousands are printed.
Is there a obvious error or some step I am missing?
I have not altered neither ray generation program nor the intersection program to work with the selector node.
EDIT:
I have narrowed the problem down:
In my Phong-shader I cast shadow rays and they seem to be the problem.
rtDeclareVariable(rtObject, top_object, , );
rtDeclareVariable(rtObject, top_shadower, , );
...
if( NdotL > 0.0f && light.casts_shadow){
PerRayData_shadow shadow_prd;
shadow_prd.attenuation = make_float3(1.0f);
optix::Ray shadow_ray = optix::make_Ray(hit_point, to_light, shadow_ray_type, scene_epsilon, light_distance);
rtTrace(top_shadower, shadow_ray, shadow_prd);
light_attenuation = shadow_prd.attenuation;
}
This is the code concerning the shadows. I assume it is that the shadow rays do not properly terminate and therefore the result of the phong shading is somehow undefined. But that’s just a guess.