npm install --save @use-gpu/glsl-loader
yarn add @use-gpu/glsl-loader
Docs: https://usegpu.live/docs/reference-loader-@use-gpu-glsl-loader
This is a JS loader which enables easy use of @use-gpu/shader
.
For webpack, it will emit ESM or CommonJS automatically:
{
// ...
module: {
rules: [
//...
{
test: /\.glsl$/i,
use: ['@use-gpu/glsl-loader'],
},
],
},
}
For rollup, import the plugin as:
import rollupGLSL from "@use-gpu/glsl-loader/rollup";
For esbuild, import the plugin as:
import glslPlugin from "@use-gpu/glsl-loader/esbuild";
You can then do:
import shader from './shader.glsl';
This will import a ParsedBundle
that can be used with @use-gpu/shader
's linkBundle(...)
function.
If you use a named import:
import { symbol } from './shader.glsl';
You will get the same ParsedBundle
, but with entry
set to the imported symbol name.
To allow shader imports to type check, use the shader2ts
script from @use-gpu/shader
to emit .d.ts files, e.g. for src/
:
./node_modules/@use-gpu/shader/bin/shader2ts.js --lang glsl --noEmit --typeDef src
Made by Steven Wittens. Part of @use-gpu
.