Created
November 28, 2012 07:49
-
-
Save chrisdickinson/4159717 to your computer and use it in GitHub Desktop.
an example glslify main module.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// precision statements in child programs are ripped out. | |
// only the main module's precision statements will remain. | |
precision highp float; | |
precision highp vec2; | |
// only "attribute|varying|uniform" vars defined by the root program | |
// will be emitted. | |
attribute vec2 lol; | |
// a generic require statement. | |
// NB: quotes are not valid *anywhere* in a GLSL program. | |
// TODO: allow arbitrary expressions on the right hand side of a mapping. | |
#pragma glslify: add_three = require(./file2) | |
// child shaders may define "attribute" (incoming vertices) or "varying" | |
// (outgoing vertices). in that case, the requiring program can either link | |
// them to an existing variable at this level, or leave them for a parent requiring | |
// module to define. | |
// | |
// if no module defines a mapping for the "attribute|varying|uniform" var, an | |
// exception will be thrown an the program won't compile. | |
#pragma glslify: something = require(./file3, thing=lol) | |
// looking up modules from `node_modules/` works too -- if the package.json | |
// does not specify a `glslify` or `main`, then it will use `index.glsl`. | |
#pragma glslify: our_modulo = require(glsl-test) | |
void main(void) { | |
int result = our_modulo(something(add_three(3)), 5); | |
// TODO: when gl_Position (or gl_FragColor) is used in a submodule, | |
// export them as required names (like attributes and friends). | |
gl_Position = vec4(result, result, result, 1.0); | |
} | |
// you may export a declaration from your module (but one, and only one.) | |
#pragma glslify: export(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precision highp float; | |
precision highp vec2; | |
attribute vec2 lol; | |
int b_x_add_four(int y) { | |
return y + 4; | |
} | |
int a_x_main(int z) { | |
return b_x_add_four(z) - 1; | |
} | |
vec2 c_x_test(int z) { | |
return b_x_add_four(z); | |
} | |
int e_x_modulo(int a, int b) { | |
return a % b; | |
} | |
void main(void) { | |
int result = e_x_modulo(c_x_test(a_x_main(3)), 5); | |
gl_Position = vec4(result, result, result, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment