Search code examples
3drenderingrenderblendergltf

Exporting a scene as a GLTF


I would like to understand what exporting a scene in a GLTF format entails. I have a 3D model with high-definition texture maps, materials, yadee yadee yada, and I'm exporting a scene to a GLTF file.

During this process, is there actually any compute involved? What I mean by that is, does exporting the scene to the GLTF format actually involve any rendering, or any computation similar to rendering, or does it just basically bundle the 3D model with embedded textures in JPEG/PNG?


Solution

  • It matters what system you're exporting from, but in this case you tagged the question Blender so I will give an answer for exporting from Blender.

    With most formats, exporting is just a matter of gathering up and organizing the data (vertices, attributes, meshes, textures and/or texture filename references, and the like) and packing into the exported file according to the format specification.

    With the particular case of Blender exporting to glTF, there's a little catch. The glTF file format is particular about certain color channels. For example, roughness gets stored in glTF's green channel, metallic in the blue channel, and so on. So if a Blender user supplies a greyscale image for roughness and a separate image for metallic, Blender can't export those images as-is to a glTF file.

    So the Blender glTF exporter includes a section on image encoding. This bit of Python code will adapt the user-supplied images, when needed, to reassign color channels to match the glTF specification. Having all glTF assets use the same channel assignments makes it much easier for viewers to have shaders that work for all glTF files, particularly those systems that use precompiled shaders with runtime assets.

    The glTF mesh data may also be different from Blender's mesh. The glTF format specifies the data the way a GPU wants to receive it, with vertex attributes (glTF accessors) and the like. This means that artist-friendly features such as per-face UVs and per-face normals are converted to separate vertices in the exported glTF. Per-face attributes must be unwelded, converted into separate GPU vertices with separate vertex attributes. Some users perceive this as an increase in the number of vertices in the model, but internally the GPU needs this expanded version of the mesh data to function.

    In both these cases, the difference between artist asset interchange vs. raw GPU data delivery is visible. The glTF format makes the intentional choice to go with the latter, as a "transmission format" for publishing to the end user. This lightens the load on readers and viewers who wish to receive the file and render it quickly. But it does place compute requirements on glTF exporters.