Geometry Shaders (geometry Shader)

Monday to Friday, a day, 7 am Beijing time - time update, bilingual, while learning program while playing the guitar, do a wonderful yard farming!

Do not doubt whether there are translation problems, our engineers are Lanxiang graduation translate it!

The geometry shader is logically the last shader stage in the front end (for logically, geometry shader is the last shader stages of the rendering pipeline), sitting after the vertex and tessellation stages and before the rasterizer (after vertex and tessellation, grating of before). the geometry shader runs once per primitive and has access to all of the input vertex data for all of the vertices that make time (processing time for each geometry shader a primitive, each treatment up the primitive being processed, All points can access the primitives). the geometry shader is also unique among the shader stages in that it is able to increase or reduce the amount of data flowing through the pipeline in a programmatic way (geometry shader is very unique it may increase or decrease the output primitives) programmatically. Tessellation shaders can also increase or decrease the amount of work in the pipeline, but only implicitly by setting the tessellation levelfor the patch (although tessella tion may be increased or decreased elements, but can only do implicitly by some settings).

Another unique feature of geometry shaders is that they can change the primitive mode mid-pipeline (another point is unique geometry shader mode can be changed during the primitives). For example, they can take triangles as input and produce a bunch of points or lines as output (for example they may be used as input primitive triangle, but the final output point or line), or even create triangles from independent points (or even more triangles created by the point input). An example geometry shader is shown in Listing 3.9. (Listing3.9 shows a sample of a geometry shader)

#version 450 core
layout (triangles) in;
layout (points, max_vertices = 3) out;
void main(void)
{
int i;
for (i = 0; i < gl_in.length(); i++)
{
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
}
Listing 3.9: Our first geometry shader

The shader shown in Listing 3.9 acts as another simple pass-through shader that converts triangles into points so that we can see their vertices (Listing 3.9 shows a simple geometry shader, it simply triangles into dot). The first layout qualifier indicates that the geometry shader is expecting to see triangles as its input (first modifier want triangular geometry shader represented as input). The second layout qualifier tells OpenGL that the geometry shader will produce points and that the maximum number of points that each shader will produce will be three (second modifier is noted that the output is a point geometry shader, and each output of up to 3 points). in the main function, a loop runs through all of the members of the gl_in array, which is determined by calling its .length () function (in the main function, there is a loop iterates gl_in array, its size can be obtained through the interface length)

We actually know that the length of the array will be three because we are processing triangles and every triangle has three vertices (in fact, we already know that the array size is 3, because the data we input is a triangle, and the triangle has three points). The outputs of the geometry shader are again similar to those of a vertex shader (these output data becomes again more vertex shader output data of the same). in particular, we write to gl_Position to set the position of the resulting vertex (especially we use gl_Position to set the position of the vertex). Next, we call EmitVertex (), which produces a vertex at the output of the geometry shader (we then call EmitVertex outputting a dot). Geometry shaders automatically call EndPrimitive () at the end of your shader, so calling this function explicitly is not necessary in this example (geometry shader will automatically call EndPrimitive, so you do not have to be displayed to call it in the shader). As a result of running this shader, three vertices will be produc ed and rendered as points (after the run, there will be three points are rendered)

By inserting this geometry shader into our simple one tessellated triangle example, we obtain the output shown in Figure 3.2 (in this geometry shader stuffed after our rendering pipeline, we will get the results in Figure 3.2). To create this image , we set the point size to 5.0 by calling glPointSize () (in order to get this picture, we have set the point size became 5.0, so that the point can be bigger, and can easily be seen). this makes the points large and highly visible

Geometry Shaders (geometry Shader)

Translations of this day to get here, see you tomorrow, bye ~

Get the latest plot first time, please pay attention to the Eastern Han Dynasty academy and the heart of the public graphic No.

Han College, waiting for you to play Oh

Guess you like

Origin blog.51cto.com/battlefire/2421591