在一台计算机上编译此着色器而在另一台计算机上编译时,“纹理”功能会出错。着色器编译的OpenGL版本是3.1。另一台运行OpenGL 4.1的计算机虽然存在这些错误但不会编译它。
0(21) : error C1105: cannot call a non-function
0(58) : error C1105: cannot call a non-function
我们在线查看但未找到答案。文档说'texture2D'和'shadow2D'可以作为替换,但'shadow2D'给出一个错误,说它在glsl版本140之后被删除了,即使编译程序中的OpenGL上下文是3.1。我的理解是显卡向后兼容以前的glsl版本。
以下是问题着色器:
#version 140
in vec3 position;
in vec2 texCoord;
in vec3 normal;
out vec3 normalView_vs;
out vec3 normalShadow_vs;
out vec3 eyeView_vs;
out vec3 lightDirView_vs;
out vec2 texCoord_vs;
out vec4 shadowCoord_vs;
uniform mat4 worldMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelProjectionMatrix;
uniform mat4 depthModelProjectionMatrix;
uniform vec3 sunDirection;
const mat4 biasMatrix = mat4(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f);
void main(void)
{
eyeView_vs = -(viewMatrix * worldMatrix * vec4(position, 1.0f)).xyz;
lightDirView_vs = (viewMatrix*vec4(sunDirection, 0.0f)).xyz;
normalShadow_vs = (depthModelProjectionMatrix * vec4(normal, 0.0f)).xyz;
normalView_vs = (viewMatrix * worldMatrix * vec4(normal, 0.0f)).xyz;
// Note: Only correct if worldMatrix does not scale the model ! Use its inverse transpose if not.
gl_Position = modelProjectionMatrix * vec4(position, 1.0f);
texCoord_vs = texCoord;
shadowCoord_vs = biasMatrix * depthModelProjectionMatrix * vec4(position, 1.0f);
}