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. triangles_adjacency : GL_TRIANGLES_ADJACENCY or GL_TRIANGLE_STRIP_ADJACENCY ( 6).triangles: GL_TRIANGLES, GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN ( 3).lines_adjacency: GL_LINES_ADJACENCY or GL_LINE_STRIP_ADJACENCY ( 4).lines: when drawing GL_LINES or GL_LINE_STRIP ( 2).points: when drawing GL_POINTS primitives ( 1).This input layout qualifier can take any of the following primitive values: We do this by declaring a layout specifier in front of the in keyword. Gl_Position = gl_in.gl_Position + vec4( 0.1, 0.0, 0.0, 0.0) Īt the start of a geometry shader we need to declare the type of primitive input we're receiving from the vertex shader. Layout (line_strip, max_vertices = 2) out We're going to throw you right into the deep by showing you an example of a geometry shader: What makes the geometry shader interesting is that it is able to convert the original primitive (set of vertices) to completely different primitives, possibly generating more vertices than were initially given. The geometry shader can then transform these vertices as it sees fit before sending them to the next shader stage. A geometry shader takes as input a set of vertices that form a single primitive e.g. Geometry Shader Advanced-OpenGL/Geometry-Shaderīetween the vertex and the fragment shader there is an optional shader stage called the geometry shader.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |