Fix: support RenderLayer filtering for lights#23265
Fix: support RenderLayer filtering for lights#23265pauliusuza wants to merge 3 commits intobevyengine:mainfrom
Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
| .get(*light_entity) | ||
| .expect("Failed to get spot light visible entities"); | ||
| (visible_entities, &light.render_layers) | ||
| } |
| 's, | ||
| (&'static RenderVisibleMeshEntities, &'static ExtractedPointLight), | ||
| With<ExtractedPointLight>, | ||
| >, |
There was a problem hiding this comment.
This will collide with #23107. It's not a blocker though.
| /// Keep this in sync with the light-side packing in `light.rs` and the shader | ||
| /// constants in `mesh_view_types.wgsl`. | ||
| const SHADER_RENDER_LAYER_MASK_BITS: u32 = 26; | ||
| const SHADER_RENDER_LAYER_MASK: u32 = (1 << SHADER_RENDER_LAYER_MASK_BITS) - 1; |
There was a problem hiding this comment.
I totally get why you wanted to save memory here, but I think I'd just add a field instead. As you wrote it, we have no room to add flags; if we wanted to add flags we'd have to add a field anyway or risk breaking apps. And 26 is kind of an arbitrary number; 32 would be less weird.
There was a problem hiding this comment.
The light flags field is a u32, and the lower 6 bits are already used for light feature flags (bit 0..bit 5), so render-layer bits must start at shift 6, leaving exactly 26 bits for layer membership.
Objective
Prior art:
Solution
With this implementation, per-mesh/per-light filtering supports layers 0..=25 (26 layers total).
Testing
Tested and confirmed working with:
cargo run --example light_render_layers