parent
4796ff6de5
commit
c7a56745a7
2 changed files with 88 additions and 10 deletions
@ -1,14 +1,44 @@ |
|||||||
|
@group(0) @binding(0) var<uniform> mvp_matrix: mat4x4<f32>; |
||||||
|
|
||||||
|
struct VertexOutput { |
||||||
|
@builtin(position) position: vec4<f32>, |
||||||
|
@location(0) color: vec4<f32>, |
||||||
|
}; |
||||||
|
|
||||||
|
struct FragmentOutput { |
||||||
|
@location(0) pixel_color: vec4<f32> |
||||||
|
}; |
||||||
|
|
||||||
@vertex fn vertex_main( |
@vertex fn vertex_main( |
||||||
@builtin(vertex_index) index: u32 |
@builtin(vertex_index) index: u32 |
||||||
) -> @builtin(position) vec4<f32> { |
) -> VertexOutput { |
||||||
let pos = array<vec2<f32>, 3>( |
let color = array<vec3<f32>, 3>( |
||||||
vec2<f32>( 0.0, 0.5), |
vec3<f32>(1.0, 0.0, 0.0), |
||||||
vec2<f32>(-0.5, -0.5), |
vec3<f32>(0.0, 1.0, 0.0), |
||||||
vec2<f32>( 0.5, -0.5) |
vec3<f32>(0.0, 0.0, 1.0), |
||||||
); |
); |
||||||
return vec4<f32>(pos[index], 0.0, 1.0); |
let pos = array<vec2<f32>, 9>( |
||||||
|
vec2<f32>(-1.0, 0.5 + 0.25), |
||||||
|
vec2<f32>(-1.5, -0.5 + 0.25), |
||||||
|
vec2<f32>(-0.5, -0.5 + 0.25), |
||||||
|
|
||||||
|
vec2<f32>( 0.0, 0.5 - 0.25), |
||||||
|
vec2<f32>(-0.5, -0.5 - 0.25), |
||||||
|
vec2<f32>( 0.5, -0.5 - 0.25), |
||||||
|
|
||||||
|
vec2<f32>( 1.0, 0.5), |
||||||
|
vec2<f32>( 0.5, -0.5), |
||||||
|
vec2<f32>( 1.5, -0.5), |
||||||
|
); |
||||||
|
|
||||||
|
var out: VertexOutput; |
||||||
|
out.position = vec4<f32>(pos[index], 0.0, 1.0) * mvp_matrix; |
||||||
|
out.color = vec4<f32>(color[index / 3], 1.0); |
||||||
|
return out; |
||||||
} |
} |
||||||
|
|
||||||
@fragment fn frag_main() -> @location(0) vec4<f32> { |
@fragment fn frag_main(in: VertexOutput) -> FragmentOutput { |
||||||
return vec4<f32>(1.0, 0.0, 0.0, 1.0); |
var out: FragmentOutput; |
||||||
|
out.pixel_color = in.color; |
||||||
|
return out; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue