1
$\begingroup$

I am trying to pass vertex attributes from my vertex shader -> geometry shader and then to the fragment shader.

Pretty simple program, here is my vertex shader:

#version 440 core

uniform mat4 uModelViewMatrix;
uniform mat4 uProjMatrix;

in vec4 aPosition;

out vec3 modelPosition;

void main()
{
    modelPosition = aPosition.xyz;
    gl_Position = uProjMatrix * uModelViewMatrix * aPosition;
}

Here is my geometry shader:

#version 440 core

layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;

in vec3 modelPosition[];

out vec3 gModelPosition[];

void main()
{
    for (int i = 0; i < gl_in.length(); i++)
    {
        gl_Position = gl_in[i].gl_Position;
        EmitVertex();
    }
    gModelPosition[0] = modelPosition[0];
    gModelPosition[1] = modelPosition[1];
    gModelPosition[2] = modelPosition[2];
    EndPrimitive();
}

And here is my fragment shader:

#version 440 core

in vec3 gModelPosition;

out vec4 fragColor;

void main()
{
    fragColor = vec4(gModelPosition, 1.0);
}

I get the following error:

PROGRAM_LINKING_ERROR: error: "gModelPosition" not declared as input from previous stage

If I just comment out the last line in the fragment shader, and say fragColor = vec4(1.0); it works fine. And I clearly am declaring gModelPosition as an input from the previous stage.

Am I doing something wrong here?

$\endgroup$
1
  • 1
    $\begingroup$ If you solved your problem yourself, you can answer your own question. Deleting it just means the next person with a similar problem won't get the benefit of your experience. $\endgroup$
    – Dan Hulme
    Commented Oct 25, 2017 at 21:55

1 Answer 1

2
$\begingroup$

The issue was that I declared out vec3 gModelPosition[] as an array in my geometry shader.

It should have only been declared as a vec3 (i.e. out vec3 gModelPosition)

$\endgroup$
1
  • $\begingroup$ You should also write to them the same way you write to gl_Position: before calling EmitVertex(). $\endgroup$ Commented Oct 27, 2017 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.