0

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.

Bicyclette
  • 13
  • 2

1 Answers1

3

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.

Andrei Despinoiu
  • 370
  • 3
  • 17
  • Yes glTF is a nice file format, and I wish I could keep using it. The reason I am leaving it for FBX is because I am trying to get some better texture loading performances in a small game engine I have written in C++. I discovered that glTF was doing an automatic conversion of every textures in either PNG or JPG, which is slow to load from RAM to VRAM due to the uncompression stage. Thus I searched for "what is the best texture format for games", and I read about the DDS format, which I finally managed to load in my game engine, but only with FBX files since I cannot use glb/glTF for that. – Bicyclette Aug 26 '21 at 20:23
  • I agree with you, loading one texture by hand can be a solution, I did thought about that, but I won't give it a try even if I know it works :) I also thought of something else : Give your object in Blender/Maya a blinn or phong material, then use the regular channels for albedo and normal map, but for textures like metallic and roughness, you can put them in the transparency and emissive color channels respectively. Finally in your code with assimp, you retrieve the transparency and emissive color textures, and send them to your metallic and roughness OpenGL texture units. – Bicyclette Aug 26 '21 at 20:24
  • 1
    The bad thing with the last solution is that you can't have a preview of what your material will look like in Blender, since everything happens in your game engine. Anyway, I stopped searching for a way to load al of this properly, and I will stick to the good old phong material for my game, I really want those DDS textures, since it really makes a difference in texture loading time (like 8 times faster than PNG/JPG). And it is still possible to obtain really good looking models with non PBR materials, so it's okay I guess :) Thanks ! – Bicyclette Aug 26 '21 at 20:25