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_sprite::mesh2d_vertex_output::VertexOutput
3@group(#{MATERIAL_BIND_GROUP}) @binding(0) var<uniform> frame: vec4<f32>;
4// current/previous ring origin X, stable anchor X, and view width.
5@group(#{MATERIAL_BIND_GROUP}) @binding(1) var<uniform> anchor: vec4<f32>;
7@fragment
8fn fragment(_in: VertexOutput) -> @location(0) vec4<f32> {
9 // The physical point is anchored in world space. Camera-follow ring origin
10 // changes in anchor.xy are deliberately absent from both positions.
11 let current_world_x = anchor.z + frame.z;
12 let previous_world_x = anchor.z + frame.w;
13 let current_ndc_x = 2.0 * (current_world_x - frame.x) / anchor.w;
14 let previous_ndc_x = 2.0 * (previous_world_x - frame.y) / anchor.w;
15 let current_ndc = vec2<f32>(current_ndc_x, 0.0);
16 let previous_ndc = vec2<f32>(previous_ndc_x, 0.0);
18 // Terra and Bevy use current minus previous NDC, transformed to UV space.
19 let raw_motion = (current_ndc - previous_ndc) * vec2<f32>(0.5, -0.5);
20 let motion = select(raw_motion, vec2(0.0), raw_motion == vec2(0.0));
21 return vec4<f32>(motion, 0.0, 1.0);
Contents