Installation
Install wtc-gl from npm, and set up your bundler to import GLSL files as strings.
Install the package
npm install wtc-glpnpm add wtc-glyarn add wtc-glEverything is a named export from wtc-gl, including the vectors and matrices from wtc-math, which it depends on:
import { Renderer, Mesh, Program, Vec3, Mat4 } from 'wtc-gl'wtc-gl ships ES modules and a CommonJS build, with TypeScript types.
Browser support
wtc-gl needs WebGL2, which every current browser supports. Version 1 also ran on WebGL1; if you're upgrading, the changelog lists what changed and how to migrate.
Shaders as files
Shaders are strings, so they can live inline in your JavaScript. For anything longer, keep them in .vert, .frag and .glsl files and have your bundler import them as strings. With Vite, add vite-plugin-glsl:
import { defineConfig } from 'vite'
import glsl from 'vite-plugin-glsl'
export default defineConfig({
plugins: [glsl()]
})import vertex from './shaders/scene.vert'
import fragment from './shaders/scene.frag'For TypeScript, declare the modules once:
declare module '*.vert' {
const source: string
export default source
}
declare module '*.frag' {
const source: string
export default source
}
declare module '*.glsl' {
const source: string
export default source
}React
The React package wraps ScrollRenderer in a provider and hooks. It needs React 18 or later, and wtc-gl alongside it:
npm install @wethegit/react-wtc-gl wtc-glOptional extras
Some features use packages you install only if you need them:
- CSG works with manifold-3d. wtc-gl doesn't depend on it; you load it and pass it in.