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.
1import bevy_render::view::View;
2import package::fullscreen_vertex_shader::FullscreenVertexOutput;
3import bevy_pbr::render::view_transformations::uv_to_ndc;
5struct PreviousViewUniforms {
6 view_from_world: mat4x4<f32>,
7 clip_from_world: mat4x4<f32>,
8 unjittered_clip_from_world: mat4x4<f32>,
9 clip_from_view: mat4x4<f32>,
10 world_from_clip: mat4x4<f32>,
11 view_from_clip: mat4x4<f32>,
14@group(0) @binding(0) var<uniform> view: View;
15@group(0) @binding(1) var<uniform> previous_view: PreviousViewUniforms;
17/// Writes motion vectors for sky pixels (depth == 0 in reversed-Z) based on camera rotation.
18///
19/// The fullscreen vertex outputs z=0.0, which equals the cleared depth at sky pixels in
20/// reversed-Z. The GreaterEqual depth test passes only where depth == 0, so this only writes
21/// to pixels untouched by geometry.
22@fragment
23fn fragment(in: FullscreenVertexOutput) -> @location(1) vec4<f32> {
24 let clip_pos = uv_to_ndc(in.uv);
25 let world_pos = view.world_from_clip * vec4(clip_pos, 0.0, 1.0);
26 // Use the unjittered matrices on both sides to strip TAA jitter from the motion
27 // vector.
28 let curr_clip_pos = (view.unjittered_clip_from_world * world_pos).xy;
29 let prev_clip_pos = (previous_view.unjittered_clip_from_world * world_pos).xy;
30 let velocity = (curr_clip_pos - prev_clip_pos) * vec2(0.5, -0.5);
31 return vec4(velocity.x, velocity.y, 0.0, 1.0);
Contents