[WebGL entry] 6. vertices and polygon. webgl entry vertices
Note: The article is translated from http://wgld.org/, the original author shanbenya (doxas). If I have additional instructions in the article, I will add [lufy:]. In addition, the research on webgl is not in-depth enough, and some professional words are required, if the translation is incorrect, please correct me.
Something that can be drawn in a 3D space
Anything can be traced in the Web GL world. The most basic components of plotting are the following.
Renewal point
Segment
Triangle
Although rectangle painting is provided in OpenGL, WebGL can only draw the above three types. Unlike the two-dimensional world, like the img tag in HTML, it is impossible to simply draw a rectangular image on the screen.
Basically, WebGL uses triangles to draw things on the screen. This triangle is a polygon. A polygon connects at least three vertices to draw a polygon. Therefore, at least three vertices are required for a polygon.
A vertex exists in a 3D space. Of course, this point must have coordinates. X is the horizontal coordinate of the vertex, y is the vertical coordinate, and z is the depth. Concatenates the vertices that contain the information to form a polygon.
In recent years, very realistic 3D games, Disney, organizing activities, and other 3D animations have actually done the same thing. With a large number of triangles that you cannot imagine, you can create extremely exquisite figures and scenes.
To draw a model with complex structures, you need to prepare a large number of very small polygon. The less polygon is used, the more obvious the angle of the drawn model (like the first generation of UA Fighter ). To draw a beautiful model, you need more polygon. Of course, if the number of these polygon increases, the number of fixed points will multiply, and the load of coordinate calculation will increase.
The difficulty in 3D rendering is that it is appropriate to increase the number of vertices and the number of polygon. If there are too many vertices and polygon, the processing speed may not keep up. If there are too few vertices and polygon, the visual effect will be reduced.
If it is an abstract design, the number of vertices and the number of polygon will be greatly reduced, but it is difficult to design it. It is really annoying.
Connection sequence and occlusion elimination of vertices
A polygon is drawn by connecting vertices and wires. In fact, this order is very important for clockwise or counterclockwise connections.
To say why, for example, if you want to draw a sphere or sphere, no matter where you take photos, it must be a ball. Besides, we can only see half of them. The same is true when the moon does not see the last half of the sphere. The parts other than the first half of the sphere are hidden.
The hidden part does not need to be drawn. If coordinates are calculated, the calculation is invalid. If the processing on the inside of the sphere is not executed, the amount of processing will be halved. In the 3D rendering world, what you don't see is the most common method to reduce the burden.
The Mechanism in it is called Occlusion Removal. Of course, OpenGL and WebGL can both be used to set Occlusion Removal. If Occlusion Removal is set, only the visible Polygon on the outside will be drawn, and all the Polygon on the inside will not be drawn.
However, try to think about how to judge the inside or outside of a polygon?
In fact, it is based on the connection sequence of the vertex just mentioned. The polygon connecting vertices Clockwise is on the outer side, while the polygon connecting counterclockwise is on the inner side. Therefore, pay special attention to the definition of vertex intelligence. If Occlusion Removal is set, there should be a polygon at a certain position, but it will not be drawn at all.
Summary
A vertex is any point in a three-dimensional space that contains at least coordinate intelligence. The three points are connected by a line and act as a polygon of a triangle. The polygon can be divided into the inner and outer sides based on the connection sequence of the vertex. Based on this, occlusion removal can be performed.
Next, the actual rendering starts with the definition of vertex intelligence. At this time, the sequence of vertices, Occlusion Removal, and other settings become very important, so we must thoroughly understand this article.
Next time, prepare the actual rendering environment.
Reprinted Please note: