bevy_render::camera

Struct Camera

Source
pub struct Camera {
    pub viewport: Option<Viewport>,
    pub order: isize,
    pub is_active: bool,
    pub computed: ComputedCameraValues,
    pub target: RenderTarget,
    pub hdr: bool,
    pub output_mode: CameraOutputMode,
    pub msaa_writeback: bool,
    pub clear_color: ClearColorConfig,
}
Expand description

The defining Component for camera entities, storing information about how and what to render through this camera.

The Camera component is added to an entity to define the properties of the viewpoint from which rendering occurs. It defines the position of the view to render, the projection method to transform the 3D objects into a 2D image, as well as the render target into which that image is produced.

Adding a camera is typically done by adding a bundle, either the Camera2dBundle or the Camera3dBundle.

Fields§

§viewport: Option<Viewport>

If set, this camera will render to the given Viewport rectangle within the configured RenderTarget.

§order: isize

Cameras with a higher order are rendered later, and thus on top of lower order cameras.

§is_active: bool

If this is set to true, this camera will be rendered to its specified RenderTarget. If false, this camera will not be rendered.

§computed: ComputedCameraValues

Computed values for this camera, such as the projection matrix and the render target size.

§target: RenderTarget

The “target” that this camera will render to.

§hdr: bool

If this is set to true, the camera will use an intermediate “high dynamic range” render texture. This allows rendering with a wider range of lighting values.

§output_mode: CameraOutputMode

The CameraOutputMode for this camera.

§msaa_writeback: bool

If this is enabled, a previous camera exists that shares this camera’s render target, and this camera has MSAA enabled, then the previous camera’s outputs will be written to the intermediate multi-sampled render target textures for this camera. This enables cameras with MSAA enabled to “write their results on top” of previous camera results, and include them as a part of their render results. This is enabled by default to ensure cameras with MSAA enabled layer their results in the same way as cameras without MSAA enabled by default.

§clear_color: ClearColorConfig

The clear color operation to perform on the render target.

Implementations§

Source§

impl Camera

Source

pub fn to_logical(&self, physical_size: UVec2) -> Option<Vec2>

Converts a physical size in this Camera to a logical size.

Source

pub fn physical_viewport_rect(&self) -> Option<URect>

The rendered physical bounds URect of the camera. If the viewport field is set to Some, this will be the rect of that custom viewport. Otherwise it will default to the full physical rect of the current RenderTarget.

Source

pub fn logical_viewport_rect(&self) -> Option<Rect>

The rendered logical bounds Rect of the camera. If the viewport field is set to Some, this will be the rect of that custom viewport. Otherwise it will default to the full logical rect of the current RenderTarget.

Source

pub fn logical_viewport_size(&self) -> Option<Vec2>

The logical size of this camera’s viewport. If the viewport field is set to Some, this will be the size of that custom viewport. Otherwise it will default to the full logical size of the current RenderTarget. For logic that requires the full logical size of the RenderTarget, prefer Camera::logical_target_size.

Returns None if either:

  • the function is called just after the Camera is created, before camera_system is executed,
  • the RenderTarget isn’t correctly set:
    • it references the PrimaryWindow when there is none,
    • it references a Window entity that doesn’t exist or doesn’t actually have a Window component,
    • it references an Image that doesn’t exist (invalid handle),
    • it references a TextureView that doesn’t exist (invalid handle).
Source

pub fn physical_viewport_size(&self) -> Option<UVec2>

The physical size of this camera’s viewport (in physical pixels). If the viewport field is set to Some, this will be the size of that custom viewport. Otherwise it will default to the full physical size of the current RenderTarget. For logic that requires the full physical size of the RenderTarget, prefer Camera::physical_target_size.

Source

pub fn logical_target_size(&self) -> Option<Vec2>

The full logical size of this camera’s RenderTarget, ignoring custom viewport configuration. Note that if the viewport field is Some, this will not represent the size of the rendered area. For logic that requires the size of the actually rendered area, prefer Camera::logical_viewport_size.

Source

pub fn physical_target_size(&self) -> Option<UVec2>

The full physical size of this camera’s RenderTarget (in physical pixels), ignoring custom viewport configuration. Note that if the viewport field is Some, this will not represent the size of the rendered area. For logic that requires the size of the actually rendered area, prefer Camera::physical_viewport_size.

Source

pub fn target_scaling_factor(&self) -> Option<f32>

Source

pub fn clip_from_view(&self) -> Mat4

The projection matrix computed using this camera’s CameraProjection.

Source

pub fn world_to_viewport( &self, camera_transform: &GlobalTransform, world_position: Vec3, ) -> Option<Vec2>

Given a position in world space, use the camera to compute the viewport-space coordinates.

To get the coordinates in Normalized Device Coordinates, you should use world_to_ndc.

Returns None if any of these conditions occur:

  • The computed coordinates are beyond the near or far plane
  • The logical viewport size cannot be computed. See logical_viewport_size
  • The world coordinates cannot be mapped to the Normalized Device Coordinates. See world_to_ndc May also panic if glam_assert is enabled. See world_to_ndc.
Source

pub fn viewport_to_world( &self, camera_transform: &GlobalTransform, viewport_position: Vec2, ) -> Option<Ray3d>

Returns a ray originating from the camera, that passes through everything beyond viewport_position.

The resulting ray starts on the near plane of the camera.

If the camera’s projection is orthographic the direction of the ray is always equal to camera_transform.forward().

To get the world space coordinates with Normalized Device Coordinates, you should use ndc_to_world.

Returns None if any of these conditions occur:

  • The logical viewport size cannot be computed. See logical_viewport_size
  • The near or far plane cannot be computed. This can happen if the camera_transform, the world_position, or the projection matrix defined by CameraProjection contain NAN. Panics if the projection matrix is null and glam_assert is enabled.
Source

pub fn viewport_to_world_2d( &self, camera_transform: &GlobalTransform, viewport_position: Vec2, ) -> Option<Vec2>

Returns a 2D world position computed from a position on this Camera’s viewport.

Useful for 2D cameras and other cameras with an orthographic projection pointing along the Z axis.

To get the world space coordinates with Normalized Device Coordinates, you should use ndc_to_world.

Returns None if any of these conditions occur:

Source

pub fn world_to_ndc( &self, camera_transform: &GlobalTransform, world_position: Vec3, ) -> Option<Vec3>

Given a position in world space, use the camera’s viewport to compute the Normalized Device Coordinates.

When the position is within the viewport the values returned will be between -1.0 and 1.0 on the X and Y axes, and between 0.0 and 1.0 on the Z axis. To get the coordinates in the render target’s viewport dimensions, you should use world_to_viewport.

Returns None if the camera_transform, the world_position, or the projection matrix defined by CameraProjection contain NAN. Panics if the camera_transform contains NAN and the glam_assert feature is enabled.

Source

pub fn ndc_to_world( &self, camera_transform: &GlobalTransform, ndc: Vec3, ) -> Option<Vec3>

Given a position in Normalized Device Coordinates, use the camera’s viewport to compute the world space position.

When the position is within the viewport the values returned will be between -1.0 and 1.0 on the X and Y axes, and between 0.0 and 1.0 on the Z axis. To get the world space coordinates with the viewport position, you should use world_to_viewport.

Returns None if the camera_transform, the world_position, or the projection matrix defined by CameraProjection contain NAN. Panics if the projection matrix is null and glam_assert is enabled.

Trait Implementations§

Source§

impl Clone for Camera

Source§

fn clone(&self) -> Camera

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for Camera
where Self: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::Table

A constant indicating the storage type used for this component.
Source§

fn register_component_hooks(_hooks: &mut ComponentHooks)

Called when registering this component, allowing mutable access to its ComponentHooks.
Source§

impl Debug for Camera

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Camera

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl FromReflect for Camera
where Self: Any + Send + Sync, Option<Viewport>: FromReflect + TypePath + RegisterForReflection, isize: FromReflect + TypePath + RegisterForReflection, bool: FromReflect + TypePath + RegisterForReflection, ClearColorConfig: FromReflect + TypePath + RegisterForReflection,

Source§

fn from_reflect(reflect: &dyn Reflect) -> Option<Self>

Constructs a concrete instance of Self from a reflected value.
Source§

fn take_from_reflect( reflect: Box<dyn Reflect>, ) -> Result<Self, Box<dyn Reflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
Source§

impl GetTypeRegistration for Camera
where Self: Any + Send + Sync, Option<Viewport>: FromReflect + TypePath + RegisterForReflection, isize: FromReflect + TypePath + RegisterForReflection, bool: FromReflect + TypePath + RegisterForReflection, ClearColorConfig: FromReflect + TypePath + RegisterForReflection,

Source§

fn get_type_registration() -> TypeRegistration

Returns the default TypeRegistration for this type.
Source§

fn register_type_dependencies(registry: &mut TypeRegistry)

Registers other types needed by this type. Read more
Source§

impl Reflect for Camera
where Self: Any + Send + Sync, Option<Viewport>: FromReflect + TypePath + RegisterForReflection, isize: FromReflect + TypePath + RegisterForReflection, bool: FromReflect + TypePath + RegisterForReflection, ClearColorConfig: FromReflect + TypePath + RegisterForReflection,

Source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
Source§

fn into_any(self: Box<Self>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>.
Source§

fn as_any(&self) -> &dyn Any

Returns the value as a &dyn Any.
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Returns the value as a &mut dyn Any.
Source§

fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>

Casts this type to a boxed reflected value.
Source§

fn as_reflect(&self) -> &dyn Reflect

Casts this type to a reflected value.
Source§

fn as_reflect_mut(&mut self) -> &mut dyn Reflect

Casts this type to a mutable reflected value.
Source§

fn clone_value(&self) -> Box<dyn Reflect>

Clones the value as a Reflect trait object. Read more
Source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
Source§

fn try_apply(&mut self, value: &dyn Reflect) -> Result<(), ApplyError>

Tries to apply a reflected value to this value. Read more
Source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
Source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
Source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
Source§

fn reflect_owned(self: Box<Self>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
Source§

fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>

Returns a “partial equality” comparison result. Read more
Source§

fn apply(&mut self, value: &(dyn Reflect + 'static))

Applies a reflected value to this value. Read more
Source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
Source§

fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Debug formatter for the value. Read more
Source§

fn serializable(&self) -> Option<Serializable<'_>>

Returns a serializable version of the value. Read more
Source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
Source§

impl Struct for Camera
where Self: Any + Send + Sync, Option<Viewport>: FromReflect + TypePath + RegisterForReflection, isize: FromReflect + TypePath + RegisterForReflection, bool: FromReflect + TypePath + RegisterForReflection, ClearColorConfig: FromReflect + TypePath + RegisterForReflection,

Source§

fn field(&self, name: &str) -> Option<&dyn Reflect>

Returns a reference to the value of the field named name as a &dyn Reflect.
Source§

fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>

Returns a mutable reference to the value of the field named name as a &mut dyn Reflect.
Source§

fn field_at(&self, index: usize) -> Option<&dyn Reflect>

Returns a reference to the value of the field with index index as a &dyn Reflect.
Source§

fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>

Returns a mutable reference to the value of the field with index index as a &mut dyn Reflect.
Source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
Source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
Source§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
Source§

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.
Source§

impl TypePath for Camera
where Self: Any + Send + Sync,

Source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
Source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
Source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
Source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
Source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
Source§

impl Typed for Camera
where Self: Any + Send + Sync, Option<Viewport>: FromReflect + TypePath + RegisterForReflection, isize: FromReflect + TypePath + RegisterForReflection, bool: FromReflect + TypePath + RegisterForReflection, ClearColorConfig: FromReflect + TypePath + RegisterForReflection,

Source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

Auto Trait Implementations§

§

impl Freeze for Camera

§

impl !RefUnwindSafe for Camera

§

impl Send for Camera

§

impl Sync for Camera

§

impl Unpin for Camera

§

impl !UnwindSafe for Camera

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId), )

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

Source§

fn get_component_ids( components: &Components, ids: &mut impl FnMut(Option<ComponentId>), )

Gets this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))

Source§

impl<T> DynamicTypePath for T
where T: TypePath,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World.
Source§

impl<S> GetField for S
where S: Struct,

Source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
Source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
Source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

Source§

fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
Source§

fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
Source§

fn path<'p, T>( &self, path: impl ReflectPath<'p>, ) -> Result<&T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
Source§

fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,