Add shapes and basic selective actions

This commit is contained in:
2026-04-27 18:26:02 +02:00
parent 21476a3b95
commit 5881a7dafc
12 changed files with 1060 additions and 423 deletions

45
src/shaders/shape.wgsl Normal file
View File

@@ -0,0 +1,45 @@
struct VsUniform {
mvp: mat4x4f,
};
struct ShapeUniform {
transform: mat4x4f,
base_color: vec4f,
state: u32,
};
struct VsIn {
@location(0) position: vec2f,
};
struct Vs2Fs {
@builtin(position) pos: vec4f,
@location(0) @interpolate(linear) color: vec4f,
};
struct FsOut {
@location(0) color: vec4f,
};
@binding(0) @group(0) var<uniform> vs_uniforms: VsUniform;
@binding(1) @group(0) var<uniform> shape_uniform: ShapeUniform;
@vertex fn vs_main(input: VsIn) -> Vs2Fs {
var output: Vs2Fs;
let world_pos = vec4f(input.position.x, input.position.y, 0.0, 1.0) * shape_uniform.transform;
output.pos = world_pos * vs_uniforms.mvp;
if (shape_uniform.state == 2u) {
output.color = vec4f(1.0, 0.84, 0.0, 1.0);
} else if (shape_uniform.state == 1u) {
output.color = clamp(shape_uniform.base_color * 1.5, vec4f(0.0), vec4f(1.0));
} else {
output.color = shape_uniform.base_color;
}
return output;
}
@fragment fn fs_main(input: Vs2Fs) -> FsOut {
var output: FsOut;
output.color = input.color;
return output;
}