I want to render scenes like they are used in mitsuba or pbrt (see https://benedikt-bitterli.me/resources/ for example scene description files).

That is, I have a list of obj-files. Each Obj file contains a mesh. And to each obj file a different BSDF is related. What I'm currently doing is creating a separate vertex and index buffer per obj file. Moreover, I'm creating a separate bottom level acceleration structure (BLAS) per obj file. I'm assing an InstanceID of i to the $i$th obj file so that I can figure out which one was hit using the InstanceID() intrinsic in my closesthit shader.

Now, that's fine. However, I wonder how I'm able to access the vertex buffer in my shaders. When I only have a single obj file (and hence a single BLAS), I can simply upload the corresponding vertex and index buffers. So, in that case I have something like this in my code:

RaytracingAccelerationStructure accelerationStructure : register(t0);
StructuredBuffer<Vertex>        vertices              : register(t1);
StructuredBuffer<uint>          indices               : register(t2);

But what am I doing if I have multiple BLASs with different vertex/index buffers? Do I need to concatenate them together? But how do I distinguish them in the code then? For example, if the $i$th mesh was hit, how do I skip over the vertices corresponding to the first $i-1$ meshes?

This is such a common problem that there must be general advice on this. Looking into the existing tutorials is not of much help, since they are either way to simple or way too complex ...



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.