use crate::{primitives::Frustum, Camera, CameraProjection, OrthographicProjection, Projection};1use bevy_ecs::prelude::*;2use bevy_reflect::{std_traits::ReflectDefault, Reflect, ReflectDeserialize, ReflectSerialize};3use bevy_transform::prelude::{GlobalTransform, Transform};4use serde::{Deserialize, Serialize};5use wgpu_types::{LoadOp, TextureUsages};67/// A 2D camera component. Enables the 2D render graph for a [`Camera`].8#[derive(Component, Default, Reflect, Clone)]9#[reflect(Component, Default, Clone)]10#[require(11Camera,12Projection::Orthographic(OrthographicProjection::default_2d()),13Frustum = OrthographicProjection::default_2d().compute_frustum(&GlobalTransform::from(Transform::default())),14)]15pub struct Camera2d;1617/// A 3D camera component. Enables the main 3D render graph for a [`Camera`].18///19/// The camera coordinate space is right-handed X-right, Y-up, Z-back.20/// This means "forward" is -Z.21#[derive(Component, Reflect, Clone)]22#[reflect(Component, Default, Clone)]23#[require(Camera, Projection)]24pub struct Camera3d {25/// The depth clear operation to perform for the main 3d pass.26pub depth_load_op: Camera3dDepthLoadOp,27/// The texture usages for the depth texture created for the main 3d pass.28pub depth_texture_usages: Camera3dDepthTextureUsage,29/// How many individual steps should be performed in the `Transmissive3d` pass.30///31/// Roughly corresponds to how many “layers of transparency” are rendered for screen space32/// specular transmissive objects. Each step requires making one additional33/// texture copy, so it's recommended to keep this number to a reasonably low value. Defaults to `1`.34///35/// ### Notes36///37/// - No copies will be performed if there are no transmissive materials currently being rendered,38/// regardless of this setting.39/// - Setting this to `0` disables the screen-space refraction effect entirely, and falls40/// back to refracting only the environment map light's texture.41/// - If set to more than `0`, any opaque [`clear_color`](Camera::clear_color) will obscure the environment42/// map light's texture, preventing it from being visible “through” transmissive materials. If you'd like43/// to still have the environment map show up in your refractions, you can set the clear color's alpha to `0.0`.44/// Keep in mind that depending on the platform and your window settings, this may cause the window to become45/// transparent.46pub screen_space_specular_transmission_steps: usize,47/// The quality of the screen space specular transmission blur effect, applied to whatever's “behind” transmissive48/// objects when their `roughness` is greater than `0.0`.49///50/// Higher qualities are more GPU-intensive.51///52/// **Note:** You can get better-looking results at any quality level by enabling TAA. See: `TemporalAntiAliasPlugin`53pub screen_space_specular_transmission_quality: ScreenSpaceTransmissionQuality,54}5556impl Default for Camera3d {57fn default() -> Self {58Self {59depth_load_op: Default::default(),60depth_texture_usages: TextureUsages::RENDER_ATTACHMENT.into(),61screen_space_specular_transmission_steps: 1,62screen_space_specular_transmission_quality: Default::default(),63}64}65}6667#[derive(Clone, Copy, Reflect, Serialize, Deserialize)]68#[reflect(Serialize, Deserialize, Clone)]69pub struct Camera3dDepthTextureUsage(pub u32);7071impl From<TextureUsages> for Camera3dDepthTextureUsage {72fn from(value: TextureUsages) -> Self {73Self(value.bits())74}75}7677impl From<Camera3dDepthTextureUsage> for TextureUsages {78fn from(value: Camera3dDepthTextureUsage) -> Self {79Self::from_bits_truncate(value.0)80}81}8283/// The depth clear operation to perform for the main 3d pass.84#[derive(Reflect, Serialize, Deserialize, Clone, Debug)]85#[reflect(Serialize, Deserialize, Clone, Default)]86pub enum Camera3dDepthLoadOp {87/// Clear with a specified value.88/// Note that 0.0 is the far plane due to bevy's use of reverse-z projections.89Clear(f32),90/// Load from memory.91Load,92}9394impl Default for Camera3dDepthLoadOp {95fn default() -> Self {96Camera3dDepthLoadOp::Clear(0.0)97}98}99100impl From<Camera3dDepthLoadOp> for LoadOp<f32> {101fn from(config: Camera3dDepthLoadOp) -> Self {102match config {103Camera3dDepthLoadOp::Clear(x) => LoadOp::Clear(x),104Camera3dDepthLoadOp::Load => LoadOp::Load,105}106}107}108109/// The quality of the screen space transmission blur effect, applied to whatever's “behind” transmissive110/// objects when their `roughness` is greater than `0.0`.111///112/// Higher qualities are more GPU-intensive.113///114/// **Note:** You can get better-looking results at any quality level by enabling TAA. See: `TemporalAntiAliasPlugin`115#[derive(Resource, Default, Clone, Copy, Reflect, PartialEq, PartialOrd, Debug)]116#[reflect(Resource, Default, Clone, Debug, PartialEq)]117pub enum ScreenSpaceTransmissionQuality {118/// Best performance at the cost of quality. Suitable for lower end GPUs. (e.g. Mobile)119///120/// `num_taps` = 4121Low,122123/// A balanced option between quality and performance.124///125/// `num_taps` = 8126#[default]127Medium,128129/// Better quality. Suitable for high end GPUs. (e.g. Desktop)130///131/// `num_taps` = 16132High,133134/// The highest quality, suitable for non-realtime rendering. (e.g. Pre-rendered cinematics and photo mode)135///136/// `num_taps` = 32137Ultra,138}139140141