Add option to animate materials in many_cubes#17927
Merged
superdump merged 2 commits intobevyengine:mainfrom Feb 18, 2025
Merged
Add option to animate materials in many_cubes#17927superdump merged 2 commits intobevyengine:mainfrom
superdump merged 2 commits intobevyengine:mainfrom
Conversation
IceSentry
approved these changes
Feb 18, 2025
superdump
approved these changes
Feb 18, 2025
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 20, 2025
# Objective Fix incorrect mesh culling where objects (particularly directional shadows) were being incorrectly culled during the early preprocessing phase. The issue manifested specifically on Apple M1 GPUs but not on newer devices like the M4. The bug was in the `view_frustum_intersects_obb` function, where including the w component (plane distance) in the dot product calculations led to false positive culling results. This caused objects to be incorrectly culled before shadow casting could begin. ## Issue Details The problem of missing shadows is reproducible on Apple M1 GPUs as of this commit (bisected): ``` 00722b8 Make indirect drawing opt-out instead of opt-in, enabling multidraw by default. (#16757) ``` and as recent as this commit: ``` c818c92 Add option to animate materials in many_cubes (#17927) ``` - The frustum culling calculation incorrectly included the w component (plane distance) when transforming basis vectors - The relative radius calculation should only consider directional transformation (xyz), not positional information (w) - This caused false positive culling specifically on M1 devices likely due to different device-specific floating-point behavior - When objects were incorrectly culled, `early_instance_count` never incremented, leading to missing geometry in the shadow pass ## Testing - Tested on M1 and M4 devices to verify the fix - Verified shadows and geometry render correctly on both platforms - Confirmed the solution matches the existing Rust implementation's behavior for calculating the relative radius: https://github.com/bevyengine/bevy/blob/c818c92143e56ef3b51836af423319a5a61b15ad/crates/bevy_render/src/primitives/mod.rs#L77-L87 - The fix resolves a mathematical error in the frustum culling calculation while maintaining correct culling behavior across all platforms. --- ## Showcase `c818c9214` <img width="1284" alt="c818c9214" src="https://github.com/user-attachments/assets/fe1c7ea9-b13d-422e-b12d-f1cd74475213" /> `mate-h/frustum-cull-fix` <img width="1283" alt="frustum-cull-fix" src="https://github.com/user-attachments/assets/8a9ccb2a-64b6-4d5e-a17d-ac4798da5b51" />
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This adds an option to animate the materials in the
many_cubesstress test. Each material instancebase_coloris varied each frame.This has been tested in conjunction with the
--vary-material-data-per-instanceand--material-texture-countoptions.If
--vary-material-data-per-instanceis not used it will just update the single material, otherwise it will update all of them. If--material-texture-countis used thebase_coloris multiplied with the texture so the effect is still visible.Because this test is focused on the performance of updating material data and not the performance of bevy's color system it uses its own function (
fast_hue_to_rgb) to quickly set the hue. This appeared to be around 8x faster than usingbase_color.set_hue(hue)in the tight loop.