Skip to content

Commit b14f94e

Browse files
atlv24mockersf
authored andcommitted
doc(render): fix incorrectly transposed view matrix docs (#19317)
# Objective - Mend incorrect docs ## Solution - Mend them - add example use - clarify column major ## Testing - No code changes
1 parent 4562bb4 commit b14f94e

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

crates/bevy_render/src/view/mod.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -262,34 +262,36 @@ impl RetainedViewEntity {
262262
pub struct ExtractedView {
263263
/// The entity in the main world corresponding to this render world view.
264264
pub retained_view_entity: RetainedViewEntity,
265-
/// Typically a right-handed projection matrix, one of either:
265+
/// Typically a column-major right-handed projection matrix, one of either:
266266
///
267267
/// Perspective (infinite reverse z)
268268
/// ```text
269269
/// f = 1 / tan(fov_y_radians / 2)
270270
///
271-
/// ⎡ f / aspect 0 0 0 ⎤
272-
/// ⎢ 0 f 0 0 ⎥
273-
/// ⎢ 0 0 0 -1
274-
/// ⎣ 0 0 near 0 ⎦
271+
/// ⎡ f / aspect 0 0 0 ⎤
272+
/// ⎢ 0 f 0 0 ⎥
273+
/// ⎢ 0 0 0 near
274+
/// ⎣ 0 0 -1 0 ⎦
275275
/// ```
276276
///
277277
/// Orthographic
278278
/// ```text
279279
/// w = right - left
280280
/// h = top - bottom
281-
/// d = near - far
281+
/// d = far - near
282282
/// cw = -right - left
283283
/// ch = -top - bottom
284284
///
285-
/// ⎡ 2 / w 0 0 0
286-
/// ⎢ 0 2 / h 0 0
287-
/// ⎢ 0 0 1 / d 0
288-
/// ⎣ cw / w ch / h near / d 1 ⎦
285+
/// ⎡ 2 / w 0 0 cw / w
286+
/// ⎢ 0 2 / h 0 ch / h
287+
/// ⎢ 0 0 1 / d far / d
288+
/// ⎣ 0 0 0 1 ⎦
289289
/// ```
290290
///
291291
/// `clip_from_view[3][3] == 1.0` is the standard way to check if a projection is orthographic
292292
///
293+
/// Glam matrices are column major, so for example getting the near plane of a perspective projection is `clip_from_view[3][2]`
294+
///
293295
/// Custom projections are also possible however.
294296
pub clip_from_view: Mat4,
295297
pub world_from_view: GlobalTransform,
@@ -529,34 +531,36 @@ pub struct ViewUniform {
529531
pub world_from_clip: Mat4,
530532
pub world_from_view: Mat4,
531533
pub view_from_world: Mat4,
532-
/// Typically a right-handed projection matrix, one of either:
534+
/// Typically a column-major right-handed projection matrix, one of either:
533535
///
534536
/// Perspective (infinite reverse z)
535537
/// ```text
536538
/// f = 1 / tan(fov_y_radians / 2)
537539
///
538-
/// ⎡ f / aspect 0 0 0 ⎤
539-
/// ⎢ 0 f 0 0 ⎥
540-
/// ⎢ 0 0 0 -1
541-
/// ⎣ 0 0 near 0 ⎦
540+
/// ⎡ f / aspect 0 0 0 ⎤
541+
/// ⎢ 0 f 0 0 ⎥
542+
/// ⎢ 0 0 0 near
543+
/// ⎣ 0 0 -1 0 ⎦
542544
/// ```
543545
///
544546
/// Orthographic
545547
/// ```text
546548
/// w = right - left
547549
/// h = top - bottom
548-
/// d = near - far
550+
/// d = far - near
549551
/// cw = -right - left
550552
/// ch = -top - bottom
551553
///
552-
/// ⎡ 2 / w 0 0 0
553-
/// ⎢ 0 2 / h 0 0
554-
/// ⎢ 0 0 1 / d 0
555-
/// ⎣ cw / w ch / h near / d 1 ⎦
554+
/// ⎡ 2 / w 0 0 cw / w
555+
/// ⎢ 0 2 / h 0 ch / h
556+
/// ⎢ 0 0 1 / d far / d
557+
/// ⎣ 0 0 0 1 ⎦
556558
/// ```
557559
///
558560
/// `clip_from_view[3][3] == 1.0` is the standard way to check if a projection is orthographic
559561
///
562+
/// Glam matrices are column major, so for example getting the near plane of a perspective projection is `clip_from_view[3][2]`
563+
///
560564
/// Custom projections are also possible however.
561565
pub clip_from_view: Mat4,
562566
pub view_from_clip: Mat4,

crates/bevy_render/src/view/view.wgsl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,35 @@ struct View {
1919
world_from_clip: mat4x4<f32>,
2020
world_from_view: mat4x4<f32>,
2121
view_from_world: mat4x4<f32>,
22-
// Typically a right-handed projection matrix, one of either:
22+
// Typically a column-major right-handed projection matrix, one of either:
2323
//
2424
// Perspective (infinite reverse z)
2525
// ```
2626
// f = 1 / tan(fov_y_radians / 2)
2727
//
28-
// ⎡ f / aspect 0 0 0 ⎤
29-
// ⎢ 0 f 0 0 ⎥
30-
// ⎢ 0 0 0 -1
31-
// ⎣ 0 0 near 0 ⎦
28+
// ⎡ f / aspect 0 0 0 ⎤
29+
// ⎢ 0 f 0 0 ⎥
30+
// ⎢ 0 0 0 near
31+
// ⎣ 0 0 -1 0 ⎦
3232
// ```
3333
//
3434
// Orthographic
3535
// ```
3636
// w = right - left
3737
// h = top - bottom
38-
// d = near - far
38+
// d = far - near
3939
// cw = -right - left
4040
// ch = -top - bottom
4141
//
42-
// ⎡ 2 / w 0 0 0
43-
// ⎢ 0 2 / h 0 0
44-
// ⎢ 0 0 1 / d 0
45-
// ⎣ cw / w ch / h near / d 1 ⎦
42+
// ⎡ 2 / w 0 0 cw / w
43+
// ⎢ 0 2 / h 0 ch / h
44+
// ⎢ 0 0 1 / d far / d
45+
// ⎣ 0 0 0 1 ⎦
4646
// ```
4747
//
4848
// `clip_from_view[3][3] == 1.0` is the standard way to check if a projection is orthographic
49+
//
50+
// Wgsl matrices are column major, so for example getting the near plane of a perspective projection is `clip_from_view[3][2]`
4951
//
5052
// Custom projections are also possible however.
5153
clip_from_view: mat4x4<f32>,

0 commit comments

Comments
 (0)