Introducing gloc for Open Web Shader Linking

UPDATE: Check out video of David Sheets’ presentation at WebGL Camp Orlando from Friday March 16.

UPDATE: David Sheets is scheduled to speak at the next San Francisco WebGL Developer’s Meetup in May.

We have just released our first version of gloc, a toolkit for WebGL and OpenGL ES2 GLSL shaders. The purpose of gloc is to make it much easier to build – and much easier to share – shaders. As a result, we hope gloc will help to further the creative potential of 3D graphics on the web and mobile platforms. (gloc links our creativity!)

With gloc, shaders and shader fragments, for numerical and graphics functions, become portable first-class web resources.

What gloc enables:

  • Libraries of shader functions
  • Capability-based shader component fall-backs
  • Collaborative shading effect mash-ups
  • LD_PRELOAD-like functionality
  • Compression by factorization of common shader functions

What gloc makes much easier:

  • Semantically-linked shaders in visualization systems
  • Cascading shaders for selective overriding
  • User Interface effects and compositing
  • and much more!

Where gloc lives:

The source code for the gloc suite version 1.0.0 has been released under the BSD 3-Clause license on GitHub. A Web interface is immediately available.

How gloc works:


gloc pipeline: gloc transforms ES SL into glo object files which are subsequently linked by glol with other glo resources to produce complete WebGL shaders.

gloc is a multi-stage compiler that accurately parses and reifies the lexical structure of the language tokens, the lexical preprocessor, and the shading language proper. Every token’s position is tracked to the file, line and column, and comments are tagged to their nearest token. gloc’s preprocessor is first-class, open-scoped, and partial, which allows staged evaluation of preprocessor directives as environmental parameters become known.

After the parsing and evaluation of the preprocessor expressions, gloc analyzes the potential shading language token streams for validity (grammatical only in this release, type checking will be added in a future release). gloc’s shading language parser is also open-scoped, allowing for undeclared variables, functions, and types. Scope analysis is then performed on the token streams; and finally, required and exported macros and symbols are inferred.

The result of this scope analysis and a minimally modified reserialization of the source is then packaged into a simple JSON format, glo. The glo format we have designed makes accurate linking as easy as possible with a concise linking algorithm, glol. glo includes support for link maps indicating the location of each linked source fragment to aid debugging. Also included is optional hyperlinked authorship metadata declaring the copyright holder, author, license, library, version, and build. We recommend transporting glo shader libraries in the glom manifest format which provides an ordered, named, hierarchical JSON structure around each glo object. The glom format and glol algorithm are flexible enough to provide storage and transport for arbitrary application-specific JSON objects in a well-defined order.

Finally, the generated glo files may be linked back into valid shader programs by gloc or a simple JavaScript linker, glol.js, included with the distribution. The linking algorithm takes a list of symbols to be satisfied (['main'] by default) and a search path of glo resources to use in shader construction.

As always, we welcome comments, contributions, and discussions on OCaml, WebGL and pretty much anything cool! :)

Subscribe to the RSS feed of this blog or join the gloc-users or gloc-devel mailing lists at OCaml Forge

Happy hacking!

  • http://zproxy.wordpress.com/ Arvo Sulakatko

    Rather interesting idea. Waiting for more examples :)

  • Lindsay Kay

    This might just be what I need for tidying up shader composition in SceneJS