kcoley / gltf2usd

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

AlphaMode parameter is missing in the Material class #88

Closed ShantanuSriv closed 5 years ago

ShantanuSriv commented 5 years ago

https://github.com/kcoley/gltf2usd/blob/2fb00ed730b8a87206551ff67cd75682d8276ad4/Source/_gltf2usd/gltf2/Material.py#L104

I was going through the code and couldn't find anything which handles alphaMode parameter of material class -- for handling transparency nature of the asset? I wanted to know whether this is purposely left out because of no API support or did @kcoley miss adding the support for it?

As, I converted a few glTF files to usdz and there were issues with transparency of the converted files.

gopikrishnachaganti commented 5 years ago

@kcoley i also see transparency is missing and scale values are literally high when converting gltf to usda. Can you please look into this asap?

kcoley commented 5 years ago

@ShantanuSriv @gopikrishnachaganti I didn't see an alphaMode option in the UsdPreviewSurface API spec, so I left it out: https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html

There is a material opacity option, which I set using the base color factor, if a base color texture with alpha isn't set in usd_material: https://github.com/kcoley/gltf2usd/blob/master/Source/_gltf2usd/usd_material.py#L231

Though I should set the opacity regardless whether there is alpha in the base color texture, which I can quickly fix.

@gopikrishnachaganti when you say scale values, are you referring to normal scale, emissive factor, base color factor, etc? I also set these in usd_material.py based on their parameters though I can run some tests to verify they are working against these models: https://github.com/KhronosGroup/glTF-Asset-Generator/tree/master/Output/Material.

If referring to model scale, models by default are scaled by 100 to convert from glTF meters to centimeters, though this can be adjusted with the --scale flag

kcoley commented 5 years ago

@ShantanuSriv @gopikrishnachaganti I pushed a fix for opacity with base color factor that I mentioned previously. I also tested the alpha modes based on Material_07 and the factors seem to export as expected: https://github.com/KhronosGroup/glTF-Asset-Generator/tree/master/Output/Material

Though I am not sure if ArQuicklook is respecting the scale factors of the textures based on looking at the renders on Mac and iOS.

@ShantanuSriv As for adding support for alpha modes to the USD spec, I think that is a good question for the USD interest group: https://groups.google.com/forum/#!forum/usd-interest

ShantanuSriv commented 5 years ago

@kcoley Thanks a lot for such a quick response! I will look into the new changes and test it.

ShantanuSriv commented 5 years ago

@kcoley I have tried converting the files from gltf to usdz. Even after the changes of the latest patch, I see the transparency issues. I have a question to ask: is this the issue with ARQuickLook or is there some edge cases that are not handled properly during the conversion. Plus, I have tried converting obj to usdz -- from another tool -- but the same transparency issues. So, what I have concluded that there is some issue with how ARQuickLook is handling transparency -- not sure though. Do you have any confirmation on this issue?

Here are some of the files in glTF and its corresponding usdz-converted files:

glTF

screen shot 2018-11-02 at 2 58 14 pm screen shot 2018-11-02 at 3 00 17 pm screen shot 2018-11-02 at 3 01 08 pm

usdz-converted

image from ios 1 image from ios 2 image from ios

Also, do you have any official usdz sample file from Apple which has transparency exposed in it?

kcoley commented 5 years ago

@ShantanuSriv hmm, it could be an issue with ArQuickLook. Apple does not have any sample usdz models with transparency on their gallery: https://developer.apple.com/arkit/gallery/

I noticed that if there is alpha in the base color texture, it gets used in ArQuickLook even when set to not be used in the UsdPreviewSurface in the usdz file. I could put in a check for that and overwrite the transparency to completely opaque if the alpha mode is set to opaque.

kcoley commented 5 years ago

@ShantanuSriv I just added support for alpha mode in the Material class (https://github.com/kcoley/gltf2usd/pull/93).

Note that Alpha Mask is not yet supported in USD so it will default to Alpha Blend. If that doesn't fix your issue, feel free to reopen.

ShantanuSriv commented 5 years ago

I tried the new changes but all the transparency is now gone.

glTF

screen shot 2018-11-02 at 3 01 08 pm

converted-usdz

image from ios 3

The glTF file has only two alphaModes:

Conclusion: After the changes, shadow at the bottom is fixed but transparency is still an issue.