Socket
Book a DemoInstallSign in
Socket

glslminify

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

glslminify

compress glsl code

0.0.1
unpublished
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

glslprep.js

glslprep.js is a Node.js script that optimizes GLSL, minifies the result and wraps it up in source code.

GLSL optimization is done via an emscripten-compiled version of glsl-optimizer (extracted from Mesa by Unity 3D development team and ported by Josh Koo) and the minification and wrapping stages are based-on glsl-unit (forked / fixed here, as the project appears dormant) using mustache.js for source code templates.

glslminify.js

The minification stage is also provided as a stand-alone library, which, unlike GLSL-unit as a whole, does not depend on Mustache or Node.

The source code tranformation is conservative, i.E. it does not change the meaning of the processed code. It does not rely on semantic analysis and thus allows the input source code to be incomplete, as is typically the case when portions of the code are added by some kind of 3D engine (e.g. using Three.js ShaderMaterials).

The library file is built using Google's Closure Compiler in ADVANCED mode resulting in a source code size of less than a hundred kilobytes, making it well-suited for browser-based development tools. It has been integrated into the Three.js editor. Try the live demo!

API example

The following code shows shader minification.

var shader = [ 
		myVertexShaderSourceCode, 
		myFragmentShaderSourceCode
];

var defines = {
		"LIGHTS_ENABLED": null
		"N_LIGHTS": 3
};

try {

	glslprep.minifyGlsl(shader, defines);

} catch (e) {

	if (e instanceof glslprep.SyntaxError)
		console.error(e.line + ":" + e.column + ": " + e.message);
	else
		console.error(e.stack || e);
}

myVertexShaderSourceCode = shader[glslprep.Shader.VERTEX];
myFragmentShaderSourceCode = shader[glslprep.Shader.FRAGMENT];

Omit the defines argument calling minifyGlsl to disable preprocessing.

The parser can also be called individually for a quick syntax check:

try {

	glslprep.parseGlsl(vertexShaderSourceCode, glslprep.Shader.VERTEX);

} catch (e) {

	// ... handle error
}

Keep in mind that syntactically valid GLSL is not guaranteed to compile and link in practice. In particular, symbol names are not checked. Also, the glsl-unit compiler will neither complain nor bother when minifying. Therefore incomplete shaders (typically missing some prefix prepended by a renderer) can be processed safely.

Depencencies

All dependencies are contained within this repository.

The library file combines code from the following sources:

  • A patched version of glsl-unit,
  • a minimal subset of Google's Closure Library, and
  • the very thin API layer provided by this package.

The Node script further uses glsl-optimizer and obviously needs Node to run.

Building

Apache Ant must be installed on the system. Simlpy invoke it in the top-level directory:

$ ant

Ant then uses the Closure Compiler which is contained in this package as a Java binary.

License

This package and all bundled dependencies may be used under the terms of the Apache License Version 2.

Keywords

glsl

FAQs

Package last updated on 22 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.