PDA

View Full Version : Shader interface blocks.



DreamCore
08-10-2013, 06:04 AM
Hi,

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:


in VS_OUT
{
vec4 color;
} tcs_in[];

out TCS_OUT
{
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.

Thanks,

Robin

Alfonse Reinheart
08-10-2013, 08:50 AM
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 (https://www.opengl.org/wiki/Shader). 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 (https://www.opengl.org/wiki/Vertex_Specification#Non-array_attribute_values) like that, why not just send it as a uniform (https://www.opengl.org/wiki/Uniform_%28GLSL%29)?