

Writing Modular and Versioned GLSL - mattdesl
http://mattdesl.svbtle.com/glslify

======
pheelicks
Looks nice.

I had the problem of modularizing GLSL code myself and ended up writing a
Require.js plugin which supported #include statements. Take a look at the
shaders in here if interested: [https://github.com/felixpalmer/lod-
terrain/tree/master/js/sh...](https://github.com/felixpalmer/lod-
terrain/tree/master/js/shaders) and [https://github.com/felixpalmer/amd-
three.js/blob/master/js/l...](https://github.com/felixpalmer/amd-
three.js/blob/master/js/lib/shader.js)

While glsify has a bunch of nice features that my plugin lacks, one thing mine
can do which (as far as I know) glsify cannot, is provide support for
redefining #define statements from JavaScript. I find this quite useful if I
need to have several similar shaders and want to tweak their behavior from
JavaScript. Something like (see [https://github.com/felixpalmer/amd-
three.js/blob/master/js/a...](https://github.com/felixpalmer/amd-
three.js/blob/master/js/app/material.js)):

define( ["shader!simple.vert"], function ( simpleVert ) { simpleFrag.define(
"faceColor", "vec3(1.0, 0, 0)" ); var vertexShader = simpleVert.value; } );

Do you have any thoughts on this feature, or even plans to support something
like this in the future?

~~~
mattdesl
Cool, I'll check it out.

I don't think it supports anything like that yet. There is some talk about
using glslify at runtime, to build "uber shaders" depending on particular
needs, and it seems like this kind of feature would be nice.

------
CoryG89
> Now, when somebody checks out your code, they can just run `npm init` on the
> package and it will grab all the GLSL snippets you’ve saved as dependencies.

Should they run `npm install` here to get all the package dependencies? Not
`npm init`?

~~~
mattdesl
Thanks, fixed.

