My path tracer supports point light and area light. I store lights in the scene into a buffer. When I need to sample a point on light source, I randomly choose a light from the buffer, and sample a position according the type of the light and its corresponding parameters. This works for point light and area light with analytic shape, like disk or sphere, because a few parameters are need to specify the disk light or spherical light. I also saw many OptiX samples using ParallelogramLight, which can be handled similarly.
But when I use triangle mesh for area light, the problem comes. To sample a position on the light, I need to access to the vertex buffer and index buffer of the mesh. The light sampling is called inside the Closest Hit Program, so where should I store the buffer objects?
My idea is to, associate each triangle mesh area light with one imaginary geometry, then the buffer objects can be stored on these geometries(or GeometryInstance); when I need to sample a light position, I trace a ray (with special type) into this group of geometries to select an area light, and sample a position using the vertex buffer stored on the GeometryInstance. But this method seems a little overkill, I wonder if there is a better solution.