bevy_camera/clear_color.rs
1use bevy_color::Color;
2use bevy_derive::{Deref, DerefMut};
3use bevy_ecs::prelude::*;
4use bevy_reflect::prelude::*;
5use derive_more::derive::From;
6use serde::{Deserialize, Serialize};
7
8/// For a camera, specifies the color used to clear the viewport
9/// [before rendering](crate::camera::Camera::clear_color)
10/// or when [writing to the final render target texture](crate::camera::Camera::output_mode).
11#[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default, From)]
12#[reflect(Serialize, Deserialize, Default, Clone)]
13pub enum ClearColorConfig {
14 /// The clear color is taken from the world's [`ClearColor`] resource.
15 #[default]
16 Default,
17 /// The given clear color is used, overriding the [`ClearColor`] resource defined in the world.
18 Custom(Color),
19 /// No clear color is used: the camera will simply draw on top of anything already in the viewport.
20 ///
21 /// This can be useful when multiple cameras are rendering to the same viewport.
22 None,
23}
24
25/// Controls when MSAA writeback occurs for a camera.
26///
27/// MSAA writeback copies the previous camera's output into the MSAA sampled texture before
28/// rendering, allowing multiple cameras to layer their results when MSAA is enabled.
29#[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default, PartialEq, Eq)]
30#[reflect(Serialize, Deserialize, Default, Clone)]
31pub enum MsaaWriteback {
32 /// Never perform MSAA writeback for this camera.
33 Off,
34 /// Perform MSAA writeback only when this camera is not the first one rendering to the target.
35 /// This is the default behavior - the first camera has nothing to write back.
36 #[default]
37 Auto,
38 /// Always perform MSAA writeback, even if this is the first camera rendering to the target.
39 /// This is useful when content has been written directly to the main texture (e.g., via
40 /// `write_texture`) and needs to be preserved through the MSAA render pass.
41 Always,
42}
43
44/// A [`Resource`] that stores the default color that cameras use to clear the screen between frames.
45///
46/// This color appears as the "background" color for simple apps,
47/// when there are portions of the screen with nothing rendered.
48///
49/// Individual cameras may use [`Camera.clear_color`] to specify a different
50/// clear color or opt out of clearing their viewport.
51///
52/// [`Camera.clear_color`]: crate::camera::Camera::clear_color
53#[derive(Resource, Clone, Debug, Deref, DerefMut, Reflect)]
54#[reflect(Resource, Default, Debug, Clone)]
55pub struct ClearColor(pub Color);
56
57/// Match the dark gray bevy website code block color by default.
58impl Default for ClearColor {
59 fn default() -> Self {
60 Self(Color::srgb_u8(43, 44, 47))
61 }
62}