I have a very confusing error somewhere in the vertex or fragment shader. The rendering works when I do not actively use the block interface in the fragment shader. But when I am using it error 1281 occurs. Below you see the working vertex and fragment shaders. The error is discusse below the code.
Vertex shader:
#version 430
in layout (location = 0) vec3 position;
in layout (location = 1) vec4 color;
in layout (location = 2) vec3 normal;
in layout (location = 3) vec2 uv;
in layout (location = 4) vec3 tangent;
in layout (location = 5) int materialId;
uniform mat4 pr_matrix;
uniform mat4 vw_matrix = mat4(1.0);
uniform mat4 ml_matrix = mat4(1.0);
out VS_OUT {
vec4 color;
vec2 texture_coordinates;
vec3 normal;
vec3 tangent;
vec3 binormal;
vec3 worldPos;
int materialIdOut;
} vs_out;
out vec4 colorOut;
void main()
{
vs_out.color = color;
vs_out.texture_coordinates = uv;
mat3 normalMatrix = transpose ( inverse ( mat3 ( ml_matrix )));
vs_out.normal = normalize ( normalMatrix * normalize ( normal ));
gl_Position = ( pr_matrix * vw_matrix * ml_matrix ) * vec4 ( position, 1.0);
colorOut = vec4(vs_out.normal,1.0);
}
WORKING fragment shader (normal is used as color):
#version 430
uniform vec3 cameraPos;
uniform mat4 ml_matrix;
uniform mat4 vw_matrix;
uniform sampler2D texSlots[32];
in VS_OUT {
vec4 color;
vec2 texture_coordinates;
vec3 normal;
vec3 tangent;
vec3 binormal;
vec3 worldPos;
int materialIdOut;
} fs_in;
out vec4 gl_FragColor;
in vec4 colorOut;
void main()
{
gl_FragColor = colorOut;
}
If I am trying to use the block interface in the fragment shader like gl_FragColor = fs_in.color; or gl_FragColor = vec4(fs_in.normal,1.0);
the error 1281 occurs. I really do not see why this is not working.
EDIT: solution:
there where in fact two problems: 1) int was interpreted as float From the application I send the material attribute to the shader by using glVertexAttribPointer(SHADER_MATERIAL_INDEX, 1, GL_INT, ...); which leads to the problem, that attribute was interpreted as float in the shader By using glVertexAttribIPointerEXT(SHADER_MATERIAL_INDEX, 1, GL_INT, ...); we can overcome this problem 2) The program linking was not successful "error c5215 integer varying must be flat" which leads to a change in the vertex and fragment shader.
out VS_OUT {
vec4 color;
vec2 texture_coordinates;
vec3 normal;
vec3 tangent;
vec3 binormal;
vec3 worldPos;
flat int materialIdOut;
} vs_out;
and
in VS_OUT {
vec4 color;
vec2 texture_coordinates;
vec3 normal;
vec3 tangent;
vec3 binormal;
vec3 worldPos;
flat int materialIdOut;
} fs_in;
Now everything works perfect