pub struct ViewTarget { /* private fields */ }
Implementations§
Source§impl ViewTarget
impl ViewTarget
pub const TEXTURE_FORMAT_HDR: TextureFormat = TextureFormat::Rgba16Float
Sourcepub fn get_color_attachment(&self) -> RenderPassColorAttachment<'_>
pub fn get_color_attachment(&self) -> RenderPassColorAttachment<'_>
Retrieve this target’s main texture’s color attachment.
Examples found in repository?
587 fn run<'w>(
588 &self,
589 graph: &mut RenderGraphContext,
590 render_context: &mut RenderContext<'w>,
591 (camera, view, target): QueryItem<'w, Self::ViewQuery>,
592 world: &'w World,
593 ) -> Result<(), NodeRunError> {
594 // First, we need to get our phases resource
595 let Some(stencil_phases) = world.get_resource::<ViewSortedRenderPhases<Stencil3d>>() else {
596 return Ok(());
597 };
598
599 // Get the view entity from the graph
600 let view_entity = graph.view_entity();
601
602 // Get the phase for the current view running our node
603 let Some(stencil_phase) = stencil_phases.get(&view.retained_view_entity) else {
604 return Ok(());
605 };
606
607 // Render pass setup
608 let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
609 label: Some("stencil pass"),
610 // For the purpose of the example, we will write directly to the view target. A real
611 // stencil pass would write to a custom texture and that texture would be used in later
612 // passes to render custom effects using it.
613 color_attachments: &[Some(target.get_color_attachment())],
614 // We don't bind any depth buffer for this pass
615 depth_stencil_attachment: None,
616 timestamp_writes: None,
617 occlusion_query_set: None,
618 });
619
620 if let Some(viewport) = camera.viewport.as_ref() {
621 render_pass.set_camera_viewport(viewport);
622 }
623
624 // Render the phase
625 // This will execute each draw functions of each phase items queued in this phase
626 if let Err(err) = stencil_phase.render(&mut render_pass, world, view_entity) {
627 error!("Error encountered while rendering the stencil phase {err:?}");
628 }
629
630 Ok(())
631 }
Sourcepub fn get_unsampled_color_attachment(&self) -> RenderPassColorAttachment<'_>
pub fn get_unsampled_color_attachment(&self) -> RenderPassColorAttachment<'_>
Retrieve this target’s “unsampled” main texture’s color attachment.
Sourcepub fn main_texture(&self) -> &Texture
pub fn main_texture(&self) -> &Texture
The “main” unsampled texture.
Sourcepub fn main_texture_other(&self) -> &Texture
pub fn main_texture_other(&self) -> &Texture
The other “main” unsampled texture.
In most cases you should use Self::main_texture
instead and never this.
The textures will naturally be swapped when Self::post_process_write
is called.
A use case for this is to be able to prepare a bind group for all main textures ahead of time.
Sourcepub fn main_texture_view(&self) -> &TextureView
pub fn main_texture_view(&self) -> &TextureView
The “main” unsampled texture.
Sourcepub fn main_texture_other_view(&self) -> &TextureView
pub fn main_texture_other_view(&self) -> &TextureView
The other “main” unsampled texture view.
In most cases you should use Self::main_texture_view
instead and never this.
The textures will naturally be swapped when Self::post_process_write
is called.
A use case for this is to be able to prepare a bind group for all main textures ahead of time.
Sourcepub fn sampled_main_texture(&self) -> Option<&Texture>
pub fn sampled_main_texture(&self) -> Option<&Texture>
The “main” sampled texture.
Sourcepub fn sampled_main_texture_view(&self) -> Option<&TextureView>
pub fn sampled_main_texture_view(&self) -> Option<&TextureView>
The “main” sampled texture view.
pub fn main_texture_format(&self) -> TextureFormat
Sourcepub fn is_hdr(&self) -> bool
pub fn is_hdr(&self) -> bool
Returns true
if and only if the main texture is Self::TEXTURE_FORMAT_HDR
Sourcepub fn out_texture(&self) -> &TextureView
pub fn out_texture(&self) -> &TextureView
The final texture this view will render to.
pub fn out_texture_color_attachment( &self, clear_color: Option<LinearRgba>, ) -> RenderPassColorAttachment<'_>
Sourcepub fn out_texture_format(&self) -> TextureFormat
pub fn out_texture_format(&self) -> TextureFormat
The format of the final texture this view will render to
Sourcepub fn post_process_write(&self) -> PostProcessWrite<'_>
pub fn post_process_write(&self) -> PostProcessWrite<'_>
This will start a new “post process write”, which assumes that the caller
will write the PostProcessWrite
’s source
to the destination
.
source
is the “current” main texture. This will internally flip this
ViewTarget
’s main texture to the destination
texture, so the caller
must ensure source
is copied to destination
, with or without modifications.
Failing to do so will cause the current main texture information to be lost.
Examples found in repository?
142 fn run(
143 &self,
144 _graph: &mut RenderGraphContext,
145 render_context: &mut RenderContext,
146 (view_target, _post_process_settings, settings_index): QueryItem<Self::ViewQuery>,
147 world: &World,
148 ) -> Result<(), NodeRunError> {
149 // Get the pipeline resource that contains the global data we need
150 // to create the render pipeline
151 let post_process_pipeline = world.resource::<PostProcessPipeline>();
152
153 // The pipeline cache is a cache of all previously created pipelines.
154 // It is required to avoid creating a new pipeline each frame,
155 // which is expensive due to shader compilation.
156 let pipeline_cache = world.resource::<PipelineCache>();
157
158 // Get the pipeline from the cache
159 let Some(pipeline) = pipeline_cache.get_render_pipeline(post_process_pipeline.pipeline_id)
160 else {
161 return Ok(());
162 };
163
164 // Get the settings uniform binding
165 let settings_uniforms = world.resource::<ComponentUniforms<PostProcessSettings>>();
166 let Some(settings_binding) = settings_uniforms.uniforms().binding() else {
167 return Ok(());
168 };
169
170 // This will start a new "post process write", obtaining two texture
171 // views from the view target - a `source` and a `destination`.
172 // `source` is the "current" main texture and you _must_ write into
173 // `destination` because calling `post_process_write()` on the
174 // [`ViewTarget`] will internally flip the [`ViewTarget`]'s main
175 // texture to the `destination` texture. Failing to do so will cause
176 // the current main texture information to be lost.
177 let post_process = view_target.post_process_write();
178
179 // The bind_group gets created each frame.
180 //
181 // Normally, you would create a bind_group in the Queue set,
182 // but this doesn't work with the post_process_write().
183 // The reason it doesn't work is because each post_process_write will alternate the source/destination.
184 // The only way to have the correct source/destination for the bind_group
185 // is to make sure you get it during the node execution.
186 let bind_group = render_context.render_device().create_bind_group(
187 "post_process_bind_group",
188 &post_process_pipeline.layout,
189 // It's important for this to match the BindGroupLayout defined in the PostProcessPipeline
190 &BindGroupEntries::sequential((
191 // Make sure to use the source view
192 post_process.source,
193 // Use the sampler created for the pipeline
194 &post_process_pipeline.sampler,
195 // Set the settings binding
196 settings_binding.clone(),
197 )),
198 );
199
200 // Begin the render pass
201 let mut render_pass = render_context.begin_tracked_render_pass(RenderPassDescriptor {
202 label: Some("post_process_pass"),
203 color_attachments: &[Some(RenderPassColorAttachment {
204 // We need to specify the post process destination view here
205 // to make sure we write to the appropriate texture.
206 view: post_process.destination,
207 resolve_target: None,
208 ops: Operations::default(),
209 })],
210 depth_stencil_attachment: None,
211 timestamp_writes: None,
212 occlusion_query_set: None,
213 });
214
215 // This is mostly just wgpu boilerplate for drawing a fullscreen triangle,
216 // using the pipeline/bind_group created above
217 render_pass.set_render_pipeline(pipeline);
218 // By passing in the index of the post process settings on this view, we ensure
219 // that in the event that multiple settings were sent to the GPU (as would be the
220 // case with multiple cameras), we use the correct one.
221 render_pass.set_bind_group(0, &bind_group, &[settings_index.index()]);
222 render_pass.draw(0..3, 0..1);
223
224 Ok(())
225 }
Trait Implementations§
Source§impl Component for ViewTarget
impl Component for ViewTarget
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>
],
while immutable components will instead have [Component<Mutability = Immutable>
]. Read moreSource§fn register_required_components(
requiree: ComponentId,
components: &mut ComponentsRegistrator<'_>,
required_components: &mut RequiredComponents,
inheritance_depth: u16,
recursion_check_stack: &mut Vec<ComponentId>,
)
fn register_required_components( requiree: ComponentId, components: &mut ComponentsRegistrator<'_>, required_components: &mut RequiredComponents, inheritance_depth: u16, recursion_check_stack: &mut Vec<ComponentId>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn register_component_hooks(hooks: &mut ComponentHooks)
fn register_component_hooks(hooks: &mut ComponentHooks)
Component::on_add
, etc.)ComponentHooks
.Source§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_replace() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper
. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component
, this is populated by annotating fields containing entities with #[entities]
Read moreAuto Trait Implementations§
impl Freeze for ViewTarget
impl !RefUnwindSafe for ViewTarget
impl Send for ViewTarget
impl Sync for ViewTarget
impl Unpin for ViewTarget
impl !UnwindSafe for ViewTarget
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ids: &mut impl FnMut(ComponentId), )
Source§fn register_required_components(
components: &mut ComponentsRegistrator<'_>,
required_components: &mut RequiredComponents,
)
fn register_required_components( components: &mut ComponentsRegistrator<'_>, required_components: &mut RequiredComponents, )
Bundle
.Source§fn get_component_ids(
components: &Components,
ids: &mut impl FnMut(Option<ComponentId>),
)
fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components( self, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.