Second Instance from the same GAS not Rendering in optixSimpleMotionBlur

I’m new to this topic. When I tried to learn how to create a scene like the following picture. I started by modifying the optixSimpleMotionBlur example. By adding an additional instance using the original sphere program, my target is to place two spheres at different position in scene using the same underlying GAS (like the TransformedPrimitive in PBRT). Sadly, whatever I did, I cannot render the second sphere declared in the top level IAS out.

Here’s how I changed the sample code:
optixSimpleMotionBlur.cpp (47.4 KB)

  1. in the enum InstanceType , I set InstanceType::TRI = 2 for additional space for another instance.
  2. in the SimpleMotionBlurState, I added two variables d_sphere_motion_transform2, sphere_motion_transform_handle2 as the original ones did.
  3. in Build sphere GAS stage, I add additional build configs (line 535-570)
  4. and then created sphere_motion_transform_handle2 with another transform and the same sphere_gas_handle as its child (line 670-710)
  5. in buildInstanceAccel, set another instance using optix_instances[InstanceType::SPHERE+1](line 724-743)

    This is where things go wrong. It seems that whatever I did, this second instance will never be rendered

  6. finally, set another hit SBT with different color and position info (line 1020-1024)

Could anyone tell me what should I do?

I’m questioning your change to the enum value for the TRI entry to make room for more instances inside the IAS. Change the counting and indexing of the OptixInstances instead.

I have not seen anyone using SBT index offsets with char type.
First of all this should always be unsigned types and I would try unsigned int like in the other examples.
I would also recommend setting the sbtIndexOffsetStrideInBytes explicitly to the correct size and not zero.

If I understood your graph correctly, the left GAS should contain a single sphere you instance twice?
But you put two spheres into that GAS, so the instances on top should show four inside the scene if everything worked.

And you added an SBT entry to that GAS with sphere_input.customPrimitiveArray.numSbtRecords = 2; and directly reference the three SBT hit records with the instances sbtOffset.
That doesn’t fit together. Please check this chapter for how the effective sbtIndex is calculated and look esp. at the case where the instance SBT is set for GAS which use more than one SBT Record!

Remove the additional sphere you added to the GAS and have that use only one SBT entry again.

If that isn’t helping, this repository contains an example intro_motion_blur which is using linear and SRT motion transforms.
All examples in there only use triangle primitives. Adding custom primitives for spheres to that would require some changes, but it contains a function to generate tessellated sphere objects.

Thanks for your reply, after your suggestions and some further research into the code and mannual, I found that actually the problem is nothing above and quite a simple mistake at line 736, where the transform to copy to is instance[0] but not instance[1].

The improper setting of numPrimitives might be some garbage left after one of my attempts to make it work properly and it seems that doesn’t make any difference in the setup.

Thanks anyway.