Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#define_import_path bevy_core_pipeline::fullscreen_vertex_shader
3struct FullscreenVertexOutput {
4 @builtin(position)
5 position: vec4<f32>,
6 @location(0)
7 uv: vec2<f32>,
8};
10// This vertex shader produces the following, when drawn using indices 0..3:
11//
12// 1 | 0-----x.....2
13// 0 | | s | . ´
14// -1 | x_____x´
15// -2 | : .´
16// -3 | 1´
17// +---------------
18// -1 0 1 2 3
19//
20// The axes are clip-space x and y. The region marked s is the visible region.
21// The digits in the corners of the right-angled triangle are the vertex
22// indices.
23//
24// The top-left has UV 0,0, the bottom-left has 0,2, and the top-right has 2,0.
25// This means that the UV gets interpolated to 1,1 at the bottom-right corner
26// of the clip-space rectangle that is at 1,-1 in clip space.
27@vertex
28fn fullscreen_vertex_shader(@builtin(vertex_index) vertex_index: u32) -> FullscreenVertexOutput {
29 // See the explanation above for how this works
30 let uv = vec2<f32>(f32(vertex_index >> 1u), f32(vertex_index & 1u)) * 2.0;
31 let clip_position = vec4<f32>(uv * vec2<f32>(2.0, -2.0) + vec2<f32>(-1.0, 1.0), 0.0, 1.0);
33 return FullscreenVertexOutput(clip_position, uv);
Contents