By repeatedly calling EndPrimitive, after one or more EmitVertex calls, multiple primitives can be generated. Whenever EndPrimitive is called, all emitted vertices for this primitive are combined into the specified output render primitive. In our case we want to at least generate one line strip primitive.Įach time we call EmitVertex, the vector currently set to gl_Position is added to the output primitive. The geometry shader expects you to generate/output at least one of the primitives you specified as output. Using the vertex data from the vertex shader stage we can generate new data with 2 geometry shader functions called EmitVertex and EndPrimitive. The geometry shader receives all vertices of a primitive as its input. Note that it is declared as an array, because most render primitives contain more than 1 vertex. Here it is declared as an interface block (as discussed in the previous chapter) that contains a few interesting variables of which the most interesting one is gl_Position that contains the vector we set as the vertex shader's output. GLSL gives us a built-in variable called gl_in that internally (probably) looks something like this: To generate meaningful results we need some way to retrieve the output from the previous shader stage. Each extra point results in a new line between the new point and the previous point as you can see in the following image with 5 point vertices: In case you're wondering what a line strip is: a line strip binds together a set of points to form one continuous line between them with a minimum of 2 points. In this particular case we're going to output a line_strip with a maximum number of 2 vertices. The geometry shader also expects us to set a maximum number of vertices it outputs (if you exceed this number, OpenGL won't draw the extra vertices) which we can also do within the layout qualifier of the out keyword. To generate a single triangle for example we'd specify triangle_strip as the output and output 3 vertices. With just these 3 output specifiers we can create almost any shape we want from the input primitives. Like the input layout qualifier, the output layout qualifier can take several primitive values: We also need to specify a primitive type that the geometry shader will output and we do this via a layout specifier in front of the out keyword. The number within the parenthesis represents the minimal number of vertices a single primitive contains. If we'd chosen to draw vertices as GL_TRIANGLES we should set the input qualifier to triangles. These are almost all the rendering primitives we're able to give to rendering calls like glDrawArrays.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |