0
votes

I setup a phong shader with glsl which works fine.

When I render my object without "this line", it works. But when I uncomment "this line" the world is stil built but the object is not rendered anymore, although "LVN2" is not used anywhere in the glsl code. The shader executes without throwing errors. I think my problem is a rather general glsl question as how the shader works properly.

The main code is written in java.

Vertex shader snippet:

    // Light Vector 1
    vec3 lightCamSpace = vec4(viewMatrix * modelMatrix * lightPosition).xyz;
    out_LightVec = vec3(lightCamSpace - vertexCamSpace).xyz;

    // Light Vector 2
    vec3 lightCamSpace2 = vec4(viewMatrix * modelMatrix * lightPosition2).xyz;
    out_LightVec2 = vec3(lightCamSpace2 - vertexCamSpace).xyz;

Fragment shader snippet:

    vec3 LVN = normalize(out_LightVec);
    //vec3 LVN2 = normalize(out_LightVec2);  // <---- this line

EDIT 1:

GL_MAX_VERTEX_ATTRIBS is 29 and glGetError is already implemented but not throwing any errors.

If I change

vec3 LVN2 = normalize(out_LightVec2);

to

vec3 LVN2 = normalize(out_LightVec);

it actually renders the object again. So it really seems like something is maxed out. (LVN2 is still not used at any point in the shader)

2
It would be helpful if you include the entire code for each shader.bwroga
updated complete shaderslandmann123

2 Answers

1
votes

I actually found my absolutly stupid mistake. In the main program I was giving the shader the wrong viewMatrix location... But I'm not sure why it sometimes worked.

0
votes

I can't spot an error in your shaders. One thing that's possible is that you are exceeding GL_MAX_VERTEX_ATTRIBS by using a fifth four-component out slot. (Although limit of 4 would be weird, according to this answer the minimum supported amount should be 16, and it shouldn't even link in this case. Then again you are using GLSL 1.50, which implies OpenGL 3.2, which is pretty old. I couldn't find a specification stating minimum requirements for the attribute count.)

The reason for it working with the line uncommented could be the shader compiler being able to optimize the unused in/out parameter away, an unable to do so when it's referenced in the fragment shader body.

You could test my guess by querying the limit:

int limit;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &limit);

Beyond this, I would suggest inserting glGetError queries before and after your draw call to see if there's something else going on.