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//! Draws a progress bar with properties defined in CustomUiMaterial
2import bevy_ui_render::ui_vertex_output::UiVertexOutput;
4@group(1) @binding(0) var<uniform> color: vec4<f32>;
5@group(1) @binding(1) var<uniform> slider: vec4<f32>;
6@group(1) @binding(2) var material_color_texture: texture_2d<f32>;
7@group(1) @binding(3) var material_color_sampler: sampler;
8@group(1) @binding(4) var<uniform> border_color: vec4<f32>;
11@fragment
12fn fragment(in: UiVertexOutput) -> @location(0) vec4<f32> {
13 let output_color = textureSample(material_color_texture, material_color_sampler, in.uv) * color;
15 // half size of the UI node
16 let half_size = 0.5 * in.size;
18 // position relative to the center of the UI node
19 let p = in.uv * in.size - half_size;
21 // thickness of the border closest to the current position
22 let b = vec2(
23 select(in.border_widths.x, in.border_widths.z, 0. < p.x),
24 select(in.border_widths.y, in.border_widths.w, 0. < p.y)
25 );
27 // select radius for the nearest corner
28 let rs = select(in.border_radius_x.xy, in.border_radius_x.wz, 0.0 < p.y);
29 let radius = select(rs.x, rs.y, 0.0 < p.x);
31 // distance along each axis from the corner
32 let d = half_size - abs(p);
34 // if the distance to the edge from the current position on any axis
35 // is less than the border width on that axis then the position is within
36 // the border and we return the border color
37 if d.x < b.x || d.y < b.y {
38 // select radius for the nearest corner
39 let rs = select(in.border_radius_x.xy, in.border_radius_x.wz, 0.0 < p.y);
40 let radius = select(rs.x, rs.y, 0.0 < p.x);
42 // determine if the point is inside the curved corner and return the corresponding color
43 let q = radius - d;
44 if radius < min(max(q.x, q.y), 0.0) + length(vec2(max(q.x, 0.0), max(q.y, 0.0))) {
45 return vec4(0.0);
46 } else {
47 return border_color;
48 }
49 }
51 // sample the texture at this position if it's to the left of the slider value
52 // otherwise return a fully transparent color
53 if in.uv.x < slider.x {
54 let output_color = textureSample(material_color_texture, material_color_sampler, in.uv) * color;
55 return output_color;
56 } else {
57 return vec4(0.0);
58 }
Contents