0.0.10 • Published 4 months ago
madrid v0.0.10
Madrid
Minimal WebGPU Framework
Installation
yarn add madrid
Usage
struct Uniforms { mvp: mat4x4f }
struct VertexOutput { @builtin(position) position: vec4f }
@binding(0) @group(0) var<uniform> uniforms: Uniforms;
@vertex fn main( @location(0) position: vec4f ) -> VertexOutput {
return VertexOutput(uniforms.mvp * position);
}
@fragment fn main() -> @location(0) vec4f {
return vec4f(0, 0, 0, 0.4);
}
import { Camera, Mesh, Scene, Pipeline, Setup, Render, Plane } from 'madrid'
import vs from './vs.wgsl'
import fs from './fs.wgsl'
onload = async () => {
const gpu = new Setup()
await gpu.create()
const camera = new Camera()
const geometry = new Plane()
const mesh = new Mesh({ gpu, geometry })
const scene = new Scene({ gpu, camera, mesh })
const pipeline = new Pipeline({ gpu, vs, fs, scene })
const render = new Render({ gpu, pipeline, scene })
render.raf(() => {
mesh.rotation.x += 0.01
scene.update()
})
}