Primitive Assembly, Clipping, and Rasterization

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

After the front end of the pipeline has run (which includes vertex shading, tessellation, and geometry shading) (those of the rendering pipeline stage performs current-mentioned After completion), a fixed-function part of the pipeline performs a series of tasks that take the vertex representation of our scene and convert it into a series of pixels (the fixed part of the rendering pipeline will be in line of those points in space by means of a series of pixels becomes), which in turn need to be colored and written to the screen (these pixels are then colored and refresh the screen afterwards). the first step in this process is primitive assembly (FIG. the first step is to generate a pixel element), which is the grouping of vertices into lines and triangles (i.e. make point they become a line and triangles). primitive assembly still occurs for points, but it is trivial in that the step case (a pixel generated primitives may be generated pixel, but not very important point generation)

Once primitives have been constructed from their individual vertices, they are clipped against the displayable region, which usually means the window or screen, but can also be a smaller area known as the viewport (as from a number of separate dots to build primitive time , they will be cut two things, the first one is a second viewport window). finally, the parts of the primitive that are determined to be potentially visible are sent to a fixed-function subsystem called the rasterizer (final visible pixels that are considered to be passed to the next stages: rasterization) This block determines which pixels are covered by the primitive (point, line, or triangle) and sends the list of pixels on to the next stage-that is, fragment shading (this module which determines the pixel area covered by the primitive then sends a list of these pixels to the next stage: fragment shader)

Clipping (cut)

As vertices exit the front end of the pipeline, their position is said to be in clip space. (When the point is the front of all the phase processing is complete, they are in clip space) This is one of the many coordinate systems that can be used to represent positions (this is an ordinary coordinate system can be expressed position). you may have noticed that the gl_Position variable that we have written to in our vertex, tessellation, and geometry shaders has a vec4 type (you may have noticed we used in the vertex tessellation and geometry shader is in gl_Position type) of a vec4, and that the positions we have produced by writing to it are all four-component vectors (and when we assigned to it are all four-dimensional vector ). this is what is known as a homogeneous coordinate (which is popularly known as the homogeneous coordinates). the homogeneous coordinate system is used in projective geometry because much of the math ends up being simpler in homogeneous coordinate space than it does in regular Cartesian space ( Coordinates system is used for projective geometry, because a lot of mathematics in the Cartesian coordinate system is easier in homogeneous coordinate system).

Although the output of the front end is a four-component homogeneous coordinate, clipping occurs in Cartesian space (although the output of these stages in front of us are all homogeneous coordinates of the coordinates, but the clipping occurred in the Cartesian coordinate system). Thus , to convert from homogeneous coordinates to Cartesian coordinates, OpenGL performs a perspective division, which involves dividing all four components of the position by the last, w component (that is, in order to homogenous coordinates transformed into Cartesian coordinates, OpenGL fixed will do this conversion processing section). this has the effect of projecting the vertex from the homogeneous space to the Cartesian space, leaving w as 1.0 (such put all homogeneous coordinates transformed into Cartesian coordinates, becomes part of the final w a 1). in all of the examples so far, we have set the w component of gl_Position as 1.0, so this division has not had any effect (in all examples, we gave partial write w is 1.0, the actual on So far, this transformation is actually no data Ring). When we explore projective geometry in a short while, we will discuss the effect of setting w to values ​​other than 1.0 (where we discuss later than 1.0 part w)

After the projective division, the resulting position is in normalized device space (after homogeneous coordinates into Cartesian coordinates, we obtain the position coordinates in NDC). In OpenGL, the visible region of normalized device space is the volume that extends from -1.0 to 1.0 in the x and y dimensions and from 0.0 to 1.0 in the z dimension (viewable space in OpenGL, NDC coordinate system as x, y from -1.0 ~ 1.0), z from 0 to 1.0 . any geometry that is contained in this region may become visible to the user and anything outside of it should be discarded (any coordinate in this space will be seen, not in this space coordinates will not be seen). the six sides of this volume are formed by planes in three-dimensional space (the cut with a small box is enclosed in a three-dimensional space 6 faces). As a plane divides a coordinate space in two, the volumes on each side of the plane are called half-spaces (a plane space can be cut in half, each side of the plane of the small box are called half-cut space )

Before passing primitives on to the next stage (before the primitive is passed to the next stage), OpenGL performs clipping by determining which side of each of these planes the vertices of each primitive lie on (OpenGL plane through the point in cutting small box which side to determine what points may be transferred to the next stage). Each plane effectively has an "outside" and an "inside." If a primitive's vertices all lie on the "outside" of any one plane, then the whole thing is thrown away (if the primitive whole are outside the clipping small box, the entire primitive will be clipped). If all of primitive's vertices are on the "inside" of all the planes (and therefore inside the view volume ), then it is passed through unaltered (if there are elements in the whole crop small box, the entire primitive transferred intact to the next stage). primitives that are partially visible (which means that they cross one of the planes) must be handled specially (if the primitive is a part of the small box, the small box in an outer portion , Then the primitive special treatment after being sent to the next stage). More details about how this works is given in the "Clipping" section in Chapter 7 (more about trimming, see Chapter VII)

Viewport Transformation (viewport transformation)

After clipping, all of the vertices of the geometry have coordinates that lie between -1.0 and 1.0 in the x and y dimensions (after trimming is completed, the geometric coordinates of all points are converted into a -1 to 1). Along with az coordinate that lies between 0.0 and 1.0, these are known as normalized device coordinates (coordinates and z range is 0 to 1, the coordinates are referred to as NDC coordinates). However, the window that you're drawing to has coordinates that usually start from (0, 0) at the bottom left and range to (w - 1, h - 1) (however, you know the window coordinates are usually from (0,0) to (w-1, h- 1) the coordinate range, wherein w, h refers to the pixel window width and height), where w and h are the width and height of the window in pixels, respectively. to place your geometry into the window, OpenGL applies the viewport transform, which applies a scale and offset to the vertices' normalized device coordinates to move them into window coordinates (geometric point in order to allow you to go into the window, OpenGL using viewport transformation, NDC and offset by scaling the coordinates into window coordinates).

void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
and(和)

glDepthRange void (nearVal GLdouble, respectively, farVal GLdouble, respectively);
This form Transform Takes The following :( this transformation uses the following mathematical formula)
Primitive Assembly, Clipping, and Rasterization
Here, xw, yw, and ZW are coordinates of the Resulting The Vertex The window in Space (where xw, yw, zw are coordinates in the window coordinate system output), and xd, yd, and zd are the incoming coordinates of the vertex in normalized device space (xd, yd, zd is NDC input coordinates). px and py are the width and height of the viewport in pixels, and n and f are the near and far plane distances in the z coordinate, respectively (px, py is a viewport coordinate, in pixels, n, f is the near clipping plane and the far clipping plane z coordinates). Finally, ox, oy, and oz are the origins of the viewport ( last, ox, oy, oz are viewport origin)

Culling (removing)

Before a triangle is processed further (more prior treatment), it may be optionally passed through a stage called culling (it is also called the culling been to deal with a job), which determines whether the triangle faces toward or away from the viewer and can decide whether to actually go ahead and draw it based on the result of this computation (this process is mainly through currently being drawn primitive whether facing the camera but decided not to draw it). if the triangle faces toward the viewer, then it is considered to be frontfacing (if the triangle facing the camera, then it will be considered the front); otherwise, it is said to be back-facing (otherwise the surface is considered to be the back) it is very common to. discard triangles that are back-facing because when an object is closed, any back-facing triangle will be hidden by another front-facing triangle (when a surface is considered to be the back, usually when we do not draw the face, because it will be blocked in front of it)

To determine whether a triangle is front- or back-facing, OpenGL will determine its signed area in window space (to judge the front or back, OpenGL is determined that the area is determined in the symbol window space). One way to determine the area of a triangle is to take the cross product of two of its edges (method a triangle cross product of two sides). the equation for this is (the following formula)
Primitive Assembly, Clipping, and Rasterization
Here, and are the coordinates of the ith vertex of the triangle in window space and i ⊕ 1 is (i +1) mod 3 (Here are some explanations of the variables, but because the page can not display these complicated equations, please refer to the original the book) If the area is positive, then the triangle is considered to be front-facing (if this area is positive, then that is positive); if it is negative, then it is considered to be back-facing (if it is negative , then this would be considered negative). the sense of this computation can be reversed by calling glFrontFace () with dir set to either GL_CW or GL_CCW (this formula can be operational formula set settings are not the same as the fork by glFrontFace take the order may require the opposite of to) (where CW and CCW stand for clockwise and counterclockwise, respectively). This is known as the winding order of the triangle, and the clockwise or counterclockwise terms refer to the order in which the vertices appear in window organization sequence space (this ability is called triangular, clockwise or counterclockwise Determines the order of connection points of the triangle). By default, this state is set to GL_CCW,
Primitive Assembly, Clipping, and Rasterization
Once the direction that the triangle is facing has been determined, OpenGL is capable of discarding either front-facing, back-facing, or even both types of triangles (a triangle when the front and back surfaces are finalized, OpenGL conditions can be done excluded). By default, OpenGL will render all triangles, regardless of which way they face (by default, OpenGL will render all triangles, whether before or after). to turn on culling, call glEnable () with cap set to GL_CULL_FACE (to open removed, you need to call glEnable, incoming GL_CULL_FACE). when you enable culling, OpenGL will cull back-facing triangles by default (when you turn eliminate the time, OpenGL default would eliminate the back). to change which types of triangles are culled, call glCullFace () with face set to GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK. (you can also be provided to remove the surface by glCullFace) As points and lines do not have any geometric area, 2 this facing calculation does not apply to them and they can not be culled at this s Tage (dots and lines can not be calculated due to the area, the culling process will not be used to point and line).

Rasterization (rasterization)

Rasterization is the process of determining which fragments might be covered by a primitive such as a line or a triangle (rasterization problem which pixel is what primitive covers determination). There are myriad algorithms for doing this, but most OpenGL systems will settle on a half-space-based method for triangles (there are many algorithms that can do this, but most of the OpenGL will use half-space-based), as it lends itself well to parallel implementation (because this can be a good algorithm parallel processing elements). essentially, OpenGL will determine a bounding box for the triangle in window coordinates and test every fragment inside it to determine whether it is inside or outside the triangle (substantially, OpenGL will be used to calculate a bounding box window coordinate system of the triangle is in the bounding box inside). to do this, it treats each of the triangle's three edges as a half-space that divides the window in two (in order to achieve this, it will triangle with three sides are seen as a window cut into two half-space)

Fragments that lie on the interior of all three edges are considered to be inside the triangle and fragments that lie on the exterior of any of the three edges are considered to be outside the triangle (those falling inside the pixel is considered inside the triangle, pixels outside is outside the triangle). Because the algorithm to determine which side of a line a point lies on is relatively simple and is independent of anything besides the position of the line's endpoints and of the point being tested, many tests can be performed concurrently, providing the opportunity for massive parallelism (the judgment of lines and points is relatively simple, you can run concurrently various means)

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/2422261