使用GLSL-Unit编译片段着色器

时间:2013-11-05 20:53:40

标签: glsl webgl

我想使用GLSL-Unit来缩小片段着色器。但是,如果我执行此命令:

sunbox$ glsl-compiler --input=/Users/sunbox/Sites/bessa-app/xyz.fshader

我收到这些错误消息:

/usr/local/bin/glsl-compiler: line 1: syntax error near unexpected token `b'
/usr/local/bin/glsl-compiler: line 1: `var COMPILED=true,goog=goog||{};goog.global=this;goog.DEBUG=true;goog.LOCALE="en";goog.provide=function(b){if(!COMPILED){if(goog.isProvided_(b))throw Error('Namespace "'+b+'" already declared.');delete goog.implicitNamespaces_[b];for(var f=b;f=f.substring(0,f.lastIndexOf("."));){if(goog.getObjectByName(f))break;goog.implicitNamespaces_[f]=true}}goog.exportPath_(b)};'

那么,我如何简单地缩小片段着色器?

1 个答案:

答案 0 :(得分:3)

我终于开始工作了。 :d

对于所有感兴趣的人,您需要此文件: http://code.google.com/p/glsl-unit/source/browse/bin/template_glsl_compiler.js

...并安装了NodeJS。然后在着色器文件中添加一个简单的注释:

//! FRAGMENT

precision lowp float;
uniform sampler2D image;
varying vec2 src_position;
void main() {
    gl_FragColor = texture2D(image, src_position);
}

...而且烦人地你必须使用.glsl文件扩展名! :( 现在您可以运行此命令:

sunbox$ node /Volumes/template_glsl_compiler.js  --input=/Volumes/test.glsl --variable_renaming=INTERNAL --output=/Volumes/test.fshader.min

就是这样。编译输出将是:

//! VERTEX

//! FRAGMENT
precision lowp float;uniform sampler2D image;varying vec2 a;void main(){gl_FragColor=texture2D(image,a);}

真的很好! :)

相关问题