Add UV channel selection to StandardMaterial
Objective
- The StandardMaterial always uses ATTRIBUTE_UV_0 for each texture except lightmap. This is not flexible enough for a lot of gltf Files.
- Fixes #12496
- Fixes #13086
- Fixes #13122
- Closes #13153
Solution
- The StandardMaterial gets extended for each texture by an UvChannel enum. It defaults to Uv0 but can also be set to Uv1.
- The gltf loader now handles the texcoord information. If the texcoord is not supported it creates a warning.
- It uses StandardMaterial shader defs to define which attribute to use.
Testing
This fixes #12496 for example:
For testing of all kind of textures I used the TextureTransformMultiTest from https://github.com/KhronosGroup/glTF-Sample-Assets/tree/main/Models/TextureTransformMultiTest Its purpose is to test multiple texture transfroms but it is also a good test for different texcoords. It also shows the issue with emission #13133.
Before:
After:
Added the same support for clearcoat textures and using shader defs instead of material flags.
@geckoxx You should add "Closes #13153" to your description
just a quick note about the shader defs - we could alternatively use indexes/bits in the material data to specify the uv indexes and avoid a proliferation of shader variants.
i think defs are probably better because
- it will have no cost in the base case where only 1 set of texcoords are used
- if you do need to use multiple sets, you likely have them all in the same locations, so only one variant would be needed
- if they are not in the same locations, if you control the assets and you care enough, you can modify your assets to align them
whereas using data in the material would increase its size having a (marginal) effect on all uses of StandardMaterial, whether you want the flexibility or not.
Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to https://github.com/bevyengine/bevy-website/issues/1313 if you'd like to help out.