Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ARRAY_TEXTURES support to shaders. #6842

Closed
wants to merge 1 commit into from

Conversation

IamTheCarl
Copy link

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.

@ickk
Copy link
Member

ickk commented Dec 4, 2022

Just as a note: Array textures currently seem to have some problems on the webgl2 platform.

see gfx-rs/wgpu#3197

@ickk ickk added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen labels Dec 4, 2022
@IamTheCarl
Copy link
Author

Probably not worth mentioning, but I have had problems woth areay textures on hardware from before 2010.

I wouldn't be against hiding the theoretical "ArrayTextureStandardMaterial" behind a feature flag for these reasons, especially since the use cases are a little less common. I've only really seen them used for voxel rendering.

@StarArawn
Copy link
Contributor

Just as a note: Array textures currently seem to have some problems on the webgl2 platform.

see gfx-rs/wgpu#3197

There is only a problem with copy_texture_to_texture and array textures. Looking through this PR it should be fine. 🤔

@IamTheCarl
Copy link
Author

Thank you.

For what it's worth, I've been using my fork ever since I made it and haven't had an issue with standard materials.

My changes were meant to be like that so it shouldn't be a surprise.

I do think a more elegant solution is possible but it would require some significant changes to the preprocessor and it would likely bring in issues that C's preprocessor is infamous for.

I've been wondering if the WGPU team has been considering something similar to generics for their language. It would be hard to implement but would be very elegant in this particular use case.

@IamTheCarl
Copy link
Author

With how drastic the changes to the shaders have been, I no longer have the bandwidth to keep updating this branch.
I'm planning to rebuild my renderer without the use of this feature.

@IamTheCarl IamTheCarl closed this Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants