diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index f3a6291292..22af7ffb44 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -186,6 +186,35 @@ impl Msaa { #[derive(Component)] pub struct ExtractedView { + /// Typically a right-handed projection matrix, one of either: + /// + /// Perspective (infinite reverse z) + /// ```text + /// f = 1 / tan(fov_y_radians / 2) + /// + /// ⎡ f / aspect 0 0 0 ⎤ + /// ⎢ 0 f 0 0 ⎥ + /// ⎢ 0 0 0 -1 ⎥ + /// ⎣ 0 0 near 0 ⎦ + /// ``` + /// + /// Orthographic + /// ```text + /// w = right - left + /// h = top - bottom + /// d = near - far + /// cw = -right - left + /// ch = -top - bottom + /// + /// ⎡ 2 / w 0 0 0 ⎤ + /// ⎢ 0 2 / h 0 0 ⎥ + /// ⎢ 0 0 1 / d 0 ⎥ + /// ⎣ cw / w ch / h near / d 1 ⎦ + /// ``` + /// + /// `clip_from_view[3][3] == 1.0` is the standard way to check if a projection is orthographic + /// + /// Custom projections are also possible however. pub clip_from_view: Mat4, pub world_from_view: GlobalTransform, // The view-projection matrix. When provided it is used instead of deriving it from @@ -423,6 +452,35 @@ pub struct ViewUniform { pub world_from_clip: Mat4, pub world_from_view: Mat4, pub view_from_world: Mat4, + /// Typically a right-handed projection matrix, one of either: + /// + /// Perspective (infinite reverse z) + /// ```text + /// f = 1 / tan(fov_y_radians / 2) + /// + /// ⎡ f / aspect 0 0 0 ⎤ + /// ⎢ 0 f 0 0 ⎥ + /// ⎢ 0 0 0 -1 ⎥ + /// ⎣ 0 0 near 0 ⎦ + /// ``` + /// + /// Orthographic + /// ```text + /// w = right - left + /// h = top - bottom + /// d = near - far + /// cw = -right - left + /// ch = -top - bottom + /// + /// ⎡ 2 / w 0 0 0 ⎤ + /// ⎢ 0 2 / h 0 0 ⎥ + /// ⎢ 0 0 1 / d 0 ⎥ + /// ⎣ cw / w ch / h near / d 1 ⎦ + /// ``` + /// + /// `clip_from_view[3][3] == 1.0` is the standard way to check if a projection is orthographic + /// + /// Custom projections are also possible however. pub clip_from_view: Mat4, pub view_from_clip: Mat4, pub world_position: Vec3, diff --git a/crates/bevy_render/src/view/view.wgsl b/crates/bevy_render/src/view/view.wgsl index 46ba189dad..ed08599758 100644 --- a/crates/bevy_render/src/view/view.wgsl +++ b/crates/bevy_render/src/view/view.wgsl @@ -19,6 +19,35 @@ struct View { world_from_clip: mat4x4, world_from_view: mat4x4, view_from_world: mat4x4, + // Typically a right-handed projection matrix, one of either: + // + // Perspective (infinite reverse z) + // ``` + // f = 1 / tan(fov_y_radians / 2) + // + // ⎡ f / aspect 0 0 0 ⎤ + // ⎢ 0 f 0 0 ⎥ + // ⎢ 0 0 0 -1 ⎥ + // ⎣ 0 0 near 0 ⎦ + // ``` + // + // Orthographic + // ``` + // w = right - left + // h = top - bottom + // d = near - far + // cw = -right - left + // ch = -top - bottom + // + // ⎡ 2 / w 0 0 0 ⎤ + // ⎢ 0 2 / h 0 0 ⎥ + // ⎢ 0 0 1 / d 0 ⎥ + // ⎣ cw / w ch / h near / d 1 ⎦ + // ``` + // + // `clip_from_view[3][3] == 1.0` is the standard way to check if a projection is orthographic + // + // Custom projections are also possible however. clip_from_view: mat4x4, view_from_clip: mat4x4, world_position: vec3,