For more information about the glTF file format please have a look into the Khronos glTF 2.0 specifications here:
https://github.com/KhronosGroup/glTF/tree/main
The cheat sheet there might be helpful to understand what index inside the *.gltf means what.
The *.gltf
files themselves are actually *.json
files which normally reference raw binary files (*.bin
) with the buffer data.
Just look at some of the simple ones inside the Khronos glTF-Sample-Assets
The glTF file format is rather OpenGL centric. There are quite some things in there which do not directly map to OptiX or more precisely CUDA, like memory alignment restrictions being different, which requires copying data around, or specific input data formats required by OptiX. etc. You’ll see that in my example.
There shouldn’t be a problem generating glTF files if you have understood its format.
It’s basically a JSON file and one or more raw binary files which contain the buffer data used for the different elements. These are interpreted via Accessors, which in turn use BufferViews onto these Buffers.
Everything is connected with indices to arrays of these things.
A much simpler format would be OBJ and its associated MTL material description, but that is ASCII and will load comparably slow and its indices are one-based. (I regularly convert huge OBJ files to GLTF to save repeated loading time.) If you need per-vertex colors, that is also pretty uncommon and non-standard behavior in OBJ. Most parsers do not handle that.
I’m creating the file myself, so I could try to save it to a more friendly format while it allows me to recover intersection points and colors.
If you do not need to rely on a standard file format, you would be free to implement whatever data format you’d like as well. Though it would be better to be able to compare results in other renderers. GLTF supports per-vertex colors if you need that.
Just read the cheat sheet, read the specs, and some of the simpler *.gltf
files and you’ll see how that works.
For an OptiX beginner you need to understand how to build acceleration structures.
My examples have runtime generation function for shapes (plane, box, sphere, torus) which generate the vertex attributes and then build the geometry acceleration structure (GAS) from the position attributes of these.
Then these are placed under a top-level instance acceleration structure (IAS) which places them into the world.
This post explains some options: https://forums.developer.nvidia.com/t/passing-per-vertex-attribute-data-into-a-shader-program/279321/2
The other crucial thing you need to understand in OptiX is the Shader Binding Table (SBT) which is rather flexible and can have different layouts depoending on what your application needs. As said GLTF is a little special in that area.
Please read the OptiX Programming Guide and these forum threads:
https://forums.developer.nvidia.com/t/sbt-theoretical-quesions/179309/2
https://forums.developer.nvidia.com/t/how-to-handle-multiple-ray-generators/83446/2