Fix issues

This commit is contained in:
Andras Schmelczer 2023-04-16 14:05:47 +01:00
commit 5feb7c929d
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
12 changed files with 190 additions and 113 deletions

View file

@ -0,0 +1,52 @@
import shader from './full-screen-quad.wgsl';
export const setUpFullScreenQuad = (
device: GPUDevice
): {
buffer: GPUBuffer;
vertex: GPUVertexState;
} => {
const buffer = device.createBuffer({
size: 4 * 4 * 4, // 4x vec4<f32>
usage: GPUBufferUsage.VERTEX,
mappedAtCreation: true,
});
// prettier-ignore
const vertexData = [
// posX posY U V
-1.0, -1.0, 0.0, 1.0,
+1.0, -1.0, 1.0, 1.0,
-1.0, +1.0, 0.0, 0.0,
+1.0, +1.0, 1.0, 0.0,
];
new Float32Array(buffer.getMappedRange()).set(vertexData);
buffer.unmap();
return {
buffer,
vertex: {
module: device.createShaderModule({
code: shader,
}),
entryPoint: 'vertex',
buffers: [
{
arrayStride: 4 * 4,
stepMode: 'vertex',
attributes: [
{
shaderLocation: 0,
offset: 0,
format: 'float32x2',
},
{
shaderLocation: 1,
offset: 8,
format: 'float32x2',
},
],
},
],
},
};
};

View file

@ -0,0 +1,12 @@
struct VertexOutput {
@builtin(position) position : vec4<f32>,
@location(0) uv : vec2<f32>,
}
@vertex
fn vertex(
@location(0) position : vec2<f32>,
@location(1) uv : vec2<f32>
) -> VertexOutput {
return VertexOutput(vec4(position, 0.0, 1.0), uv);
}