WGSL shader compiler and analysis tool
npm install wgsl-wasm-transpiler-bundlerThis is a simple tool to convert WGSL shaders into other formats. You can use it from the command line or in JavaScript (Node.js or browser).
``bash`
cargo run --features cli -- shader.wgsl --format glsl
`bash`
cargo run --features cli -- shader.wgsl --format hlsl --output shader.hlsl
Formats you can use: wgsl, glsl, hlsl, metal, spirv, spirv-asm
Node.js:
`javascript
const { compileShader, init } = require('./pkg-nodejs/wgsl_wasm_transpiler.js');
init();
const wgsl = '@fragment fn main() -> @location(0) vec4
const glsl = compileShader(wgsl, 'glsl');
console.log(glsl);
`
Browser:
`javascript`
import init, { compileShader } from './pkg/wgsl_wasm_transpiler.js';
await init();
const result = compileShader(wgslCode, 'glsl');
For the CLI:
`bash`
cargo build --release --features cli
For WebAssembly:
`bash`
cargo install wasm-pack
./scripts/build-wasm.sh
- WGSL
- GLSL
- HLSL
- Metal
- SPIR-V (binary or assembly)
SPIR-V can be output as:
- spirv: binary file (.spv), or base64 string in JSspirv-asm
- : readable text (.spvasm)
- examples/web-example.html — browser demoexamples/nodejs-example.js
- — Node.js demo
- compileShader(wgsl_code: string, format: string) -> stringgetSupportedFormats() -> string[]
- init()
-
`bash``
cargo test --features cli
cargo test --features wasm
./scripts/test-all.sh
python3 scripts/serve.pyThen open http://localhost:{port}/examples/web-example.html