Compute vertex position in shader
This commit is contained in:
parent
bc9bb28b1c
commit
3f467d1212
6 changed files with 60 additions and 128 deletions
|
|
@ -37,3 +37,11 @@ fn select_border_radius(radi: vec4<f32>, position: vec2<f32>, center: vec2<f32>)
|
|||
rx = select(rx, ry, position.y > center.y);
|
||||
return rx;
|
||||
}
|
||||
|
||||
// Compute the normalized quad coordinates based on the vertex index.
|
||||
fn vertex_position(vertex_index: u32) -> vec2<f32> {
|
||||
// #: 0 1 2 3 4 5
|
||||
// x: 1 1 0 0 0 1
|
||||
// y: 1 0 0 0 1 1
|
||||
return vec2<f32>((vec2(1u, 2u) + vertex_index) % 6u < 3u);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
struct GradientVertexInput {
|
||||
@location(0) v_pos: vec2<f32>,
|
||||
@builtin(vertex_index) vertex_index: u32,
|
||||
@location(1) @interpolate(flat) colors_1: vec4<u32>,
|
||||
@location(2) @interpolate(flat) colors_2: vec4<u32>,
|
||||
@location(3) @interpolate(flat) colors_3: vec4<u32>,
|
||||
|
|
@ -48,7 +48,7 @@ fn gradient_vs_main(input: GradientVertexInput) -> GradientVertexOutput {
|
|||
vec4<f32>(pos - vec2<f32>(0.5, 0.5), 0.0, 1.0)
|
||||
);
|
||||
|
||||
out.position = globals.transform * transform * vec4<f32>(input.v_pos, 0.0, 1.0);
|
||||
out.position = globals.transform * transform * vec4<f32>(vertex_position(input.vertex_index), 0.0, 1.0);
|
||||
out.colors_1 = input.colors_1;
|
||||
out.colors_2 = input.colors_2;
|
||||
out.colors_3 = input.colors_3;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
struct SolidVertexInput {
|
||||
@location(0) v_pos: vec2<f32>,
|
||||
@builtin(vertex_index) vertex_index: u32,
|
||||
@location(1) color: vec4<f32>,
|
||||
@location(2) pos: vec2<f32>,
|
||||
@location(3) scale: vec2<f32>,
|
||||
|
|
@ -40,7 +40,7 @@ fn solid_vs_main(input: SolidVertexInput) -> SolidVertexOutput {
|
|||
vec4<f32>(pos - vec2<f32>(0.5, 0.5), 0.0, 1.0)
|
||||
);
|
||||
|
||||
out.position = globals.transform * transform * vec4<f32>(input.v_pos, 0.0, 1.0);
|
||||
out.position = globals.transform * transform * vec4<f32>(vertex_position(input.vertex_index), 0.0, 1.0);
|
||||
out.color = input.color;
|
||||
out.border_color = input.border_color;
|
||||
out.pos = pos;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue