0

I am trying to learn tessellation shaders in openGL 4.1. I understood most of the things. I have one question.

What is gl_InvocationID?

Can any body please explain in some easy way?

user253751
  • 57,427
  • 7
  • 48
  • 90

1 Answers1

2

gl_InvocationID has two current uses, but it represents the same concept in both.

In Geometry Shaders, you can have GL run your geometry shader multiple times per-primitive. This is useful in scenarios where you want to draw the same thing from several perspectives. Each time the shader runs on the same set of data, gl_InvocationID is incremented.

The common theme between Geometry and Tessellation Shaders is that each invocation shares the same input data. A Tessellation Control Shader can read every single vertex in the input patch primitive, and you actually need gl_InvocationID to make sense of which data point you are supposed to be processing.

This is why you generally see Tessellation Control Shaders written something like this:

gl_out [gl_InvocationID].gl_Position = gl_in [gl_InvocationID].gl_Position;

gl_in and gl_out are potentially very large arrays in Tessellation Control Shaders (equal in size to GL_PATCH_VERTICES), and you have to know which vertex you are interested in.

Also, keep in mind that you are not allowed to write to any index other than gl_out [gl_InvocationID] from a Tessellation Control Shader. That property keeps invoking Tessellation Control Shaders in parallel sane (it avoids order dependencies and prevents overwriting data that a different invocation already wrote).

Community
  • 1
  • 1
Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • I may have neglected to point this out - your TCS runs (is invoked) `GL_PATCH_VERTICES`-many times for every patch you process. – Andon M. Coleman Dec 14 '14 at 14:46
  • Dear Andon, Can you please also let me know that what is meant by GL_MAX_PATCH_VERTICES – Muhammad Awais Khalid Dec 14 '14 at 20:33
  • @MuhammadAwaisKhalid: `GL_**MAX**_PATCH_VERTICES`? That is the largest number of control points your implementation supports in a patch primitive. I have a description [here](http://stackoverflow.com/questions/24075462/gl-triangles-with-tessellation-shaders/24075672#24075672). – Andon M. Coleman Dec 14 '14 at 20:46
  • I want to render a surface using B-Splines and tessellation shader. I have control points over the surface. Can you suggest me some steps how to do it.? – Muhammad Awais Khalid Dec 15 '14 at 14:17