Compute vertex position for image shader

This commit is contained in:
Jim Eckerlein 2023-09-24 15:24:08 +02:00
parent e197abe0aa
commit 5fb877ab59
2 changed files with 23 additions and 80 deletions

View file

@ -7,7 +7,7 @@ struct Globals {
@group(1) @binding(0) var u_texture: texture_2d_array<f32>;
struct VertexInput {
@location(0) v_pos: vec2<f32>,
@builtin(vertex_index) vertex_index: u32,
@location(1) pos: vec2<f32>,
@location(2) scale: vec2<f32>,
@location(3) atlas_pos: vec2<f32>,
@ -25,7 +25,9 @@ struct VertexOutput {
fn vs_main(input: VertexInput) -> VertexOutput {
var out: VertexOutput;
out.uv = vec2<f32>(input.v_pos * input.atlas_scale + input.atlas_pos);
let v_pos = vertex_position(input.vertex_index);
out.uv = vec2<f32>(v_pos * input.atlas_scale + input.atlas_pos);
out.layer = f32(input.layer);
var transform: mat4x4<f32> = mat4x4<f32>(
@ -35,7 +37,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
vec4<f32>(input.pos, 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>(v_pos, 0.0, 1.0);
return out;
}