From f6d058be6639c8e052c5a38dea4f33d6b26ae20c Mon Sep 17 00:00:00 2001 From: Tengu712 Date: Sat, 26 Sep 2026 21:36:43 +0900 Subject: add texture --- src/shader.wgsl | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/shader.wgsl') diff --git a/src/shader.wgsl b/src/shader.wgsl index 9f158f1..c154cc4 100644 --- a/src/shader.wgsl +++ b/src/shader.wgsl @@ -1,10 +1,23 @@ +@group(0) @binding(0) var tex_sampler: sampler; +@group(0) @binding(1) var font_tex: texture_2d; + +struct VertexOutput { + @builtin(position) position: vec4, + @location(0) uv: vec2, +} + @vertex -fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4 { +fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> VertexOutput { let uv = vec2(f32((in_vertex_index << 1) & 2), f32(in_vertex_index & 2)) / 2.0; - return vec4(uv.x - 0.5, uv.y - 0.5, 0.0, 1.0); + + var out: VertexOutput; + out.position = vec4(uv.x - 0.5, uv.y - 0.5, 0.0, 1.0); + out.uv = uv; + + return out; } @fragment -fn fs_main() -> @location(0) vec4 { - return vec4(1.0, 1.0, 1.0, 1.0); +fn fs_main(in: VertexOutput) -> @location(0) vec4 { + return vec4(1.0, 1.0, 1.0, textureSample(font_tex, tex_sampler, in.uv).r); } -- cgit v1.3.1