struct Globals {
ndc_to_px: vec2<f32>,
_pad: vec2<f32>,
};
@group(0) @binding(0) var<uniform> G: Globals;
struct VSOut {
@builtin(position) pos: vec4<f32>,
@location(0) color: vec4<f32>,
@location(1) uv: vec2<f32>,
};
@vertex
fn vs_main(
@location(0) xywh: vec4<f32>,
@location(1) uv_rect: vec4<f32>,
@location(2) color: vec4<f32>,
@builtin(vertex_index) v: u32
) -> VSOut {
var positions = array<vec2<f32>, 6>(
vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(1.0, 1.0),
vec2(0.0, 0.0), vec2(1.0, 1.0), vec2(0.0, 1.0)
);
var uvs = array<vec2<f32>, 6>(
vec2(0.0, 0.0), vec2(1.0, 0.0), vec2(1.0, 1.0),
vec2(0.0, 0.0), vec2(1.0, 1.0), vec2(0.0, 1.0)
);
let p = positions[v];
let uv_lerp = uvs[v];
let pos_ndc = xywh.xy + p * xywh.zw;
var out: VSOut;
out.pos = vec4(pos_ndc, 0.0, 1.0);
out.uv = mix(uv_rect.xy, uv_rect.zw, uv_lerp);
out.color = color;
return out;
}
@group(1) @binding(0) var glyph_tex: texture_2d<f32>;
@group(1) @binding(1) var glyph_sampler: sampler;
@fragment
fn fs_main(in: VSOut) -> @location(0) vec4<f32> {
let cov = textureSample(glyph_tex, glyph_sampler, in.uv).r;
let a = cov * in.color.a;
return vec4(in.color.rgb * a, a);
}