编译问题,简单的 GLSL 着色器
Compilation issue, simple GLSL shader
最近熟悉了 GLSL,我编写了这个简单的着色器,它应该在 2D 环境中绘制的多边形周围创建轮廓。但是,我似乎无法让它通过编译,因为它让我困惑于以下错误:
Failed to compile fragment shader: 0(2) : error C0000: syntax error,
unexpected identifier, expecting '{' at token "tex" 0(3) : syntax
error, unexpected ')', expecting '::' at token ")"
这是有问题的着色器:
uniform vec2 stepSize;
uniform sampler2d tex;
vec4 borderEffect(vec4 col, vec2 texture Post, sampler2d texture) {
float outlineIntensity = 4*texture2d(texture, texturePos).a
- texture2d(texture, texturePos + vec2(stepSize.x, 0.0)).a
- texture2d(texture, texturePos + vec2(-stepSize.x, 0.0)).a
- texture2d(texture, texturePos + vec2(0.0, stepSize.y)).a
- texture2d(texture, texturePos + vec2(0.0, -stepSize.y)).a;
return mix(texture2d(texture, texturePos), col, outlineIntensity);
}
void main() {
gl_FragColor = gl_Color*borderEffect(vec4(0.0, 0.0, 0.0, 1.0), gl_TexCoord[0].xy, tex):
}
所以,我的问题是,这些错误是什么意思,我该如何修复它们?
它必须是统一的 sampler2D,在你的第 2 行有一个大 'D'。
最近熟悉了 GLSL,我编写了这个简单的着色器,它应该在 2D 环境中绘制的多边形周围创建轮廓。但是,我似乎无法让它通过编译,因为它让我困惑于以下错误:
Failed to compile fragment shader: 0(2) : error C0000: syntax error, unexpected identifier, expecting '{' at token "tex" 0(3) : syntax error, unexpected ')', expecting '::' at token ")"
这是有问题的着色器:
uniform vec2 stepSize;
uniform sampler2d tex;
vec4 borderEffect(vec4 col, vec2 texture Post, sampler2d texture) {
float outlineIntensity = 4*texture2d(texture, texturePos).a
- texture2d(texture, texturePos + vec2(stepSize.x, 0.0)).a
- texture2d(texture, texturePos + vec2(-stepSize.x, 0.0)).a
- texture2d(texture, texturePos + vec2(0.0, stepSize.y)).a
- texture2d(texture, texturePos + vec2(0.0, -stepSize.y)).a;
return mix(texture2d(texture, texturePos), col, outlineIntensity);
}
void main() {
gl_FragColor = gl_Color*borderEffect(vec4(0.0, 0.0, 0.0, 1.0), gl_TexCoord[0].xy, tex):
}
所以,我的问题是,这些错误是什么意思,我该如何修复它们?
它必须是统一的 sampler2D,在你的第 2 行有一个大 'D'。