Acceleration structure for multiple geometries

Hello developers,

I am working with multiple geometries, one is made from triangular MESH and other is normal sphere, the problem is when I am using acceleration structure like:

geometrygroup->setAcceleration(m_context->createAcceleration("Bvh", "Bvh"));

I can see only one geometry while previously I was using “NoAccel” it was working fine, but it was little slow.

Can anyone help me with this?

Hard to judge from single line of code.

If you have two different geometric primitives you also need to have two different bounding box and intersection programs.

Then these two GeometryGroups need to be placed under a root Group node which then becomes your top object variable where the scene traversal starts when launching rays and that root Group also needs to have an acceleration structure assigned.

Also according to your other post you changed the mesh loader to make the “vertex_buffer” with the triangle mesh data be a context global variable. While that screws up the mesh loader to not be able to load more than one OBJ or PLY file into a scene (last one wins and app most likely crashes), that might also have affected your sphere data in case you used the same name variable “vertex_buffer” to define the sphere center and radius which has a different data format.

Hello,
Thank you for your reply, I think this problem occurs before the amendments in mesh loader, I think I am missing some thing in here.

The main problem is with acceleration structure because whem I am using “NoAccel” everything is working fine just it is slow, but when I am using any other acceleration structure I cannot see my other object

details are below:
like I have one disk geometry :

Geometry disk2 = m_context->createGeometry();
//		std::string sphere_ptx(ptxpath("tutorial", "sphere.cu"));
		disk2->setPrimitiveCount(1u);
		disk2->setBoundingBoxProgram(m_context->createProgramFromPTXFile(sphere_ptx, "bounds"));
		disk2->setIntersectionProgram(m_context->createProgramFromPTXFile(sphere_ptx, "intersect2"));
		disk2["sphere"]->setFloat(0.0, 5, 6.0);
		disk2["normal"]->setFloat(0, 0, 1);
		disk2["radius"]->setFloat(4.0);

a geometry group:

GeometryGroup geometrygroup = m_context->createGeometryGroup();
 geometrygroup = m_context->createGeometryGroup();
  geometrygroup->setChildCount( static_cast<unsigned int>(gis.size()) );

and one geometry model from.obj file:

InsertModel(prog_path, geometrygroup, box_matl, mesh_intersect, m0, true);
InsertModel("C:/ProgramData/NVIDIA Corporation/OptiX SDK 3.8.0/SDK/tutorial/knot.obj", geometrygroup, box_matl, mesh_intersect, m0, false);

pushing geometry in gis and setting child node

std::vector<GeometryInstance> gis;
gis.push_back(m_context->createGeometryInstance(disk2, &object_matl, &object_matl + 1));
 geometrygroup->setChild(0, gis[0]);

setting acceleration:

geometrygroup->setAcceleration(m_context->createAcceleration("NoAccel", "NoAccel"));

when I am using this aceleration everything is fine, problem occurs when I change the acceleration

making top object:

m_context["top_object"]->set( geometrygroup );
  m_context["top_shadower"]->set( geometrygroup );

That isn’t really helpful either.
If the given code blocks are run in the order you gave here, that is not going to work.

For example:
You set a number of children from gis.size() which should be zero at that point.
You call InsertModel() twice. Are you loading two OBJ files there?
In that case your changes to make the “vertex_buffer” context-global would probably break things.

InsertModel() resp. OptiXMesh will add a child to the GeometryGroup you provide.
It also adds an acceleration structure in case you have none at the GeometryGroup and it specifically sets the acceleration properties to special cases for indexed triangle mesh data.
If you then use that acceleration structure with a builder which actually uses these names “vertex_buffer” and “index_buffer” and you do not provide these, as is the case with the sphere Geometry, the builder might not actually find the proper data, resp. won’t work correctly because it assumes triangle data. (I’m normally not using any of these default names for my vertex attributes or indices.)
Debug into OptiXMeshImpl::createGeoInstancesAndOptixGroup() to see what it does exactly.

Then you overwrite the first child of the GeometryGroup if there was one.
Then you put a new acceleration structure to that GeometryGroup, leaking the one from InsertModel().

For a clearer picture of what calls your application is really doing I would recommend to do an OptiX API Capture (OAC) trace and look into the resulting trace.oac text file which contains all OptiX C-API calls in the order issued to OptiX.
Please see this thread for instructions how to do that: https://devtalk.nvidia.com/default/topic/803116/?comment=4436953
If you attach that trace.oac text file here, it would become clearer what is actually happening API-wise.
Only if that turns out as real issue and not an incorrect usage of the OptiX API, the whole oac* folder contents would be needed for analysis.

To get a solid foundation about how you need to setup a scene in OptiX and how to put things together I recommend to start learning OptiX following this order: https://devtalk.nvidia.com/default/topic/550862/?comment=3847704

Sorry for the late reply, Thank you so much for your detailed reply, I fixed my problem that time and didn’t get time to respond. it was just a problem in my bounding box program.
Thanks any ways.
Keep it up, this forum is really very helpful.
much Appreciated.