GAMES101现代计算机图形学入门
以下为笔者学习GAMES101过程中的笔记,包含了从几何变换到光栅化的内容。
Overview
Computer graphics:The use of computers to synthesize and manipulate visual information.
Course Topics (mainly 4 parts)
- Rasterization
- Curves and Meshes
- Ray Tracing
- Animation/Simulation
即光栅化成像,几何表示,光的传播理论,动画与模拟
光栅化(Rasterization)指的是将三维图形实时显示在二维平面上。在图形学中,30 FPS 就可以认为是实时的,低于这个帧率的则认为是离线渲染。
光线追踪(Ray tracing)指的是像每一个像素发射光,令光线不断反射。这样的技术能够让渲染更加真实,但是效率会更低。使用光线追踪是效果和效率的 Trade-off。
从二维图像和三维模型的角度出发,我们认为一切以三维模型为起点的都是计算机图形学(Computer graphics)的范畴,而所有从二维图像为起点的都是计算机视觉(Computer vision)。特别的,从三维模型出发获得二维图像的称为渲染(Rendering),从三维模型出发获得新的三维模型的可以是模拟(Simulation)。但是上述的分类也是粗糙而模糊的。

Transformation
几何变换(translate——位移,transform——转换)
基础知识: 线性代数,向量和矩阵的基本运算
(向量的叉乘可通过矩阵形式表示,如下图)

2D Transformations
Representing transformations using matrices
-
Scale Matrix:
-
Reflection Matrix:
-
Shear Matrix:
-
Rotation Matrix:
旋转矩阵是正交矩阵,想求逆直接求其转置
- Linear Transforms = Matrices(of the same dimension)
- Translation cannot be represented in matrix form(So, translation is Not linear transform!)
Affine map = linear map + translation
Using homogenous coordinates:
3D Transformations
Use matrices for affine transformations

(注意绕y轴旋转的矩阵较为特殊,原因是:)
Rotation by angle around axis
(默认为过原点的单位向量)
推导过程如下: (其中)

Viewing Transformation
View/Cemera Transformation
-
What is view transformation?
-
Think about how to take a photo
- Find a good place and arrange people (model transformation)
- Find a good “angle” to put the camera (view transformation)
- Cheese! (projection transformation)
(三个变换过程)
(为了计算方便,把观测点移到原点并通过旋转和坐标轴对齐,再对物体进行同样的变换,保证相对位置不变;
求旋转矩阵的方法:先求出逆变换,再转置)

-
Projection in Computer Graphics
- 3D to 2D
- Orthographic projection
- In general, we want to map a cuboid to the “canonical (正则、规范、标准)” cube
- Perspective projection


如何推导? 变换满足条件: 所有点的x和y坐标上原来的倍,同时近平面上坐标全部不变,远平面上z坐标不变,且中心点坐标不变

Rasterization
- Rasterizing one triangle
- Sampling theory
- Antialiasing
What’s after MVP ? 将所得的模型输出到屏幕上

- Irrelevant to z
- Transform in xy plane: to
- Viewport transform matrix:
Triangles—Fundamental Shape Primitives
Rasterizing Triangles into Pixels 判断点在三角形内的方法:向量叉乘(对边界情况不做处理) 简化计算: Use a Bounding Box! http://www.sunshine2k.de/coding/java/TriangleRasterization/TriangleRasterization.html#algo1
Sampling Artifacts(Errors/ Mistakes/ Inaccuracies) in Computer Graphics Signals are changing too fast (high frequency), but sampled too slowly
Antialiasing Idea: Blurring (Pre-Filtering) Before Sampling 采样之前进行模糊处理 (出现锯齿的本质原因是信号变换太快而采样速度跟不上,通过模糊的方法降低频率,从而保证采样率能跟上) Filtering = Getting rid of certain frequency contents = Convolution(= Averaging) Convolution in the spatial domain is equal to multiplication in the frequency domain, and vice versa
How Can We Reduce Aliasing Error? Option 1: Increase sampling rate
- Essentially increasing the distance between replicas in the Fourier domain
- Higher resolution displays, sensors, framebuffers…
- But: costly & may need very high resolution Option 2: Antialiasing
- Making Fourier contents “narrower” before repeating
- i.e. Filtering out high frequencies before sampling
Antialiasing by Computing Average Pixel Value Antialiasing By Supersampling (MSAA) 对一个像素点采样更多次,取平均值
Visibility / occlusion
- Z-buffering Idea:
- Store current min. z-value for each sample (pixel)
- Needs an additional buffer for depth values
- frame buffer stores color values
- depth buffer (z-buffer) stores depth
For simplicity we suppose z is always positve(smaller z -> closer, larger z -> further)

Shading
The process of applying a material to an object.
- Illumination & Shading
- Graphics Pipeline
-
Blinn-Phong reflflectance model
- Diffuse
- Specular
- Ambient
-
At a specifific shading point
-
Shading frequencies
-
Graphics pipeline
-
Texture mapping
-
Barycentric coordinates
(实际上允许使用视角向量和镜面反射向量的接近程度来计算高光,而这种计算方式就称为 Phong 模型,Phong模型与Bling-Phong模型产生的高光效果不一样,Bling-Phong产生的高光更加柔和。)

Shading Frequencies:
Shade each triangle (flat shading)
- Triangle face is flat — one normal vector
- Not good for smooth surfaces Shade each vertex (Gouraud shading)
- Interpolate colors from vertices across triangle
- Each vertex has a normal vector (how?) Shade each pixel (Phong shading)
- Interpolate normal vectors across each triangle
- Compute full shading model at each pixel
- Not the Blinn-Phong Reflectance Model
Graphics (Real-time Rendering) Pipeline
Shader Programs
- Program vertex and fragment processing stages
- Describe operation on a single vertex (or fragment)
Texture Mapping Visualization of Texture Coordinates Each triangle vertex is assigned a texture coordinate (u,v)
Interpolation Across Triangles: Barycentric Coordinates Interpolation Across Triangles Why do we want to interpolate?
- Specify values at vertices
- Obtain smoothly varying values across triangles What do we want to interpolate?
- Texture coordinates, colors, normal vectors, … How do we interpolate?
- Barycentric coordinates

Applying Textures
一个像素,在近处覆盖的区域小,在远处覆盖的区域大
Texture Magnification
(What if the texture is too small?)
Bilinear Interpolation
Super-sampling: costly, signal frequency too large in a pixel 大量采样取平均值->不采样,直接范围查询 Mipmap
只能做近似的正方形范围查询
Overblur
一个像素映射到纹理上的形状可能不是正方形
使用各向异性过滤解决矩形插值

