Rasterization (triangle) (notes)


One, rasterization

Screen : An array of pixels. The size of the array is called resolution. The screen is a typical raster imaging device (Raster Display).

Pixel : Insert picture description herePixel is the abbreviation of "Picture Element". According to the current understanding, a pixel refers to a small square with a specific color. The color is a mixture of RGB (red, green, blue). The index/coordinate of the pixel is expressed in (x, y) form, and both x and y are integer numbers. The coordinates of the pixel are from (0, 0) to (width-1, height-1). The center of the pixel is on (x + 0.5, y + 0.5). The screen coverage width is (0, 0) to (width, height).

Rasterization :
Insert picture description here
The process of "painting" things on the screen. To be precise, the process of mapping a standard cube to the screen (Canomical Cube to Screen).

Standard cube to screen : Insert picture description here
Ignore the z-axis, transform [-1, 1] of xy to [0, width] x [0, height]. The above is the conversion matrix.

2. Popularization of Raster Display Equipment

Oscilloscope :
Insert picture description here

Cathode Ray Tube (CRT) : The
Insert picture description here
electron flow is shot on the screen and the image is changed by shifting the electron flow.

Flat panel display devices :
Insert picture description here
LCD, OLED, retina screen. . .

LCD (Liquid Crystal Display) :
Insert picture description here
Liquid crystal display uses the principle of liquid crystal to achieve a display effect. The liquid crystal can affect the polarization direction of light according to different arrangements.

LED (Light Emitting Diode) Array Display :
Insert picture description here
LED array display.

Electrophoretic (Electronic Ink) Display :
Insert picture description here
Electronic ink screen can only display black and white. By controlling the position of the electronics to display, the refresh rate is very low. But it has a display effect close to that of a paper book.

Frame buffer :
Insert picture description here
the memory of the raster display device.

Three, the basic original shape-triangles (Triangles)

The characteristics of triangles : A
Insert picture description here
triangle is the most basic polygon, and any polygon can be split into triangles.
The triangle must be on a plane, and the inside and outside of the triangle are clearly defined. The points inside the triangle are well interpolated.

Four, sampling method (Sampling)

Sampling :
Insert picture description here
Give you a continuous function, and then get the function value in different places is called sampling. In a more professional way, sampling is the process of discretizing a continuous function.
Sampling is a core concept in graphics,

2D triangle sampling steps :
Insert picture description here
Now there is a triangle, we need to determine whether the pixel center is within the triangle.
Insert picture description here
In the computer, we define an Inside function.
Insert picture description here
Sampling is to determine whether the return value of the function at the center of different pixels is 1 or 0 (of course, 1 means there is color, and 0 means no color).

Inside calculation process :
Insert picture description here
Looking back at the notes when learning the cross product, when Q is on the same side of the three vectors, the point Q is inside the triangle surrounded by the three vectors.
Insert picture description here

When the center of the pixel is just on the line, either no processing or special processing is performed. We will not deal with it here. But some graphics APIs have their own rules.

Bounding Box :
Insert picture description here
When we rasterize an element (such as a triangle), using a bounding box can effectively avoid us from checking all pixels of the entire screen.
The bounding box area can be easily obtained by the coordinates of P0, P1, and P2. Pixels not in the bounding box area do not participate in sampling inspection.

Incremental Triangle Traversal :
Insert picture description here
An optimization method that only finds the leftmost and rightmost of the triangle in each row, so that a single pixel is not considered. Very suitable for handling very narrow and rotated triangles.

The end of the course

Insert picture description here
Insert picture description here

There are jaggies on this picture, that is, aliasing occurs when our sampling rate is not high (Aliasing)
Insert picture description here
The content of the next lesson is anti-aliasing/anti-aliasing.

Guess you like

Origin blog.csdn.net/qq_37856544/article/details/113057809