1

I am receiving this error on a pc where I cannot have access.

The error is on the Vertex Shader of the init program of the depth peeling technique.

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

This is the 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;
}

I never had problem with it before, I dev mostly on Nvidia and this one comes from a machine equipped with an ATI FirePro M7740

I also tried to google, of course, but there is no result with the quoted sentence: "illegal vector field selection length"..

I checked tens of time and it looks fine to me, no error on any vector length..

Any clue?

elect
  • 6,765
  • 10
  • 53
  • 119

1 Answers1

1

The problem is exactly what the error message says:

Illegal vector field selection length

The only line where you try to use length as a field selector is this one (line break added):

float cosine = dot(cameraSpacePosition, cameraSpaceNormal) /
               (cameraSpacePosition.length * cameraSpaceNormal.length);

This usage of length is invalid. There are two valid usages of length in GLSL:

  1. As a method on array variables, to find the number of elements in an array. Say if a is an array variable, you can write a.length() to get the number of elements. Note the parentheses.
  2. As a built-in function to calculate the length of a vector. If v is a vector, the length is calculated as length(v). Note the function syntax.

Based on the context, you're looking for option 2. The correct syntax for that line is:

float cosine = dot(cameraSpacePosition, cameraSpaceNormal) /
               (length(cameraSpacePosition) * length(cameraSpaceNormal));
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133
  • I still didnt test it, but looking on the glsl docs, you are right. Thanks for the tip, Reto – elect Feb 09 '15 at 09:56
  • Reto, on Nvidia it works, on Amd doesnt.. does this mean the Nvidia driver is fixing it by recompiling it? – elect Apr 16 '15 at 09:10