Struct bevy::render::prelude::Camera

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,
}
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.

Implementations§

§

impl Camera

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

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

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.

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.

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

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

The physical 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 physical size of the current RenderTarget. For logic that requires the full physical size of the RenderTarget, prefer Camera::physical_target_size.

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.

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

The full physical 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::physical_viewport_size.

pub fn projection_matrix(&self) -> Mat4

The projection matrix computed using this camera’s CameraProjection.

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.

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

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.

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:

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.

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§

§

impl Clone for Camera

§

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
§

impl Component for Camerawhere Camera: Send + Sync + 'static,

§

type Storage = TableStorage

A marker type indicating the storage type used for this component. This must be either TableStorage or SparseStorage.
§

impl Debug for Camera

§

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

Formats the value using the given formatter. Read more
§

impl Default for Camera

§

fn default() -> Camera

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

impl FromReflect for Camerawhere Option<Viewport>: FromReflect + TypePath, isize: FromReflect + TypePath, bool: FromReflect + TypePath, ComputedCameraValues: Any + Send + Sync + Default, RenderTarget: Any + Send + Sync + Default, CameraOutputMode: Any + Send + Sync + Default,

§

fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<Camera>

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

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

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

impl GetTypeRegistration for Camerawhere Option<Viewport>: FromReflect + TypePath, isize: FromReflect + TypePath, bool: FromReflect + TypePath, ComputedCameraValues: Any + Send + Sync, RenderTarget: Any + Send + Sync, CameraOutputMode: Any + Send + Sync,

§

impl Reflect for Camerawhere Option<Viewport>: FromReflect + TypePath, isize: FromReflect + TypePath, bool: FromReflect + TypePath, ComputedCameraValues: Any + Send + Sync, RenderTarget: Any + Send + Sync, CameraOutputMode: Any + Send + Sync,

§

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

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

fn into_any(self: Box<Camera, Global>) -> Box<dyn Any, Global>

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

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any.
§

fn into_reflect(self: Box<Camera, Global>) -> Box<dyn Reflect, Global>

Casts this type to a boxed reflected value.
§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a reflected value.
§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable reflected value.
§

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

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

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

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

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

Applies a reflected value to this value. Read more
§

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

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

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

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

fn reflect_owned(self: Box<Camera, Global>) -> ReflectOwned

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

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

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

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

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

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

Debug formatter for the value. Read more
§

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

Returns a serializable version of the value. Read more
§

fn is_dynamic(&self) -> bool

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

impl Struct for Camerawhere Option<Viewport>: FromReflect + TypePath, isize: FromReflect + TypePath, bool: FromReflect + TypePath, ComputedCameraValues: Any + Send + Sync, RenderTarget: Any + Send + Sync, CameraOutputMode: Any + Send + Sync,

§

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

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

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

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

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

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

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

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

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

Returns the name of the field with index index.
§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
§

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

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

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.
§

impl TypePath for Camerawhere Option<Viewport>: FromReflect + TypePath, isize: FromReflect + TypePath, bool: FromReflect + TypePath, ComputedCameraValues: Any + Send + Sync, RenderTarget: Any + Send + Sync, CameraOutputMode: Any + Send + Sync,

§

fn type_path() -> &'static str

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

fn short_type_path() -> &'static str

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

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

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

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

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

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

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

impl Typed for Camerawhere Option<Viewport>: FromReflect + TypePath, isize: FromReflect + TypePath, bool: FromReflect + TypePath, ComputedCameraValues: Any + Send + Sync, RenderTarget: Any + Send + Sync, CameraOutputMode: Any + Send + Sync,

§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> 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 Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

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) -> Cwhere F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a, Aligned>,

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for Twhere T: Any,

§

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

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.
§

fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>

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

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

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

§

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

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

impl<C> DynamicBundle for Cwhere C: Component,

§

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

§

impl<T> DynamicTypePath for Twhere T: TypePath,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> FromWorld for Twhere T: Default,

§

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

Creates Self using data from the given World.
§

impl<S> GetField for Swhere S: Struct,

§

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.
§

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.
§

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

§

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
§

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
§

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
§

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
§

impl<T> Instrument for T

§

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

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

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 Twhere 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.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> NoneValue for Twhere T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for Pwhere R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

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

§

impl<T> Upcast<T> for T

§

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

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,

§

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

§

impl<T> WasmNotSend for Twhere T: Send,

§

impl<T> WasmNotSync for Twhere T: Sync,