@pobidowski/esbuild-plugin-glslify-inline
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

esbuild-plugin-glslify-inline

An esbuild plugin to transform inline GLSL strings with glslify.

Install

npm install --save-dev esbuild-plugin-glslify-inline

or

yarn add --dev esbuild-plugin-glslify-inline

Usage

You can use into any esbuild.mjs script like this:

import { build } from 'esbuild'
import { glslifyInline } from 'esbuild-plugin-glslify-inline'

build({
  entryPoints: ['input.js'],
  outfile: 'output.js',
  bundle: true,
  plugins: [glslifyInline()],
}).catch(() => process.exit(1))

You can also minify the imported shaders with glslifyInline({ minify: true }).

After that, you can use glslify normally with esbuild:

import glsl from 'glslify'

// ...

const material = new THREE.MeshStandardMaterial()

customizeVertexShader(material, {
  head: glsl`
    uniform float time;
    uniform float speed;

    // you can import glsl packages like this
    #pragma glslify: noise = require(glsl-noise/simplex/3d)
  `,
  main: glsl`
    // and use them in other parts of the shader
    vec3 displacement = normal * noise(vec3(uv, time * speed));
  `,
  // hook that lets you modify the position
  transformed: glsl`
    transformed += displacement;
  `,
})

Package Sidebar

Install

npm i @pobidowski/esbuild-plugin-glslify-inline

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

6.08 kB

Total Files

6

Last publish

Collaborators

  • pobidowski