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