Testing WSGL directly

This commit is contained in:
Clément Pons
2025-05-07 17:32:36 +02:00
parent 0059d8fc3b
commit b02b2b02d5
9 changed files with 4236 additions and 33 deletions

47
src/shaders/sprite.wgsl Normal file
View File

@@ -0,0 +1,47 @@
struct Cell {
position: vec2f,
};
struct VsI { //Vertex shader input
@builtin(instance_index) instance: u32,
@location(0) position: vec2f,
};
struct Vs2Fs { //Vertex shader to Fragment shader
@builtin(position) pos: vec4f,
@location(0) @interpolate(flat) instance: u32,
};
struct FsO { //Fragment shader output
@builtin(frag_depth) depth: f32,
@location(0) color: vec4f,
};
fn color(i: u32) -> vec3f
{
let r: f32 = f32(((i >> 0) & 0xff));
let g: f32 = f32(((i >> 8) & 0xff));
let b: f32 = f32(((i >> 16) & 0xff));
return vec3f(r / 255, g / 255, b / 255);
}
//@binding(0) @group(0) var<uniform> mvp: mat4x4f;
@binding(0) @group(1) var<storage> cells: array<Cell>;
@vertex
fn vs_main(input: VsI) -> Vs2Fs {
var output: Vs2Fs;
output.pos = vec4f(cells[input.instance].position.xy, 0.0, 0.0)/* * mvp*/;
output.instance = input.instance;
return output;
}
@fragment
fn fs_main(input: Vs2Fs) -> FsO {
var output: FsO;
output.depth = 1.0;
output.color = vec4f(1.0, 0.0, 1.0, 1.0);
//output.color = vec4f(color(input.instance), 1.0);
return output;
}