bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.15k stars 3.57k forks source link

Loading a glTF scene doesn't use the correct UV map for ambient occlusion #13086

Closed jf908 closed 6 months ago

jf908 commented 6 months ago

Bevy version

0.13.2 and latest main (9592a40e1eb387f926b787cbb3a65d9db1dfb1a3)

Relevant system information

AdapterInfo { name: "NVIDIA GeForce RTX 3070 Ti Laptop GPU", vendor: 4318, device: 9440, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "546.33", backend: Vulkan }

What you did

Load a gltf model with a ambient occlusion lightmap

What went wrong

Expected Actual
https://gltf-viewer.donmccurdy.com/ Bevy Scene Viewer Example
image image

In the example there is a cube mesh and a plane mesh, each with 2 UV maps. One UV map is used for the base colour and one is used for ambient occlusion. The gltf-viewer and three.js read and render the model correctly but not in bevy. The base texture can be seen properly rendered through the broken ambient occlusion texture so I suspect that the ambient occlusion is working but the 2nd UV map is not being used or being read incorrectly.

Additional information

Model used to test: gltf_model.zip

bugsweeper commented 6 months ago

This also has problems with UV-map, but may be different kind

geckoxx commented 6 months ago

It is a similar issue. The material in the file is using a specific texCoord for its occlusionTexture but this is ignored by the gltf loader: https://github.com/bevyengine/bevy/blob/ade70b3925b27f76b669ac5fd9e2c31f824d7667/crates/bevy_gltf/src/loader.rs#L856

But the main issue is that bevy_pbr uses only one texcoord attribute for all textures. So it does not support multiple UV maps at the moment.

jf908 commented 6 months ago

I thought with the lightmap update in 0.13, bevy pbr supported 2 UV maps? three.js is hardcoded to use the 2nd UV map for ambient occlusion and lightmap textures and the 1st UV map for everything else. Perhaps bevy could follow the same convention until multiple UV maps become more flexible?

bugsweeper commented 6 months ago

It is a similar issue. The material in the file is using a specific texCoord for its occlusionTexture but this is ignored by the gltf loader

Problem is that baseColorTexture uses TEXCOORD_0, but (!!!) occlusionTexture uses TEXCOORD_1, bevy_pbr does use same ATTRIBUTE_UV_0 for both of them, that's why loader can't load this glb in mesh+StandardMaterial with correct bevy_pbr interpretation