我使用https://github.com/glslify/glslify在glsl着色器之间共享代码。
我有一个vert着色器,它试图在vert的顶部包括一个模块:
#pragma glslify: JointAndPalette = require('./JointAndPalette.glsl');
#pragma glslify: decodeJointAndPalette = require('./decodeJointAndPalette.glsl');
JointAndPalette jointAndPalette = decodeJointAndPalette(inputProps);decodeJointAndPalette还依赖于JointAndPalette结构作为其返回定义。
JointAndPalette看起来像:
struct JointAndPalette
{
int jointId;
int paletteId;
};
#pragma glslify: export(JointAndPalette)decodeJointAndPalette看起来像:
JointAndPalette decodeJointAndPalette(float jointPaletteSplit) {
// implementation
JointAndPalette JandP;
JandP.jointId = int(x);
JandP.paletteId = int(y);
return JandP;
}
#pragma glslify: export(decodeJointAndPalette)从glslify文档中我还不清楚如何构造这种依赖关系。
发布于 2019-04-23 05:34:21
编辑- TLDR;
glsify分别计算每个文件,如果在多个文件中遇到相同的变量/函数/结构名称,glsify假设对象是本地的,并重新命名它们以避免名称冲突。
这意味着在文件中可以使用外部变量/function/struct之前,包含该变量/function/struct的文件必须由require命令导入。
在特定情况下,这意味着添加行。
#pragma glslify: JointAndPalette = require('./JointAndPalette.glsl');到文件decodeJointAndPalette.glsl,同时在顶点着色器顶部保留相同的require语句。
原始答案:
我在CLI模式下安装并运行glslify,如github页面所述。
npm install -g npm
glslify index.glsl在这里,index.glsl是你所描述的你的‘自动着色器’。输出显然是混乱的,glslify似乎认为JointAndPalette有多个定义,并给它们一个_0和_1后缀。
#define GLSLIFY 1
struct JointAndPalette_0
{
int jointId;
int paletteId;
};
JointAndPalette_1 decodeJointAndPalette(float jointPaletteSplit) {
// implementation
JointAndPalette_1 JandP;
JandP.jointId = int(x);
JandP.paletteId = int(y);
return JandP;
}
JointAndPalette_0 jointAndPalette = decodeJointAndPalette(inputProps);因此试图修改decodeJointAndPalette.glsl,以便它也可以导入JointAndPalette.glsl。
#pragma glslify: JointAndPalette = require('./JointAndPalette.glsl');
JointAndPalette decodeJointAndPalette(float jointPaletteSplit) {
// implementation
JointAndPalette JandP;
JandP.jointId = int(x);
JandP.paletteId = int(y);
return JandP;
}
#pragma glslify: export(decodeJointAndPalette)现在,使用修改后的glslify index.glsl输出的decodeJointAndPalette.glsl不再包含_0和_1后缀。
#define GLSLIFY 1
struct JointAndPalette
{
int jointId;
int paletteId;
};
JointAndPalette decodeJointAndPalette(float jointPaletteSplit) {
// implementation
JointAndPalette JandP;
JandP.jointId = int(x);
JandP.paletteId = int(y);
return JandP;
}
JointAndPalette jointAndPalette = decodeJointAndPalette(inputProps);这在我看来是对的。逻辑似乎是glsilify假设不同编译单元中同名的声明应该是唯一的实体,因此在合并的输出中重命名它们,而不是引起名称冲突。
https://stackoverflow.com/questions/55621850
复制相似问题