Computer graphics rasterization

Rasterization

Rasterization task

Display the regular cube obtained in the projection transformation on the screen

Screen

  • A collection of pixels.

  • The size of the screen is characterized by resolution.

  • Classic raster display device

Pixel

  • The pixel is a small cube with a uniform color

  • The color is composed of three parts: red, green, blue

Screen space

​ The screen is divided into cubes, called pixels. Pixel use coordinates (x, y) (x, y)(x,y ) , the center is(x + 0.5, y + 0.5) (x+0.5, y+0.5)(x+0.5,Y+0 . . 5 ) , the range of(0, 0) (0,0)(0,0) ( w i d t h − 1 , h e i g h t − 1 ) (width-1,height-1) (width1,height1)

Rasterization steps

Rasterization is mainly divided into two steps

  1. X, YX, Y of the regular cubeX,The Y- axis coordinate is transformed to[0, width] × [0, height] [0,width]\times[0,height][0,width]×[0,height]
  2. Draw the resulting graphics on the screen pixels.

The first step of rasterization viewport transformation viewport transformation

First zoom and then pan. The transformation process has nothing to do with z. The transformation matrix is ​​shown below.
(width 2 0 0 width 2 0 height 2 0 height 2 0 0 1 0 0 0 0 1) \begin{pmatrix} \frac{width}{2} & 0 & 0 & \frac{width}{2}\\ 0 & \frac{height}{2} & 0 & \frac{height}{2}\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1 \end{pmatrix}2width00002height0000102width2height01

Rasterization The second step is to rasterize triangles to pixels

The problem of concern here is how to display continuous triangular planes in discrete pixels.

The simplest rasterization method: solve by sampling, sample the pixels whose pixel center is inside the triangle, and then use these sampled pixels to represent the triangle.

Here, the judgment point PPThe method of P inside a triangle uses a cross product. First, it specifies a direction, such asAAA-> B B B-> C C C , and then calculate 3 cross products in turn according to the trend, as shown below
a ⃗ = AP ⃗ × AB ⃗ b ⃗ = BP ⃗ × BC ⃗ c ⃗ = CP ⃗ × CA ⃗ \vec{a}=\vec{AP }\times\vec{AB}\\ \vec{b}=\vec{BP}\times\vec{BC}\\ ​​\vec{c}=\vec{CP}\times\vec{CA}a =A P ×A B b =BP ×BC c =CP ×C A
If PPP is inside the triangle, thena ⃗, b ⃗, c ⃗ \vec{a},\vec{b},\vec{c}a ,b ,c In the same direction.

But sampling will bring new problems-aliasing, these problems are called sampling artifacts, for example

  • Jaggies are caused by insufficient spatial sampling.

  • Moire is caused by insufficient image sampling.

  • Wagon wheel effect, caused by insufficient time sampling.

The method to solve the above problems-anti-aliasing, the basic idea is to perform a pre-filter before sampling, and then sample again. The blurring process actually uses a low-pass filter to filter out high-frequency parts before sampling, with the purpose of blurring the edges.

The actual method is to use supersampling MSAA. The basic idea is to subdivide a pixel into multiple small parts for sampling, and then the value of each pixel is the average of all the small parts in the pixel.

Guess you like

Origin blog.csdn.net/NelsonCheung/article/details/109088231