Assimp FBX loader and PBR textures

1.8k Views Asked by At

I would like to know if the assimp FBX loader does supports PBR materials.

I am currently using it with glTF/glb files and it perfectly loads my PBR textures. I am loading PBR textures via the "assimp/pbrmaterial.h" header file, but this file is only defining glTF macros.

How can I load PBR textures when using the FBX file format with assimp ?

Regards.

1

There are 1 best solutions below

3
On BEST ANSWER

I don't think it can. glTF 2.0 uses a single texture that contains: metallic on the blue channel, roughness on the green. And from my own testing using Blender v2.93.3 (the latest right now), if you use its Shader Editor to split that single texture into separate RGB channels, the FBX won't get saved with any paths to it. Even when you import the FBX back into Blender it will only have the base color and normal map applied, nothing else. So I don't think you can expect Assimp (v5.0.1) to work with it either... But this might just be a bug in Blender, I'm not sure. Because it seems that if metallic and roughness are individual textures, Blender can correctly import the FBX back. It's a pretty big oversight that you can't export (as FBX) models that use multi-channel textures. Pretty much all PBR workflows involve having them merged into a single texture, to reduce texture lookups.

I don't know... seems like glTF 2.0 is a much better format. It comes with a GPU-friendly binary (compared to something like Wavefront OBJ which is very slow), and you can even have the textures separately if you choose the "glTF Separate" format when you export it. You automatically get a merged PNG with both metallic and roughness like I said before:

If you really wanna have support for FBX files (I know I do; it's a popular format), what you could do, is to have it correctly identify and load the base color and normal map, but then you have to manually load the "PBR" texture somewhere before the render loop starts, and then manually bind the texture and send it as a uniform to the fragment shader before drawing it. I tested this and it works.

glActiveTexture(GL_TEXTURE2); // Texture unit 2
glBindTexture(GL_TEXTURE_2D, *pMyMetRoughTexture);
pShader->SetInt("uMaterial.MetallicRoughnessTexture", 2); // Tell the sampler2D from the fragment shader to use texture unit 2
pMyModel->Draw(pShader);

But having 2/3 textures loaded automatically and 1 left up to you, to manually handle, for every... single... model... is just... bleh. I'm sorry if this isn't a "proper" answer. I'm really disappointed by the lack of PBR support, for something that's used so ubiquitously in I think all AAA games in the last few years.