Files
snow_trail/src/shaders/text.wgsl
2026-03-29 10:47:10 +02:00

46 lines
829 B
WebGPU Shading Language

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.004
{
discard;
}
return vec4<f32>(1.0, 1.0, 1.0, coverage);
}