shaderexp: push vertex data into shader

This commit is contained in:
praschke 2022-08-22 13:11:21 +00:00 committed by Stephen Gutekanst
parent 4199d2a001
commit c57f0575ea
2 changed files with 24 additions and 56 deletions

View file

@ -3,12 +3,27 @@ struct VertexOut {
@location(0) frag_uv : vec2<f32>,
}
@vertex fn main(
@location(0) position : vec4<f32>,
@location(1) uv : vec2<f32>
) -> VertexOut {
@vertex fn main(@builtin(vertex_index) index : u32) -> VertexOut {
var pos = array<vec2<f32>, 6>(
vec2<f32>(-1.0, -1.0),
vec2<f32>( 1.0, -1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>(-1.0, 1.0),
vec2<f32>(-1.0, -1.0)
);
var uv = array<vec2<f32>, 6>(
vec2<f32>(0.0, 0.0),
vec2<f32>(1.0, 0.0),
vec2<f32>(1.0, 1.0),
vec2<f32>(1.0, 1.0),
vec2<f32>(0.0, 1.0),
vec2<f32>(0.0, 0.0)
);
var output : VertexOut;
output.position_clip = position;
output.frag_uv = uv;
output.position_clip = vec4<f32>(pos[index], 0.0, 1.0);
output.frag_uv = uv[index];
return output;
}