From 2b718c6de12226c2664e72010ed364795d8efac6 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 21 May 2022 11:05:16 -0700 Subject: [PATCH] examples/gkurve: explain frag_bary coordinates intent Signed-off-by: Stephen Gutekanst --- examples/gkurve/vert.wgsl | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/gkurve/vert.wgsl b/examples/gkurve/vert.wgsl index 87439458..18d9fe0e 100644 --- a/examples/gkurve/vert.wgsl +++ b/examples/gkurve/vert.wgsl @@ -6,7 +6,7 @@ struct VertexUniform { struct VertexOut { @builtin(position) position_clip: vec4, @location(0) frag_uv: vec2, - @interpolate(linear) @location(1) frag_bary: vec3, + @interpolate(linear) @location(1) frag_bary: vec2, @interpolate(flat) @location(2) triangle_index: u32, } @@ -18,10 +18,22 @@ struct VertexOut { var output : VertexOut; output.position_clip = ubo.matrix * position; output.frag_uv = uv; - output.frag_bary = vec3( + + // Generates [0, 0], [0.5, 0.0], [1.0, 1.0] + // + // Equal to: + // + // if ((vertex_index+1u) % 3u == 0u) { + // output.frag_bary = vec2(0.0, 0.0); + // } else if ((vertex_index+1u) % 3u == 1u) { + // output.frag_bary = vec2(0.5, 0.0); + // } else { + // output.frag_bary = vec2(1.0, 1.0); + // } + // + output.frag_bary = vec2( f32(((vertex_index+2u) % 3u * 2u) % 3u), f32(((vertex_index+2u) % 3u * 2u) & 2u) * 2.0, - 0.0, ); output.triangle_index = vertex_index / 3u; return output;