kcoley / gltf2usd

command-line utility for converting glTF 2.0 models to USD
MIT License
263 stars 39 forks source link

Questions on embedded GLTF PBR Texture #38

Closed enzyme69 closed 5 years ago

enzyme69 commented 6 years ago

Just now, I exported GLTF material from Blender, and during conversion, I am getting this error:

Traceback (most recent call last):
  File "gltf2usd.py", line 1126, in <module>
    convert_to_usd(args.gltf_file, args.usd_file, args.fps, args.scale, args.verbose)
  File "gltf2usd.py", line 1114, in convert_to_usd
    GLTF2USD(gltf_file=gltf_file, usd_file=usd_file, fps=fps, scale=scale, verbose=verbose)
  File "gltf2usd.py", line 70, in __init__
    self.convert()
  File "gltf2usd.py", line 1099, in convert
    self._convert_materials_to_preview_surface()
  File "gltf2usd.py", line 482, in _convert_materials_to_preview_surface
    primvar_st1_output=primvar_st1_output
  File "gltf2usd.py", line 1074, in _convert_texture_to_usd
    texture_name = self.unpack_textures_to_grayscale_images(image_name, color_components)
  File "gltf2usd.py", line 1035, in unpack_textures_to_grayscale_images
    raise Exception('Unsupported image type!: {}'.format(img.mode))
Exception: Unsupported image type!: RGBA

So far, I have tested 3D GLTF from Sketchfab only and never had issue. Only today I am setting up the shader based on GLTF Blend example. Then I exported the object and getting an error. It does not seem to like RGBA, maybe I should change it to JPG?

screen shot 2018-09-05 at 1 01 18 pm
enzyme69 commented 6 years ago

Works ok on Clay-Viewer:

screen shot 2018-09-05 at 1 02 59 pm
kcoley commented 6 years ago

@enzyme69 do you have a sample model that repros this issue?

enzyme69 commented 6 years ago

@kcoley This is the one: USDZ_donut_rgba_error.zip

Maybe the texture itself is problematic. Just now, I convert all the PNG into JPG and works!

ox commented 6 years ago

So the texture it's failing on is the Ambient Occlusion png, which has 4 channels. The _convert_materials_to_preview_surface function goes in expecting to use the r component of the occulusionTexture image as the occlusion map, sees a 4 channel image, which jumps to logic trying to unpack a glossiness map.

I think if you change your ao.png to only be 3 channels, it should work

kcoley commented 6 years ago

@enzyme69 yes what @ox says is correct since the logic initially assumes that you are using an ORM texture (occlusion: r, roughness: g, metallic: b). The texture logic definitely needs refactoring. I will look into that later today to make it more robust. But in the meantime, @ox solution should work.

enzyme69 commented 6 years ago

Also something interesting I found with RGBA and RGB, try the model below: https://sketchfab.com/models/f8b43d7d9f914480bfc91c8a4d6fd314

For some PNG, it gives this weird flipped overlapping material on the USDZ after conversion. Again this is seems to be RGBA related. If I save PNG as RGB, it works good.

enzyme69 commented 6 years ago

It makes me wonder if we actually have "Occlusion Transparency Shader" already ... weird_rgb

enzyme69 commented 6 years ago

@kcoley Do you mean in the Blender material node itself, I could have Roughness - Metalness -Occlusion (greyscale) plug into RGB node which will translate into GLTF and works with your conversion?

enzyme69 commented 6 years ago

It's this Metalness and Roughness which unfortunate...

screen shot 2018-09-07 at 7 03 32 am
sulydeni commented 6 years ago

It makes me wonder if we actually have "Occlusion Transparency Shader" already ... weird_rgb I have a similar issue. My model does not reflect light the same way it does in gltf

kcoley commented 5 years ago

@sulydeni @sulydeni I think the USD implementation in XCode/iOS always reads the alpha value even if it is not used in the glTF and is ignored in the usd file. I'll make an issue to remove the alpha channel from the texture if it is not used in glTf.

kcoley commented 5 years ago

I recently merged a change to remove alpha channel based on alpha mode: https://github.com/kcoley/gltf2usd/pull/93