-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathfullscreen_vertex.rs
More file actions
29 lines (27 loc) · 878 Bytes
/
Copy pathfullscreen_vertex.rs
File metadata and controls
29 lines (27 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use glam::{Vec2, Vec4};
use spirv_std::spirv;
/// webgpu NDC is like OpenGL: (-1.0 .. 1.0, -1.0 .. 1.0, 0.0 .. 1.0)
/// https://www.w3.org/TR/webgpu/#coordinate-systems
///
/// So to make a fullscreen triangle around a box at (-1..1):
///
/// ```norun
/// 3 +
/// |\
/// 2 | \
/// | \
/// 1 +-----+
/// | |\
/// 0 | 0 | \
/// | | \
/// -1 +-----+-----+
/// -1 0 1 2 3
/// ```
const FULLSCREEN_VERTICES: [Vec2; 3] = [Vec2::new(-1., -1.), Vec2::new(-1., 3.), Vec2::new(3., -1.)];
#[spirv(vertex)]
pub fn fullscreen_vertex(#[spirv(vertex_index)] vertex_index: u32, #[spirv(position)] gl_position: &mut Vec4) {
// broken on edition 2024 branch
// let vertex = unsafe { *FULLSCREEN_VERTICES.index_unchecked(vertex_index as usize) };
let vertex = FULLSCREEN_VERTICES[vertex_index as usize];
*gl_position = Vec4::from((vertex, 0., 1.));
}