wgpu/tests/in/quad.wgsl

39 lines
997 B
WebGPU Shading Language
Raw Normal View History

// vertex
2021-04-11 04:35:03 +00:00
let c_scale: f32 = 1.2;
struct VertexOutput {
@location(0) uv : vec2<f32>,
@builtin(position) position : vec4<f32>,
}
2020-12-08 05:23:29 +00:00
@vertex
fn vert_main(
2022-01-19 15:33:06 +00:00
@location(0) pos : vec2<f32>,
@location(1) uv : vec2<f32>,
) -> VertexOutput {
return VertexOutput(uv, vec4<f32>(c_scale * pos, 0.0, 1.0));
2020-12-08 05:23:29 +00:00
}
// fragment
2022-01-19 15:33:06 +00:00
@group(0) @binding(0) var u_texture : texture_2d<f32>;
@group(0) @binding(1) var u_sampler : sampler;
2020-12-08 05:23:29 +00:00
@fragment
2022-01-19 15:33:06 +00:00
fn frag_main(@location(0) uv : vec2<f32>) -> @location(0) vec4<f32> {
2021-04-11 04:35:03 +00:00
let color = textureSample(u_texture, u_sampler, uv);
if color.a == 0.0 {
discard;
}
2021-03-15 05:24:40 +00:00
// forcing the expression here to be emitted in order to check the
// uniformity of the control flow a bit more strongly.
2021-04-11 04:35:03 +00:00
let premultiplied = color.a * color;
return premultiplied;
2020-12-08 05:23:29 +00:00
}
// We need to make sure that backends are successfully handling multiple entry points for the same shader stage.
@fragment
2022-01-19 15:33:06 +00:00
fn fs_extra() -> @location(0) vec4<f32> {
return vec4<f32>(0.0, 0.5, 0.0, 0.5);
}