2023-10-21 11:51:58 +00:00
|
|
|
#import bevy_render::view::View
|
2023-02-11 17:55:18 +00:00
|
|
|
|
2023-06-21 23:50:29 +00:00
|
|
|
const TEXTURED_QUAD: u32 = 0u;
|
|
|
|
|
2023-09-19 22:17:44 +00:00
|
|
|
@group(0) @binding(0) var<uniform> view: View;
|
2021-12-10 22:21:23 +00:00
|
|
|
|
|
|
|
struct VertexOutput {
|
2022-07-14 21:17:16 +00:00
|
|
|
@location(0) uv: vec2<f32>,
|
|
|
|
@location(1) color: vec4<f32>,
|
2023-06-25 20:50:47 +00:00
|
|
|
@location(3) @interpolate(flat) mode: u32,
|
2022-07-14 21:17:16 +00:00
|
|
|
@builtin(position) position: vec4<f32>,
|
2021-12-10 22:21:23 +00:00
|
|
|
};
|
|
|
|
|
2022-07-14 21:17:16 +00:00
|
|
|
@vertex
|
2021-12-10 22:21:23 +00:00
|
|
|
fn vertex(
|
2022-07-14 21:17:16 +00:00
|
|
|
@location(0) vertex_position: vec3<f32>,
|
|
|
|
@location(1) vertex_uv: vec2<f32>,
|
|
|
|
@location(2) vertex_color: vec4<f32>,
|
2023-06-21 23:50:29 +00:00
|
|
|
@location(3) mode: u32,
|
2021-12-10 22:21:23 +00:00
|
|
|
) -> VertexOutput {
|
|
|
|
var out: VertexOutput;
|
|
|
|
out.uv = vertex_uv;
|
|
|
|
out.position = view.view_proj * vec4<f32>(vertex_position, 1.0);
|
2022-04-25 13:54:50 +00:00
|
|
|
out.color = vertex_color;
|
2023-06-21 23:50:29 +00:00
|
|
|
out.mode = mode;
|
2021-12-10 22:21:23 +00:00
|
|
|
return out;
|
2022-08-05 02:28:06 +00:00
|
|
|
}
|
2021-12-10 22:21:23 +00:00
|
|
|
|
2023-09-19 22:17:44 +00:00
|
|
|
@group(1) @binding(0) var sprite_texture: texture_2d<f32>;
|
|
|
|
@group(1) @binding(1) var sprite_sampler: sampler;
|
2021-12-10 22:21:23 +00:00
|
|
|
|
2022-07-14 21:17:16 +00:00
|
|
|
@fragment
|
|
|
|
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
|
2023-06-21 23:50:29 +00:00
|
|
|
// textureSample can only be called in unform control flow, not inside an if branch.
|
2022-08-05 02:28:06 +00:00
|
|
|
var color = textureSample(sprite_texture, sprite_sampler, in.uv);
|
2023-06-21 23:50:29 +00:00
|
|
|
if in.mode == TEXTURED_QUAD {
|
|
|
|
color = in.color * color;
|
|
|
|
} else {
|
2023-06-25 20:50:47 +00:00
|
|
|
color = in.color;
|
2023-06-21 23:50:29 +00:00
|
|
|
}
|
2021-12-10 22:21:23 +00:00
|
|
|
return color;
|
2022-08-05 02:28:06 +00:00
|
|
|
}
|