What is the simplest way to enable visibility mask on spheres in sphereArray

I have an array of hittable spheres as follow:

OptixBuildInput sphere_input = {};
sphere_input.type = OPTIX_BUILD_INPUT_TYPE_SPHERES;
sphere_input.sphereArray.vertexBuffers = ...;
sphere_input.sphereArray.numVertices = ...;
...

optixAccelBuild(context, ..., &sphere_input, ..., &gas_handle);
...

Now I want to partition these spheres into eight group tagging with visibility mask (Assuming given 256 spheres, I want to set visibility of 0~31 as 0b00000001, visibility of 32~63 as 0b00000010, etc.), what is the simplest to rearrange my code with OptixBuildInput instance_input?

P.S. I check the example in OptiX SDK, do I need to create eight different gas_handle with optixAccelBuild(context, ..., sphere_group[0/1/2/...], ..., &gas_handle_0/1/2/...) first and set the instance traverse handle? If so, how should I set the transform?

Hi @794906124,

The visibility mask is a feature of instances, and is only available on the OptixInstance type, which means you will need an instance build input made using OptixBuildInputInstanceArray.

You can find examples of using visibility masks with instances in a few SDK samples, include optixClusterStructuredMesh, optixCutouts, optixMotionGeometry, optixSimpleMotionBlur, and optixVolumeViewer. That last one, optixVolumeViewer is pretty good as it makes use of the visibility masks and involves several different geometry types.

An OptixInstance is defined as a traversable handle (for example a GAS) plus a few other things like a transform, visibility mask, SBT offset, and an instance ID.

Rather than build a GAS of 256 spheres, you would instead build 1 GAS with 1 sphere which will become the traversable handle used for your instances. Then build an Instance Accel Structure (IAS) with 256 instances. You can use the instance transform to position each sphere. Read more about instance build inputs in the OptiX Programming Guide.


David.

Thanks! I will check the example, that helps a lot!