Community Showcase: GDX glTF
Hey everybody! As announced a few weeks ago we want to give creators of interesting community projects the opportunity to present their exciting libraries or tools on the official blog. This is the third of these Community Showcases, in which Mgsx is going to present his gdx-gltf library!
If you are interested in other cool community projects, be sure to check out the libGDX Awesome List as well. To participate in future showcases, take a look here.
gdx-gltf is a library that enables advanced 3D for your games. Detailed features are already listed in the repository. In this article, MGSX will explain the motivation behind this library, why he made it, how it works and what happens next.
A complicated workflow G3DJ, G3DB, FBX, and fbx-conv
The first thing that was annoying me when doing 3D with libGDX is the 3D format support: you need to export as FBX and convert it to G3DJ or G3DB using fbx-conv. This workflow is a bit awkward when iterating on your project. Also, you need to install fbx-conv and the required runtime dependencies (FBX SDK) which is problematic if you want to load models on the fly within your game.
Other things that I found annoying were that FBX is a proprietary format and it’s difficult to improve things. Each intermediate format/tool has their own limitation (i.e. the 32k vertices limit in both fbx-conv and libGDX). Besides, libGDX G3D is a custom format so I would have to convert back to something else if I want to migrate to another framework/game engine. I’m not a fan of these kinds of dependencies.
A promising alternative
So I was seeking an open source format, well integrated in Blender and other game engines… and Boom! I found the glTF format. It provides a lot more features, very close to OpenGL and is becoming a standard. Bonus point: this format supports PBR workflow. What LibGDX provides out of the box for 3D is nice but a bit limited: gouraud shading, linear key frame interpolation, max 32k vertices per mesh.
So what do we have? A nice open source 3D format, some test models, a premade PBR shader, a Blender plugin. All of these are maintained by Khronos group (who maintains OpenGL, OpenGLES, Vulkan, etc.). It sounds very good, right?
Implementation of the loader was pretty straightforward thanks to the good specification and documentation. Integration into libGDX was also not so complicated: few overrides here and there but libGDX 3D API has been well designed for extensive formats.
Expanding features
Once the loader and PBR shader were implemented, I added some features I was interested in like exporting models from libGDX. Yeah, you can load and save models from your game which enable procedural generation in libGDX, export to Blender, tweak the stuff, export again and load it back. A brand new universe is opening.
Beside, my primo library user (who made the showcase video) was a bit pissed off with IBL worlflow, requiring some weird tools. So i made my own. You can import HDRI and export all you need for your game : environment map, radiance map, irradiance map.
Then it was time to show to the others what the library is capable of, and also have fun. I made several game jams using it, it helps me to improve the API, fixing some bugs and improve documentation.
My goal was also to help beginners by providing some convenient classes in order to quickly enable stuff like shadows, post processing effect.
So basically the library contains :
- all you need to load/save glTF files
- all you need to render it
- some convenient stuff like the Scene3D package
- some tools: IBL-composer, GLTF-viewer
- some experiments in the test package
The test project was at first to help me implementing the specification and validate my code against existing models. But it progressively became a kind of model viewer. Very useful to check some models, inspect them easily, play with it. I use it sometimes when I have issues in my game to see if my model was correctly loaded.
The future of it
Is it a replacement of the default libGDX 3D? No. Default shaders and format still well suited for lowend devices (PBR shader is more costly than Gouraud shader is). Also, the default API/implementation is simple, optimizd and sufficent for most use cases. While i’m considering gdx-gltf mature enough and ready for production (because it’s more recent), it’s not as bullet proofed as libGDX core implementation.
What next? The library implements all the glTF specification and main extensions, it’s pretty stable now. Sure, the documentation could be improved and I also have some new features in mind. I just need time to implement them (PR welcome :-)), among other things :
- A Phong shader to provide something in between PBR and gouraud.
- Convenient way to use multiple render target.
- Built-in HDR bloom.
- Screen space reflections and ambient occlusion.
So, give it a try and let me know what you think about it on Discord.
Thanks for reading.
References:
- Specification : https://github.com/KhronosGroup/glTF
- Viewer : https://github.com/KhronosGroup/glTF-Sample-Viewer
- Models: https://github.com/KhronosGroup/glTF-Sample-Models
- GLTF tools : https://github.khronos.org/glTF-Project-Explorer/
- Blender plugin documentation : https://docs.blender.org/manual/en/2.80/addons/io_scene_gltf2.html