下面的片段着色器有什么问题?它在GLSL 4.0下编译OK,但在GLSL 1.30上失败。
这是代码:
// Fragment Shader
"uniform sampler2D texture;\n"
"uniform sampler1D cmap;\n"
"uniform float minZ;\n"
"uniform float maxZ;\n"
"\n"
"void main() {\n"
" float height = texture2D(texture,gl_TexCoord[0].st);\n"
" float lum = (height-minZ)/(maxZ-minZ);\n"
" if (lum > 1.0) lum = 1.0;\n"
" else if (lum < 0.0) lum = 0.0;\n"
" gl_FragColor = texture1D(cmap, lum);\n"
"}"这些都是错误:
FRAGMENT glCompileShader "" FAILED
FRAGMENT Shader "" infolog:
0:7(2): error: initializer of type vec4 cannot be assigned to variable of type float
0:8(2): error: initializer of type vec4 cannot be assigned to variable of type float
0:9(6): error: operands to relational operators must be scalar and numeric
0:9(6): error: if-statement condition must be scalar boolean
0:9(17): error: value of type float cannot be assigned to variable of type vec4
0:10(11): error: operands to relational operators must be scalar and numeric发布于 2016-07-06 13:20:45
嗯,错误信息非常清楚什么是错误的:
0:7(2): error: initializer of type vec4 cannot be assigned to variable of type float
----
float height = texture2D(texture,gl_TexCoord[0].st);不能将vec4分配给浮点数。texture2D返回一个vec4,因此它不能分配到浮点高度。解决方案:在只需要一个通道时添加一个swizzle操作符:
float height = texture2D(texture,gl_TexCoord[0].st).r;除此之外,该着色器不应该编译在任何glsl版本> 140,因为gl_TexCoord在150年被删除。texture2D和texture1D方法也是如此,它们在150年被texture函数所取代。您真的用#version 400指定了glsl版本吗?
发布于 2016-07-06 13:22:19
您需要声明要编译的版本。正如在核心语言GLSL @ opengl.org中所解释的
#version指令必须出现在着色器中的其他任何内容之前,除了空格和注释。如果#version指令没有出现在顶部,那么它假设为1.10,这几乎肯定不是您想要的。
https://stackoverflow.com/questions/38224292
复制相似问题