Added ARRAY_TEXTURES support to shaders. #6842
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
I and some other people in the Bevy Discord group use texture arrays. We've had to re-implement all of the pbr functionality to support this, and any change upstream breaks our code.
Solution
I have added macros that add in/swap out the few lines of code needed to support array textures.
The user still needs to implement a custom material as I haven't added any form of "StandardArrayTextureMaterial". Adding one on top of this isn't hard, but the macro
#[derive(AsBindGroup)]
needs to be fixed. It tries to set a fallback texture when one is set to none, and because that fallback texture is not an array texture, wgpu will fail it at validation. My workaround is to set my own fallback textures, rather than using None.I would fix this myself but I've never written a Proc macro before and I figured I'd see if the shader changes are acceptable before going down that rabbit hole.
Changelog
If you create a custom material, you can add "ARRAY_TEXTURES" to your shader_defs to enable array texture support in the shaders. All textures become array textures and a "texture_layer" variable is added to the
mesh_vertex_output
.Migration Guide
Standard shaders still work as expected. No migration is needed.