npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@threeify/shader-transpiler

v2.0.7

Published

A glsl to JS module transpiler.

Downloads

8

Readme

@threeify/shader-transpiler is glsl to JS module transpiler. It is part of the threeify ecosystem.

The purpose of this is to allow one to use raw glsl files in JavaScript in the most easy fashion possible. Keeping glsl files as *.glsl files has the benefits that syntax highlighers work out of the box as do linters. This allows one to maximize their productivity.

Usage

Usage: tst [options]

Options:
  -V, --version               output the version number
  -p, --projectDir <dirpath>  the root of the project directory tree
  -r, --rootDir <dirpath>     the root of the source directory tree
  -o, --outDir <dirpath>      the root of the output directory tree
  -w, --watch                 watch and incremental transpile any changed files
  -j, --allowJSIncludes       allow referencing javascript and typescript code via includes
  -m, --minify                reduce the size of the glsl code
  -e, --extensions <items>    comma separated list of extensions to transpile
  -v, --verboseLevel <level>  higher numbers means more output
  -h, --help                  display help for command

You can also use a threeify.json configuration file in the root of your project:

{
  "glsl": {
    "rootDir": "./src",
    "outDir": "./dist",
    "extensions": ["glsl", "frag", "vert"],
    "minify": true,
    "allowJSIncludes": true,
    "verboseLevel": 0
  }
}

Build

Just run it to transform all glsl files from the input directory into the corresponding glsl.js JavaScript modules in the output directory.

npm run start -p ../threeify

Watch

To have the transpiler constantly run and transpile files incrementally on change use the watch option:

npm run -p ../threeify -w

Features

  • Allow you to keep your glsl files in raw glsl.
  • Convert glsl files into JavaScript modules.
  • Mix JS generated glsl with raw glsl files.
  • Support "#pragma once" include guard creation.
  • Incremental updates when in watch mode.

Example

An original rgbe.glsl file:

#pragma once
#pragma include "../../math/math.glsl"

vec4 rgbeToLinear( in vec4 value ) {
	return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );
}

vec4 linearToRGBE( in vec4 value ) {
	float maxComponent = max( max( value.r, value.g ), value.b );
	float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );
	return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );
}

Will be transformed into a rgbe.glsl.js JavaScript module:

import _renderers_webgl2_shaders_includes_math_math_glsl from "../../math/math.glsl.js";

export default /* glsl */ `
#ifndef _renderers_webgl2_shaders_includes_color_spaces_rgbe_glsl // start of include guard
#define _renderers_webgl2_shaders_includes_color_spaces_rgbe_glsl

${_renderers_webgl2_shaders_includes_math_math_glsl}

vec4 rgbeToLinear( in vec4 value ) {
	return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );
}

vec4 linearToRGBE( in vec4 value ) {
	float maxComponent = max( max( value.r, value.g ), value.b );
	float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );
	return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );
}

#endif // end of include guard
`;

Which you can use in your JavaScript code via:

import rgbe_code from "rgbe.glsl.js";

console.log(rgbe_cole);