0

How it possible to pass data through shaders, when using vertex, tess. control, tess. evaluation, geometry and fragment shaders. I've tried using interface block this way.

//vertex shaders
out VS_OUT { ... } vs_out;

Than I wrote this code in tessellation control shader:

in VS_OUT { ... } tc_in; 
out TC_OUT { ... } tc_out;

So, tesselation control shader called once for every vertex. Does it mean that tc_in must be not array but single variable. I'm not really sure about that because of sneaky gl_InvocationID.

Then things become tough. Tessellation evaluation shader. Something tells me that evaluation shader should take interface block as array.

in TC_OUT { ... } te_in[];
out TE_OUT { ...  } te_out[];

Moving to geometry shader. Geometry shader takes multiple vertices, so, definitely array interface block.

in TE_OUT  { ... } gs_in[];
out vec3 random_variable;
...
random_variable = gs_in[whatever_index];

Seems legit for me, but data didn't come to fragment shader.

I would appreciate any advice.

Peter
  • 435
  • 1
  • 3
  • 11

1 Answers1

2

Tessellation control shaders take the vertices of a patch as modify them in some way, so their input and output is

in VS_OUT { ... } tc_in[]; 
out TC_OUT { ... } tc_out[];

The control shader gets called for every patch vertex (see which one by using gl_InvocationID), so you usually don't need any loops to implement it.

Tessellation evaluation shaders take these modified vertices and output a single vertex per invocation, thus we have

in TC_OUT { ... } te_in[];
out TE_OUT { ...  } te_out;

Geometry shaders take multiple vertices and may output a different number of vertices, but these are constructed explicitly using EmitVertex and EmitPrimitive, so there is only one output element that has to be filled before each call of EmitVertex:

in TE_OUT { ... } gs_in[];
out GS_OUT { ... } gs_out;

But don't forget to set glPosition in your geometry shader, otherwise OpenGL won't know where to place your vertices.

The interpolated values of gs_out are then passed to the fragment shader.

Tobias Ribizel
  • 5,331
  • 1
  • 18
  • 33
  • Thank you very much! You helped a lot! – Peter Jul 04 '17 at 19:07
  • Glad to be of help. If you want some examples, when I first used tessellation shaders, [this article](http://prideout.net/blog/?p=48) helped me understand the concepts and implementation. – Tobias Ribizel Jul 04 '17 at 19:10