62 lines
1.6 KiB
WebGPU Shading Language
62 lines
1.6 KiB
WebGPU Shading Language
|
|
enable draw_index;
|
||
|
|
|
||
|
|
struct VertexInput {
|
||
|
|
@location(0) position: vec2<f32>,
|
||
|
|
@builtin(instance_index) draw_id: u32,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct VertexOutput {
|
||
|
|
@location(0) albedo: vec4<f32>,
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Face {
|
||
|
|
transform: u32,
|
||
|
|
colour: u32,
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(0) @binding(0)
|
||
|
|
var<storage, read> faces: array<Face>;
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn vs_main(
|
||
|
|
input: VertexInput
|
||
|
|
) -> VertexOutput {
|
||
|
|
let face = faces[input.draw_id];
|
||
|
|
let transform = face.transform;
|
||
|
|
let direction = transform & 0x07;
|
||
|
|
let x = f32((transform & 0x00000F8) >> 3);
|
||
|
|
let y = f32((transform & 0x0001F00) >> 8);
|
||
|
|
let z = f32((transform & 0x003E000) >> 13);
|
||
|
|
let w = f32((transform & 0x07C0000) >> 18);
|
||
|
|
let h = f32((transform & 0xF800000) >> 23);
|
||
|
|
|
||
|
|
var result: VertexOutput;
|
||
|
|
result.position = vec4(input.position.x + x, input.position.y + y, z, 1.0);
|
||
|
|
result.position.x += w * f32(input.position.x != 0);
|
||
|
|
result.position.y += h * f32(input.position.y != 0);
|
||
|
|
result.position = vec4(result.position.xy * 0.1, result.position.zw);
|
||
|
|
|
||
|
|
result.albedo = vec4(
|
||
|
|
f32(face.colour & 0x000000FF) / 255,
|
||
|
|
f32((face.colour & 0x0000FF00) >> 8) / 255,
|
||
|
|
f32((face.colour & 0x00FF0000) >> 16) / 255,
|
||
|
|
f32((face.colour & 0xFF000000) >> 24) / 255,
|
||
|
|
);
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
struct FragmentOutput {
|
||
|
|
@location(0) albedo: vec4<f32>,
|
||
|
|
@location(1) chunk_id: u32,
|
||
|
|
}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn fs_main(vertex: VertexOutput) -> FragmentOutput {
|
||
|
|
var output: FragmentOutput;
|
||
|
|
output.albedo = vertex.albedo;
|
||
|
|
output.chunk_id = 0;
|
||
|
|
return output;
|
||
|
|
}
|