Struct bevy::core_pipeline::motion_blur::MotionBlur
pub struct MotionBlur {
pub shutter_angle: f32,
pub samples: u32,
}
Expand description
A component that enables and configures motion blur when added to a camera.
Motion blur is an effect that simulates how moving objects blur as they change position during the exposure of film, a sensor, or an eyeball.
Because rendering simulates discrete steps in time, we use per-pixel motion vectors to estimate the path of objects between frames. This kind of implementation has some artifacts:
- Fast moving objects in front of a stationary object or when in front of empty space, will not have their edges blurred.
- Transparent objects do not write to depth or motion vectors, so they cannot be blurred.
Other approaches, such as A Reconstruction Filter for Plausible Motion Blur produce more correct results, but are more expensive and complex, and have other kinds of artifacts. This implementation is relatively inexpensive and effective.
§Usage
Add the MotionBlur
component to a camera to enable and configure motion blur for that
camera. Motion blur also requires the depth and motion vector prepass, which can be added more
easily to the camera with the MotionBlurBundle
.
commands.spawn((
Camera3dBundle::default(),
MotionBlurBundle::default(),
));
Fields§
§shutter_angle: f32
The strength of motion blur from 0.0
to 1.0
.
The shutter angle describes the fraction of a frame that a camera’s shutter is open and exposing the film/sensor. For 24fps cinematic film, a shutter angle of 0.5 (180 degrees) is common. This means that the shutter was open for half of the frame, or 1/48th of a second. The lower the shutter angle, the less exposure time and thus less blur.
A value greater than one is non-physical and results in an object’s blur stretching further than it traveled in that frame. This might be a desirable effect for artistic reasons, but consider allowing users to opt out of this.
This value is intentionally tied to framerate to avoid the aforementioned non-physical over-blurring. If you want to emulate a cinematic look, your options are:
- Framelimit your app to 24fps, and set the shutter angle to 0.5 (180 deg). Note that depending on artistic intent or the action of a scene, it is common to set the shutter angle between 0.125 (45 deg) and 0.5 (180 deg). This is the most faithful way to reproduce the look of film.
- Set the shutter angle greater than one. For example, to emulate the blur strength of
film while rendering at 60fps, you would set the shutter angle to
60/24 * 0.5 = 1.25
. Note that this will result in artifacts where the motion of objects will stretch further than they moved between frames; users may find this distracting.
samples: u32
The quality of motion blur, corresponding to the number of per-pixel samples taken in each direction during blur.
Setting this to 1
results in each pixel being sampled once in the leading direction, once
in the trailing direction, and once in the middle, for a total of 3 samples (1 * 2 + 1
).
Setting this to 3
will result in 3 * 2 + 1 = 7
samples. Setting this to 0
is
equivalent to disabling motion blur.
Trait Implementations§
§impl Clone for MotionBlur
impl Clone for MotionBlur
§fn clone(&self) -> MotionBlur
fn clone(&self) -> MotionBlur
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Component for MotionBlur
impl Component for MotionBlur
§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table
§fn register_component_hooks(_hooks: &mut ComponentHooks)
fn register_component_hooks(_hooks: &mut ComponentHooks)
ComponentHooks
.§impl CreateFrom for MotionBlurwhere
MotionBlur: ShaderType<ExtraMetadata = StructMetadata<2>>,
f32: for<'__> CreateFrom,
u32: for<'__> CreateFrom,
impl CreateFrom for MotionBlurwhere
MotionBlur: ShaderType<ExtraMetadata = StructMetadata<2>>,
f32: for<'__> CreateFrom,
u32: for<'__> CreateFrom,
fn create_from<B>(reader: &mut Reader<B>) -> MotionBlurwhere
B: BufferRef,
§impl Default for MotionBlur
impl Default for MotionBlur
§fn default() -> MotionBlur
fn default() -> MotionBlur
§impl ExtractComponent for MotionBlurwhere
MotionBlur: Clone,
impl ExtractComponent for MotionBlurwhere
MotionBlur: Clone,
§type QueryData = &'static MotionBlur
type QueryData = &'static MotionBlur
ReadOnlyQueryData
to fetch the components to extract.§type QueryFilter = With<Camera>
type QueryFilter = With<Camera>
§type Out = MotionBlur
type Out = MotionBlur
§fn extract_component(
item: <<MotionBlur as ExtractComponent>::QueryData as WorldQuery>::Item<'_>
) -> Option<<MotionBlur as ExtractComponent>::Out>
fn extract_component( item: <<MotionBlur as ExtractComponent>::QueryData as WorldQuery>::Item<'_> ) -> Option<<MotionBlur as ExtractComponent>::Out>
§impl FromReflect for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
impl FromReflect for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
§fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<MotionBlur>
fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<MotionBlur>
Self
from a reflected value.§fn take_from_reflect(
reflect: Box<dyn Reflect>
) -> Result<Self, Box<dyn Reflect>>
fn take_from_reflect( reflect: Box<dyn Reflect> ) -> Result<Self, Box<dyn Reflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read more§impl GetTypeRegistration for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
impl GetTypeRegistration for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration
for this type.§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
§impl ReadFrom for MotionBlurwhere
MotionBlur: ShaderType<ExtraMetadata = StructMetadata<2>>,
f32: for<'__> ReadFrom,
u32: for<'__> ReadFrom,
impl ReadFrom for MotionBlurwhere
MotionBlur: ShaderType<ExtraMetadata = StructMetadata<2>>,
f32: for<'__> ReadFrom,
u32: for<'__> ReadFrom,
§impl Reflect for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
impl Reflect for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
§fn into_any(self: Box<MotionBlur>) -> Box<dyn Any>
fn into_any(self: Box<MotionBlur>) -> Box<dyn Any>
Box<dyn Any>
.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut dyn Any
.§fn into_reflect(self: Box<MotionBlur>) -> Box<dyn Reflect>
fn into_reflect(self: Box<MotionBlur>) -> Box<dyn Reflect>
§fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
§fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
§fn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read more§fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + 'static))
§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
§fn reflect_owned(self: Box<MotionBlur>) -> ReflectOwned
fn reflect_owned(self: Box<MotionBlur>) -> ReflectOwned
§fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
§impl ShaderSize for MotionBlur
impl ShaderSize for MotionBlur
§const SHADER_SIZE: NonZero<u64> = _
const SHADER_SIZE: NonZero<u64> = _
ShaderType::min_size
)§impl ShaderType for MotionBlur
impl ShaderType for MotionBlur
§fn assert_uniform_compat()
fn assert_uniform_compat()
Self
meets the requirements of the
uniform address space restrictions on stored values and the
uniform address space layout constraints Read more§impl Struct for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
impl Struct for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
§fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>
name
as a &dyn Reflect
.§fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>
name
as a
&mut dyn Reflect
.§fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
index
as a
&dyn Reflect
.§fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>
index
as a &mut dyn Reflect
.§fn iter_fields(&self) -> FieldIter<'_> ⓘ
fn iter_fields(&self) -> FieldIter<'_> ⓘ
§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.§impl TypePath for MotionBlur
impl TypePath for MotionBlur
§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
§impl Typed for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
impl Typed for MotionBlurwhere
MotionBlur: Any + Send + Sync,
f32: FromReflect + TypePath + RegisterForReflection,
u32: FromReflect + TypePath + RegisterForReflection,
§impl WriteInto for MotionBlurwhere
MotionBlur: ShaderType<ExtraMetadata = StructMetadata<2>>,
f32: for<'__> WriteInto,
u32: for<'__> WriteInto,
impl WriteInto for MotionBlurwhere
MotionBlur: ShaderType<ExtraMetadata = StructMetadata<2>>,
f32: for<'__> WriteInto,
u32: for<'__> WriteInto,
fn write_into<B>(&self, writer: &mut Writer<B>)where
B: BufferMut,
Auto Trait Implementations§
impl Freeze for MotionBlur
impl RefUnwindSafe for MotionBlur
impl Send for MotionBlur
impl Sync for MotionBlur
impl Unpin for MotionBlur
impl UnwindSafe for MotionBlur
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§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
§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.§impl<T> GetPath for T
impl<T> GetPath for T
§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>
) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p> ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more§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
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.