Shader interface blocks.


I want to send a color value through a pipeline consisting of a Vertex Shader, Tesselation Control Shader, Tesselation Evaluation Shader, Geometry Shader and Fragment Shader. I send the color value to the Vertex shader using the function

glVertexAttrib4fv(index, const GLfloat *v)

and my Vertex Shader picks it up using:

layout (location  = 0) in vec4 color

I then use an interface block in the Vertex Shader:

out VS_OUT
    vec4 color;
} vs_out;

vs_out = color;

The Tesselation Control shader then has the following:

    vec4 color;
} tcs_in[];

    vec4 color;
} tcs_out[];

tcs_out[gl_InvocationID].gl_Position = tcs_in[gl_InvocationID].gl_Position;

However I’m unsure how to handle the input/output of these interface blocks in the shaders that comes after that (Tesselation Evaluation, Geometry & Fragment Shader) since sometimes the blocks should be an array([]) and sometimes not and I’ve tried different ways but without success.

Again, I just want to send that color value all the way to the Fragment Shader so that I can use it there to color the pixels. I also know that you can send it using a single “out” variable but I want to know how to do it using interface blocks.



Whether or not a shader stage’s inputs or outputs are aggregated into arrays is part of the nature of that particular shader stage. It’s information that you can easily look up on each shader stage’s page on the Wiki. The aggregation of inputs or outputs into arrays doesn’t change when you’re using an interface block.

Also, unless you’re actually doing tessellation, you shouldn’t be using tessellation shaders. And unless you intend to actually do something with that geometry shader, you shouldn’t be using that either. Unless you actually need them, those stages are optional.

More importantly, if this color is really being sent by a non-array attribute like that, why not just send it as a uniform?