我在无法访问的电脑上收到此错误。
错误发生在深度剥离技术的init程序的顶点着色器上。
ERROR: 0:42: error(#222) Illegal vector field selection length
ERROR: 0:42: error(#222) Illegal vector field selection length
ERROR: error(#273) 2 compilation errors. No code generated
这是VS:
#version 330
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 uv;
out vec3 cameraSpacePosition;
out vec3 cameraSpaceNormal;
out vec2 oUV;
uniform mat4 modelToWorldMatrix;
/*
* Layout {lighting, normal orientation, hasTexture, selected}
*/
uniform ivec4 settings;
layout(std140) uniform vehicleMatrices {
mat4 worldToCameraMatrix;
mat4 cameraToClipMatrix;
};
void main()
{
vec4 c = worldToCameraMatrix * (modelToWorldMatrix * vec4(position, 1.0));
gl_Position = cameraToClipMatrix * c;
cameraSpacePosition = c.xyz;
cameraSpaceNormal = mat3(worldToCameraMatrix) * (mat3(modelToWorldMatrix) * normal);
switch (settings.y) {
case 0:
cameraSpaceNormal = -cameraSpaceNormal;
break;
case 1:
float cosine = dot(cameraSpacePosition, cameraSpaceNormal) / (cameraSpacePosition.length * cameraSpaceNormal.length);
if ( cosine > 0)
cameraSpaceNormal = -cameraSpaceNormal;
break;
}
oUV = uv;
}
之前我从来没有遇到任何问题,我主要是在Nvidia上开发,这款机器来自配备ATI FirePro M7740的机器
当然,我也尝试谷歌,但引用的句子没有结果:"非法矢量字段选择长度" ..
我检查了几十次,看起来很好,任何矢量长度都没有错误..
有任何线索吗?
答案 0 :(得分:0)
问题正是错误信息所说的:
非法矢量字段选择长度
您尝试使用length
作为字段选择器的唯一一行就是这一行(添加了换行符):
float cosine = dot(cameraSpacePosition, cameraSpaceNormal) /
(cameraSpacePosition.length * cameraSpaceNormal.length);
length
的这种用法无效。 GLSL中有两个length
的有效用法:
a
是一个数组变量,您可以编写a.length()
来获取元素的数量。请注意括号。v
是向量,则长度计算为length(v)
。注意函数语法。根据上下文,您正在寻找选项2.该行的正确语法是:
float cosine = dot(cameraSpacePosition, cameraSpaceNormal) /
(length(cameraSpacePosition) * length(cameraSpaceNormal));