Skip to content

Make sure prepass notices changes in alpha mode #19170

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

Merged
merged 2 commits into from
May 18, 2025

Conversation

eero-lehtinen
Copy link
Contributor

@eero-lehtinen eero-lehtinen commented May 11, 2025

Objective

Fixes #19150

Solution

Normally the validate_cached_entity in

let Some((current_change_tick, pipeline_id)) =
view_specialized_material_pipeline_cache.get(visible_entity)
else {
continue;
};
// Skip the entity if it's cached in a bin and up to date.
if opaque_phase.as_mut().is_some_and(|phase| {
phase.validate_cached_entity(*visible_entity, *current_change_tick)
}) || alpha_mask_phase.as_mut().is_some_and(|phase| {
phase.validate_cached_entity(*visible_entity, *current_change_tick)
}) || opaque_deferred_phase.as_mut().is_some_and(|phase| {
phase.validate_cached_entity(*visible_entity, *current_change_tick)
}) || alpha_mask_deferred_phase.as_mut().is_some_and(|phase| {
phase.validate_cached_entity(*visible_entity, *current_change_tick)
}) {
continue;
}
marks unchanged entites as clean, which makes them remain in the phase.

If a material is changed to an alpha_mode that isn't supposed to be added to the prepass pipeline, the specialization system just continues and doesn't indicate to the cache that the entity is not clean anymore.

I made these invalid entities get removed from the pipeline cache so that they are correctly not marked clean and then removed from the phase.

Testing

Tested with the example code from the issue.

@eero-lehtinen
Copy link
Contributor Author

It also seems bad that we are doing all these material and mesh lookups for alpha blended materials every frame just to ignore them. Maybe this check could be moved to be a bit earlier at least.

@janhohenheim janhohenheim added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 12, 2025
Copy link
Member

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good catch, thanks!

@tychedelia tychedelia added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 17, 2025
@tychedelia tychedelia added this to the 0.16.1 milestone May 17, 2025
@superdump superdump added this pull request to the merge queue May 18, 2025
Merged via the queue into bevyengine:main with commit 2db1037 May 18, 2025
42 checks passed
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-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

DepthPrepass doesn't respect changing alpha_mode from Opaque to Blend.
5 participants