Use glossiness and normal maps in .obj + .mtl model?


(Xiuming Zhang) #1

I specified the diffuse and specular PBR maps in a .mtl file. I followed Sketchfab's recommended naming conventions, and as expected, Sketchfab was able to automatically assign the two maps to the correct slots. This is great.

Now I want to add two more maps -- glossiness and normal maps. AFAIK, the canonical .mtl standards do not support these two maps (although some newer standards support glossiness maps with tag map_Pr and normal maps with tag norm).

I tried referencing the glossiness and normal maps in my .mtl file anyways, followed Sketchfab's naming conventions, and hoped for the best.

...
newmtl Material.001
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd WoodPlanksWorn19_diffuse.jpg
map_Pr WoodPlanksWorn19_glossiness.jpg
norm WoodPlanksWorn19_normal.jpg
map_Ns WoodPlanksWorn19_specular.jpg
...

No miracle happened -- the glossiness and normal maps didn't load automatically into their slots.

Is there a way for Sketchfab to automatically allocate the glossiness and normal maps to their slots, just like how it automatically loads the diffuse and specular maps?


(Dark Minaz) #2

Hey
First of all, you don't really need to bother to much with the mtl
What is important are the following
Name of the material + correct naming of the slot
Sketchfab automatically tries to fit them in.

For the naming:
material_albedo (color)
material_AO (ambient occlusion)
material_emissive (glowy bits)
material_Normal (normal map, sometimes this doesn't work and needs to be done by hand!)
material_roughness (glossiness)
material_metallic

Here are a few additional information:
If it doesn't work
try "/edit?process_material=1" in the adress bar, this will redo the process. so far hasn't failed me once


zipping the above did generate


(Waleguene) #3

Hi @xiumingzhang ,

You can find all the informations here: https://help.sketchfab.com/hc/en-us/articles/202600873-Materials-and-Textures#textures-auto-pbr

Regarding your example, it doesn't match because your material is named "Material.001" and textures seem to reference a material names WoodPlanksWorn19

As @dark_minaz said, the mtl is not really important here, you can just drop the textures with the good names in the archive and they will be mapped on the materials.

Can you give a try with a good material name and keep us in touch ?
Thanks


(Xiuming Zhang) #4

Thanks @dark_minaz and @waleguene!

I guess the .mtl file does matter in my case. My .obj file contains three objects (I guess this is how my model is different from your example up there, @dark_minaz ?), and one of them has the four PBR maps associated with it. Therefore, the .mtl file needs to reference the PBR maps properly so that Sketchfab knows to which of the three objects these PBR maps need to be applied to. Am I right?

@waleguene I've tried with the good material name, as shown below.

    newmtl WoodPlanksWorn19
    Ns 96.078431
    Ka 1.000000 1.000000 1.000000
    Kd 0.640000 0.640000 0.640000
    Ks 0.500000 0.500000 0.500000
    Ke 0.000000 0.000000 0.000000
    Ni 1.000000
    d 1.000000
    illum 2
    map_Kd WoodPlanksWorn19_diffuse.jpg
    map_Pr WoodPlanksWorn19_glossiness.jpg
    norm WoodPlanksWorn19_normal.jpg
    map_Ns WoodPlanksWorn19_specular.jpg

but the glossiness and normal maps still do not load automatically. Given map_Pr and norm are not supported in standard .mtl, I do think that's an issue caused by the .mtl file. Any thoughts?

Here is my zipped model. model.zip (2.1 MB)

Many thanks for helping out!


(Dark Minaz) #5

I had a look, well you do have around 700 materials.
Not sure why you need that many but well
After uploading it without the mtl and my line i mentioned above (type it in and hit enter to reload the page), although the automatic one did work quite well (i simply removed them again to test if the script still works) i got the following result:

So it does seem to work with your model as well


(Xiuming Zhang) #6

Thanks @dark_minaz for trying out my model! I successfully replicated your observations -- if I upload without the .mtl file, indeed all the four PBR maps are automatically loaded to the correct slots. Therefore, it seems that referencing the PBR maps in the .mtl file confuses Sketchfab's parser.

So my problem is fully solved! For objects with PBR maps, I will just leave them out in my .mtl file. For objects with basic materials, I will specify their materials in my .mtl file. Everything works. Really appreciate your help in these experiments, @dark_minaz!

Is this behavior expected, @waleguene?


(Dark Minaz) #7

Glad i could help :wink:
Not exactly sure why the mtl stops it from working though. but i expect the devs to know more :slight_smile:


(Mrchlblng) #8

@xiumingzhang @dark_minaz we are in the process of adding some limits as to what end up displayed in the viewer. For real-time performance, we've decided to limit scenes to 100 distinct materials (which is already a lot performance wise and UX wise when you have to edit a material). Our current policy is that if there are too many distinct materials, we cannot decide which one to keep to reach our limit so the scene will end up with a single material.

We actually had a bug which recreate a material if we don't find the material definition during the processing. That's why it currently solves your issue. However you should probably not rely on this behavior.
When the fix is released, you will end up with a single material. As the material has no name, texture binding will not work at all.

Sorry to bring bad news here. @xiumingzhang do you really need so many materials? Maybe you could give us more detail as to what you're trying to achieve so we can help you more efficiently!


(Xiuming Zhang) #9

@mrchlblng So you mean I still need to reference the material with PBR maps in my .mtl file, like this?

newmtl WoodPlanksWorn19
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd WoodPlanksWorn19_diffuse.jpg
map_Pr WoodPlanksWorn19_glossiness.jpg
norm WoodPlanksWorn19_normal.jpg
map_Ns WoodPlanksWorn19_specular.jpg

and the PBR maps will get allocated correctly when I don't have so many materials?

The reason why I currently have so many materials is that my mesh has a per-face color. After color quantization, I still have 500+ distinct colors, so 500+ materials. I'm sure there is a way to reduce the number of materials and in the meanwhile achieve the same visual effects. Would love to learn. :slight_smile:


(Dark Minaz) #10

create a copy
make an automatic map on that with 1 material
then use something like for example X normal (free tool) or blender (also free) to bake the albedo (color information in your materials) down to that 1 map :slight_smile:

that would reduce your scene to 3 materials
1 for the guy behind
middle texture
1 for the guy in front :slight_smile:

@mrchlblng yeah i was surprised it even allowed so many to begin with :wink:
i expected there to be a limit of 50 or something


(Mrchlblng) #11

@xiumingzhang yes! Actually you can be lazy and just name your material in the mtl, reference said material in the obj and then prefix textures by your material name and textures should be set correctly.

Regarding your scenario, can't you bake the colors in a texture? or maybe you could use vertex colors?


(Xiuming Zhang) #12

Thanks both @dark_minaz and @mrchlblng for the advice! I will bake the colors to bring down my number of materials.

Will let you guys know if all PBR maps get allocated automatically when I finish the experiment. :slight_smile:


(Mrchlblng) #13

@xiumingzhang do not hesitate to update us on your progress. We love it when the CG research community is using sketchfab! Good luck!


(Xiuming Zhang) #14

@mrchlblng @dark_minaz Hi guys, so here are some updates.

In the end, I took the proper approach -- having a UV map for all my colors and specify UV mapping in my .obj file, so there are no longer excessively many materials causing issues.

I only have diffuse maps in my current model, and yes, they are automatically assigned when named properly. However, I do need to reference it with map_Kd in my .mtl file. Otherwise, it won't get assigned automatically. This is probably because my .obj file contains multiple objects, so I need to specify in .mtl which object this diffuse map should be applied to?

One strange thing (which doesn't affect the outcome) though is that the materials all get renamed, despite that I do have different names for all materials. For example, I have 001Wood, 002Wood, etc., but somehow Sketchfab grabs one of the names, say, 032Wood, and renames all the others to 032Wood_0, 032Wood_1, etc. Is this a bug? (In case this matters: my model is a stop motion animation of .obj, .mtl, and diffuse maps. Each .obj has three objects inside, each of which references its own diffuse map in .mtl).

Thanks!


(Dark Minaz) #15

I guess the stopmotion and with multiple obj's it gets confused as you have all similar names etc, well that is my guess :slight_smile: but good that it works if you reference it.
Since the server can't know for certain that you really want all to be the same it probably won't merge them, so it generates _0 _1 versions. So that might be the expected result :slight_smile:


(Mrchlblng) #16

@xiumingzhang @dark_minaz the material renaming looks like a bug in our pipeline. All the frames really reference the same "008WoodPlanksWorn19" material but when we parse the frames we duplicate the textures so we end up considering that it's not exactly the same material. We'll see to improve this as it's really not the expected result indeed. And it'd require less textures so less bandwidth and vram.

Just a couple of other remarks:

  • you should really try to generate 'power of 2' textures (we'll resize and maybe alter the textures as we only end up displaying power of 2 textures)
  • you should use the orientation widget to correct your model orientation
  • the frame by frame rendering is not nice; this is on our side too & we'll see if we can fix this too!

(Xiuming Zhang) #17

@mrchlblng Sorry but what do you mean by "All the frames really reference the same "008WoodPlanksWorn19" material" ? In my .obj, each frame (i.e., each .obj) references different materials. E.g., frame 1 references 001WoodPlanksWorn19, frame 2 references 002WoodPlansWorn19, etc.

I am also not sure why this renaming isn't causing problems.

Thanks again for your time!


(Mrchlblng) #18

@xiumingzhang sorry I went too fast. To clarify things, in our pipe, we have a distinction between the material definition and the textures used by the material. In your case, you do not change the material definitions, just the material names and the textures.
So we end up

  • merging all materials references (some "maps" are involved which explains why it's not necessarily the first "logical" instance that get used) which explains why you end up with 032Wood_0, 032Wood_1 etc.
  • not merging textures which explains why your materials are okay in the end.

My comment about duplicates still holds for the humanTexture001 material for which we unnecessarily duplicate the texture for each frame. So we'll improve this and it should lighten the final scene a bit!