webgpu-app/font.wgsl

53 lines
1.0 KiB
WebGPU Shading Language

struct Configuration {
viewProj: mat4x4f,
lightViewProj: mat4x4f,
lightPosition: vec4f,
eyePosition: vec4f,
aspect: f32,
};
struct GlyphBitmap {
position: vec2f,
velocity: vec2f,
};
@group(0) @binding(0) var<uniform> config: Configuration;
@group(1) @binding(0) var<storage> glyphs: array<GlyphBitmap>;
struct VertexInput {
@builtin(vertex_index) vertex_index: u32,
};
struct VertexOutput {
@builtin(position) position: vec4f,
@location(0) texture: vec2f,
};
const vertices = array(
vec2f(1.0, 0.0),
vec2f(0.0, 1.0),
vec2f(0.0, 0.0),
vec2f(1.0, 1.0),
);
@vertex
fn vertexMain(input: VertexInput) -> VertexOutput
{
let texture = vertices[input.vertex_index];
let position = texture * 2.0 - 1.0;
var output: VertexOutput;
output.position = vec4f(position, 0.0, 1.0);
output.texture = position * vec2f(config.aspect, 1);
return output;
}
@fragment
fn fragmentMain(input: VertexOutput) -> @location(0) vec4f
{
var color = vec3f(input.texture.xy, 0);
return vec4f(color, 1);
}