From 031164d9b5db45656222268497cf4f8b3f8b6dc4 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Wed, 22 May 2024 08:22:20 -0700 Subject: [PATCH] gfx: Text: add ability to change font color Signed-off-by: Stephen Gutekanst --- src/gfx/Text.zig | 2 +- src/gfx/text.wgsl | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/gfx/Text.zig b/src/gfx/Text.zig index b4db3ffd..8e3d901e 100644 --- a/src/gfx/Text.zig +++ b/src/gfx/Text.zig @@ -274,7 +274,7 @@ fn updatePipeline( .size = size.divScalar(px_density), .text_index = num_texts, .uv_pos = vec2(@floatFromInt(r.x), @floatFromInt(r.y)), - .font_color = font_color, + .color = font_color, }); origin_x += glyph.advance.x(); } diff --git a/src/gfx/text.wgsl b/src/gfx/text.wgsl index ec5fe35c..2942c34a 100644 --- a/src/gfx/text.wgsl +++ b/src/gfx/text.wgsl @@ -5,7 +5,7 @@ struct VertexOutput { // Vertex position @builtin(position) Position : vec4, - // UV coordinate + // UV coordinate into the glyph atlas @location(0) fragUV : vec2, // Color of the glyph @@ -90,6 +90,7 @@ fn vertMain( var output : VertexOutput; output.Position = pos; output.fragUV = uv; + output.color = glyph.color; return output; } @@ -101,12 +102,12 @@ fn vertMain( @fragment fn fragMain( - @location(0) fragUV: vec2 + @location(0) fragUV: vec2, @location(1) color: vec4 ) -> @location(0) vec4 { var c = textureSample(glyphTexture, glyphSampler, fragUV); if (c.a <= 0.0) { discard; } - return c * color; -} \ No newline at end of file + return vec4(color.rgb * c.a, color.a); +}