Skip to content
/ lilgpu Public

Lil wrapper to toy with WebGPU, powered by TypeGPU

Notifications You must be signed in to change notification settings

gnlow/lilgpu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lilgpu

Lil wrapper to toy with WebGPU

Usage

See examples.

Browser

import { initCanvas, d } from "https://esm.sh/gh/gnlow/lilgpu/browser.ts"

const g = await initCanvas({
    vertShader: `
        @vertex
        fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
            let x = f32(i32(in_vertex_index) - 1);
            let y = f32(i32(in_vertex_index & 1u) * 2 - 1);
            return vec4<f32>(x, y, 0.0, 1.0);
        }
    `,
    fragShader: `
        @fragment
        fn fs_main() -> @location(0) vec4<f32> {
            return vec4<f32>(1.0, 0.0, 0.0, 1.0);
        }
    `,
    canvas: document.querySelector("canvas"),
})

g.draw(3)

Deno

import { initDeno } from "https://esm.sh/gh/gnlow/lilgpu/deno.ts"

const g = await initDeno({
    vertShader: `
        @vertex
        fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
            let x = f32(i32(in_vertex_index) - 1);
            let y = f32(i32(in_vertex_index & 1u) * 2 - 1);
            return vec4<f32>(x, y, 0.0, 1.0);
        }
    `,
    fragShader: `
        @fragment
        fn fs_main() -> @location(0) vec4<f32> {
            return vec4<f32>(1.0, 0.0, 0.0, 1.0);
        }
    `,
    width: 200,
    height: 200,
})

g.draw(3)

await Deno.writeFile("./triangle.png", await g.getImage())

Jupyter

await g.getImage() // Uint8Array

About

Lil wrapper to toy with WebGPU, powered by TypeGPU

Resources

Stars

Watchers

Forks

Packages

No packages published