text rendering

This commit is contained in:
Jonas H
2026-03-28 13:23:27 +01:00
parent dcd40ae443
commit e558b682e2
8 changed files with 696 additions and 45 deletions

45
src/shaders/text.wgsl Normal file
View File

@@ -0,0 +1,45 @@
struct Uniforms
{
view_proj: mat4x4<f32>,
}
@group(0) @binding(0)
var<uniform> u: Uniforms;
@group(0) @binding(1)
var glyph_atlas: texture_2d<f32>;
@group(0) @binding(2)
var glyph_sampler: sampler;
struct VertexIn
{
@location(0) position: vec3<f32>,
@location(1) uv: vec2<f32>,
}
struct VertexOut
{
@builtin(position) clip_pos: vec4<f32>,
@location(0) uv: vec2<f32>,
}
@vertex
fn vs_main(in: VertexIn) -> VertexOut
{
var out: VertexOut;
out.clip_pos = u.view_proj * vec4<f32>(in.position, 1.0);
out.uv = in.uv;
return out;
}
@fragment
fn fs_main(in: VertexOut) -> @location(0) vec4<f32>
{
let coverage = textureSample(glyph_atlas, glyph_sampler, in.uv).r;
if coverage < 0.5
{
discard;
}
return vec4<f32>(1.0, 1.0, 1.0, 1.0);
}