getting closer to a cube

This commit is contained in:
2023-09-27 22:29:29 +02:00
parent 62bbf97c6a
commit 7f959e05cd
6 changed files with 218 additions and 72 deletions

27
shaders/cube.wgsl Normal file
View File

@@ -0,0 +1,27 @@
struct VertexOutput {
@location(0) color: vec3<f32>,
@builtin(position) position: vec4<f32>
};
struct Locals {
transform: mat4x4<f32>
};
@group(0) @binding(0)
var r_locals: Locals;
@vertex
fn vs_main(
@location(0) position: vec4<f32>,
@location(1) color: vec3<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.color = color;
out.position = r_locals.transform * position;
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.color.r, in.color.g, in.color.b, 1.0);
}

View File

@@ -1,11 +0,0 @@
@vertex
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
let x = f32(i32(in_vertex_index) - 1);
let y = f32(i32(in_vertex_index & 1u) * 2 - 1);
return vec4<f32>(x, y, 0.0, 1.0);
}
@fragment
fn fs_main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}