-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Move Transmissive3d phase to pbr/transmission #22706
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
Open
+151
−107
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| use std::ops::Range; | ||
|
|
||
| use bevy_camera::{Camera, Camera3d}; | ||
| use bevy_ecs::{ | ||
| entity::Entity, | ||
| query::With, | ||
| system::{Local, Query, ResMut}, | ||
| }; | ||
| use bevy_material::{descriptor::CachedRenderPipelineId, labels::DrawFunctionId}; | ||
| use bevy_math::FloatOrd; | ||
| use bevy_platform::collections::HashSet; | ||
| use bevy_render::{ | ||
| render_phase::{ | ||
| CachedRenderPipelinePhaseItem, PhaseItem, PhaseItemExtraIndex, SortedPhaseItem, | ||
| ViewSortedRenderPhases, | ||
| }, | ||
| sync_world::MainEntity, | ||
| view::RetainedViewEntity, | ||
| Extract, | ||
| }; | ||
|
|
||
| pub struct Transmissive3d { | ||
| pub distance: f32, | ||
| pub pipeline: CachedRenderPipelineId, | ||
| pub entity: (Entity, MainEntity), | ||
| pub draw_function: DrawFunctionId, | ||
| pub batch_range: Range<u32>, | ||
| pub extra_index: PhaseItemExtraIndex, | ||
| /// Whether the mesh in question is indexed (uses an index buffer in | ||
| /// addition to its vertex buffer). | ||
| pub indexed: bool, | ||
| } | ||
|
|
||
| impl PhaseItem for Transmissive3d { | ||
| /// For now, automatic batching is disabled for transmissive items because their rendering is | ||
| /// split into multiple steps depending on [`ScreenSpaceTransmission::screen_space_specular_transmission_steps`], | ||
| /// which the batching system doesn't currently know about. | ||
| /// | ||
| /// Having batching enabled would cause the same item to be drawn multiple times across different | ||
| /// steps, whenever the batching range crossed a step boundary. | ||
| /// | ||
| /// Eventually, we could add support for this by having the batching system break up the batch ranges | ||
| /// using the same logic as the transmissive pass, but for now it's simpler to just disable batching. | ||
| const AUTOMATIC_BATCHING: bool = false; | ||
|
|
||
| #[inline] | ||
| fn entity(&self) -> Entity { | ||
| self.entity.0 | ||
| } | ||
|
|
||
| #[inline] | ||
| fn main_entity(&self) -> MainEntity { | ||
| self.entity.1 | ||
| } | ||
|
|
||
| #[inline] | ||
| fn draw_function(&self) -> DrawFunctionId { | ||
| self.draw_function | ||
| } | ||
|
|
||
| #[inline] | ||
| fn batch_range(&self) -> &Range<u32> { | ||
| &self.batch_range | ||
| } | ||
|
|
||
| #[inline] | ||
| fn batch_range_mut(&mut self) -> &mut Range<u32> { | ||
| &mut self.batch_range | ||
| } | ||
|
|
||
| #[inline] | ||
| fn extra_index(&self) -> PhaseItemExtraIndex { | ||
| self.extra_index.clone() | ||
| } | ||
|
|
||
| #[inline] | ||
| fn batch_range_and_extra_index_mut(&mut self) -> (&mut Range<u32>, &mut PhaseItemExtraIndex) { | ||
| (&mut self.batch_range, &mut self.extra_index) | ||
| } | ||
| } | ||
|
|
||
| impl SortedPhaseItem for Transmissive3d { | ||
| // NOTE: Values increase towards the camera. Back-to-front ordering for transmissive means we need an ascending sort. | ||
| type SortKey = FloatOrd; | ||
|
|
||
| #[inline] | ||
| fn sort_key(&self) -> Self::SortKey { | ||
| FloatOrd(self.distance) | ||
| } | ||
|
|
||
| #[inline] | ||
| fn sort(items: &mut [Self]) { | ||
| radsort::sort_by_key(items, |item| item.distance); | ||
| } | ||
|
|
||
| #[inline] | ||
| fn indexed(&self) -> bool { | ||
| self.indexed | ||
| } | ||
| } | ||
|
|
||
| impl CachedRenderPipelinePhaseItem for Transmissive3d { | ||
| #[inline] | ||
| fn cached_pipeline(&self) -> CachedRenderPipelineId { | ||
| self.pipeline | ||
| } | ||
| } | ||
|
|
||
| pub fn extract_transmissive_camera_phases( | ||
| mut transmissive_3d_phases: ResMut<ViewSortedRenderPhases<Transmissive3d>>, | ||
| cameras: Extract<Query<(Entity, &Camera), With<Camera3d>>>, | ||
| mut live_entities: Local<HashSet<RetainedViewEntity>>, | ||
| ) { | ||
| live_entities.clear(); | ||
|
|
||
| for (main_entity, camera) in &cameras { | ||
| if !camera.is_active { | ||
| continue; | ||
| } | ||
|
|
||
| // This is the main camera, so use the first subview index (0). | ||
| let retained_view_entity = RetainedViewEntity::new(main_entity.into(), None, 0); | ||
|
|
||
| transmissive_3d_phases.insert_or_clear(retained_view_entity); | ||
| live_entities.insert(retained_view_entity); | ||
| } | ||
|
|
||
| transmissive_3d_phases.retain(|view_entity, _| live_entities.contains(view_entity)); | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: i don't know what this check is here for. All of these contains_key checks always return true and the conditional never runs in my testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking if this even does anything at all in #22711