pablode / guc

glTF to USD converter with MaterialX support
Apache License 2.0
107 stars 5 forks source link

Material binding not displaying with ARKit after performing a glTF to USDZ conversion #28

Closed lanxinger closed 1 week ago

lanxinger commented 1 month ago

Moved over from a discussion on the Alliance for Open USD forum: https://forum.aousd.org/t/obj-gltf-to-usdz-usdzconvert-discontinued/1648/9

Material bindings are set to preview after performing a glTF to USDZ conversion with guc and iOS ARKit/RealityKit/SceneKit doesn't display the materials on the model as a result.

The model does display view the Storm Renderer used in macOS Preview though.

iOS_RealityKit_QuickLook

macOS_Preview

rel material:binding:preview = </Asset/Materials/UsdPreviewSurface/Materials/Texture> changing that to rel material:binding = </Asset/Materials/UsdPreviewSurface/Materials/Texture> works as expected.

I furthermore found the face normals get modified to flat shading during that conversion:

before after

Here is the link the the USDZ model: https://drive.proton.me/urls/DJ0SRP3N44#20IZrmyz28Zy

Input glTF binary: https://drive.proton.me/urls/X9A1TRZN5G#HirzCL9ik1BG

pablode commented 1 month ago

Hi! Thanks for the report.

As Dhruv says, this sounds like an iOS/Apple specific bug where the runtime does not fall back to the preview binding. guc should also author the default material binding instead.

I'll investigate the normal issue and keep you posted.

pablode commented 1 month ago

@lanxinger I've implemented the binding fix and am planning to release a new version in the next few days.

Unfortunately, I can't see any issue with the normals. Could you elaborate how the above screenshots were created? Also, could you verify that (if you used usdview) 'Flat Shaded' is not enabled?

Screenshot 2024-07-13 at 21 05 15

I've also checked the converter output by setting TF_DEBUG=GUC and it doesn't generate flat normals. Furthermore, the USD file attached above seems to have valid smooth normals (here, rendered without material): 2024-07-13 21_01_25-C__Users_pablode_Downloads_test_out usdc

lanxinger commented 1 month ago

hi @pablode thank you for the quick action.

the screenshots above are from blender actually. I haven't tried usdview but good to know it is working properly there.

I am unable to change the shading to smooth inside blender for this model. maybe another ticket I need to file there for that. However it does seem to work properly for the initial USDZ we get from object capture: https://drive.proton.me/urls/ZYSW6YM7NW#XN8F3uwqvBMy

pablode commented 1 month ago

I think this may be a Blender issue based on following observations:

Perhaps this issue is related? https://projects.blender.org/blender/blender/issues/107696

Will try to verify with NVIDIA Omniverse.

pablode commented 1 month ago

Looks correct in Omniverse.. at least the normals.

2024-07-14 19_11_44-USD Composer 2023 2 5 Beta - C__Users_pablode_Downloads_test usdz_

Interestingly, the three NVIDIA render delegates didn't fall back to the preview material binding, too.

lanxinger commented 1 month ago

thanks @pablode for the thorough investigation. I have also suspected a blender bug for the normal shading. maybe I can contribute this issue to the filed ticket you linked above.

I wonder if the fallback to the preview material binding is somewhat related to the USD version being used in the build.

I see that in Apple's case it's reported as Apple USD Tools (0.24.3) which means it's one release behind the latest 0.24.5.

Maybe also worth filing this on the OpenUSD GitHub?

pablode commented 1 month ago

The binding issue should be fixed in 0.4, thanks for reporting!

Regarding the behaviour in USD: I don't think it's related to any version. My hunch is that it's caused by the HdRenderDelegate::GetMaterialBindingPurpose() getter, which allows the renderer to only return full or preview (unlike GetMaterialRenderContexts, where a preference list is returned).