diff options
| author | Dominik Kaiser | 2026-11-27 19:16:18 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2026-11-27 19:16:18 +0100 |
| commit | 0a2da9194c08cdb49a233c4d951b34d9949e00e6 (patch) | |
| tree | f0e81253aec8a8e8b57346ce3315911ef1954ebe /games/00_triangle/src/shader.wgsl | |
| parent | 5a07760ea84580106e96ed2b4f9eb896486da7c1 (diff) | |
| download | 20-games-challenge-0a2da9194c08cdb49a233c4d951b34d9949e00e6.tar.gz 20-games-challenge-0a2da9194c08cdb49a233c4d951b34d9949e00e6.zip | |
The vertex buffer
Theoretically I could stop here for now, but because of best practices
and forward compatibility I'll also finish the index buffer
implementation before moving on to Pong
Diffstat (limited to 'games/00_triangle/src/shader.wgsl')
| -rw-r--r-- | games/00_triangle/src/shader.wgsl | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/games/00_triangle/src/shader.wgsl b/games/00_triangle/src/shader.wgsl index 9ff0e3f..a341d15 100644 --- a/games/00_triangle/src/shader.wgsl +++ b/games/00_triangle/src/shader.wgsl @@ -1,19 +1,22 @@ // Vertex shader +struct VertexInput { + @location(0) position : vec3<f32>, @location(1) color : vec3<f32>, +}; + struct VertexOutput { - @builtin(position) clip_position : vec4<f32>, + @builtin(position) clip_position : vec4<f32>, @location(0) color : vec3<f32>, }; -@vertex fn vs_main(@builtin(vertex_index) in_vertex_index : u32, ) +@vertex fn vs_main(model: VertexInput,) -> VertexOutput { var out : VertexOutput; - let x = f32(1 - i32(in_vertex_index)) * 0.5; - let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5; - out.clip_position = vec4<f32>(x, y, 0.0, 1.0); + out.color = model.color; + out.clip_position = vec4<f32>(model.position, 1.0); return out; } // Fragment shader @fragment fn fs_main(in : VertexOutput) -> @location(0) vec4<f32> { - return vec4<f32>(0.3, 0.2, 0.1, 1.0); + return vec4<f32>(in.color, 1.0); } |
