bevy/crates/bevy_render/src/view/view.wgsl
atlv b14f94ec34 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
2025-05-30 23:53:51 +02:00

67 lines
2.0 KiB
WebGPU Shading Language

#define_import_path bevy_render::view
struct ColorGrading {
balance: mat3x3<f32>,
saturation: vec3<f32>,
contrast: vec3<f32>,
gamma: vec3<f32>,
gain: vec3<f32>,
lift: vec3<f32>,
midtone_range: vec2<f32>,
exposure: f32,
hue: f32,
post_saturation: f32,
}
struct View {
clip_from_world: mat4x4<f32>,
unjittered_clip_from_world: mat4x4<f32>,
world_from_clip: mat4x4<f32>,
world_from_view: mat4x4<f32>,
view_from_world: mat4x4<f32>,
// Typically a column-major 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 near ⎥
// ⎣ 0 0 -1 0 ⎦
// ```
//
// Orthographic
// ```
// w = right - left
// h = top - bottom
// d = far - near
// cw = -right - left
// ch = -top - bottom
//
// ⎡ 2 / w 0 0 cw / w ⎤
// ⎢ 0 2 / h 0 ch / h ⎥
// ⎢ 0 0 1 / d far / d ⎥
// ⎣ 0 0 0 1 ⎦
// ```
//
// `clip_from_view[3][3] == 1.0` is the standard way to check if a projection is orthographic
//
// Wgsl matrices are column major, so for example getting the near plane of a perspective projection is `clip_from_view[3][2]`
//
// Custom projections are also possible however.
clip_from_view: mat4x4<f32>,
view_from_clip: mat4x4<f32>,
world_position: vec3<f32>,
exposure: f32,
// viewport(x_origin, y_origin, width, height)
viewport: vec4<f32>,
// 6 world-space half spaces (normal: vec3, distance: f32) ordered left, right, top, bottom, near, far.
// The normal vectors point towards the interior of the frustum.
// A half space contains `p` if `normal.dot(p) + distance > 0.`
frustum: array<vec4<f32>, 6>,
color_grading: ColorGrading,
mip_bias: f32,
frame_count: u32,
};