- What is the difference between Gouraud and Phong shading?
- Gouraud shading (AKA Smooth Shading) is a per-vertex color computation. What this means is that the vertex shader must determine a color for each vertex and pass the color as an out variable to the fragment shader. Since this color is passed to the fragment shader as an in varying variable, it is interpolated across the fragments thus giving the smooth shading.
- In contrast, Phong shading is a per-fragment color computation. The vertex shader provides the normal and position data as out variables to the fragment shader. The fragment shader then interpolates these variables and computes the color.
- ??BSP tree
- 图形学复习4——光栅化画线画圆扫描线反走样算法
- Collisions
图形学复习
1 图形系统和模型
- 图形系统示意图:CPU、GPU、frame缓存、显示器
- 输入设备 —> 中央处理单元—>图形处理单元—> 帧缓存—> 输出单元
? | | {存储屏幕显示像素的颜色值,深度信息}
? CPU存储器 GPU存储器
- 输入设备 —> 中央处理单元—>图形处理单元—> 帧缓存—> 输出单元
- 处理器{获取由应用程序生成图元的属性,并为帧缓存像素赋值。即光栅化/扫描转换:几何实体-帧缓存中像素颜色和位置}
GPU{图形处理+并行性}
显示器{阴极射线管;逐行扫描,隔行扫描(60Hz每秒30次)}
- 虚拟照相机模型:什么叫COP、Projector、计算依据及实现理论
- Sample 2、2) A CG synthesized camera is normally located in space by the position of its viewpoint, its aim direction, and an up vector. If we let pc be the viewpoint, uc be the aim direction, and vup be the up vector, give the mathematics showing how to construct the view coordinate frame ux, uy, uz of the camera. (10 points)
- [4.3.3]pc viewpoint,vc aim direction
VPN=vc?pc
n=VPN/|VPN|
u=vup?n/|vup?n| //叉积、归一化生成与n、vup 均垂直的向量
v=n?u/|n?u| //vup 在照相机观察平面的投影
- [4.3.3]pc viewpoint,vc aim direction
- Sample 2、2) A CG synthesized camera is normally located in space by the position of its viewpoint, its aim direction, and an up vector. If we let pc be the viewpoint, uc be the aim direction, and vup be the up vector, give the mathematics showing how to construct the view coordinate frame ux, uy, uz of the camera. (10 points)
- COP投影中心、Projector投影线
- !虚拟照相机模型(synthetic-camera-model)中,虚拟成像平面与对象同侧
- Pipeline
- 顶点-顶点处理模块{执行坐标变换和计算每个顶点的颜色值}-裁剪模块和图元组装模块{顶点组装成像线段、多边形等图元,通过裁剪体对其裁剪}-光栅化模块{对每个图元生成一组片元,看作携带相关信息的潜在像素}-片元处理模块{更新帧缓存中像素}-像素
2 图形学编程
- 画图关键词 …_Line_Stripe/…
- GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP
- GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN
- 交互、event、idel…:补充程序
void main(){
glutInit(int argc, char *argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DPUBLE | GLUT_DEPTH);//双缓存,display中glFlush改glutSwapBuffers
...
glutIdleFunc(glutPostRedisplay);//空闲回调函数
//glutDisplayFunc(display);//回调函数并将其注册到窗口系统
glutMouseFunc(myMouse);
glutKeyboardFunc(mykey);//glutSpecialFunc(ListenKey);
glutMainLoop();//事件处理循环
}
vod myMouse(int button, int states, int x, int y){
if (button == GLUT_LEFT_BUTTON && states == GLUT_DOWN){
exit(0);
}
...
}
void myKey(unsigned char key, int x, int y){
if (key==‘q‘ || key = ‘Q‘){
exit(0);
}
...
}
3 几何对象和变换 ?
- 空间
- 向量空间(标量、向量)
- Euclid空间:向量空间+对大小或者距离的度量
- 仿射空间:向量空间+点;性质:凸性的表示
- 标架变换:b=(MT)?1a
- 向量的仿射变换仅9个自由度,点具有全部12个自由度
- 四元数:概念,如何表示旋转
- 包含向量(方向)和标量(旋转角度):(q0,q)
- ab=(p0q0?q`p,q0p+p0q,qXp)
- r=(cos(θ/2),sin(θ/2)v)
p′=rpr?1:p绕向量v旋转角度θ后的位置
- 各类矩阵及合成:平移缩放旋转剪切
- 平移、旋转:刚体变化,只改变对象的位置和方向
- 缩放:放射变换,改变大小,6个自由度:一个不动点+三个独立的缩放因子
100001000010αxαyαz1(平移)
cosθ0?sinθ00100sinθ0cosθ00001(旋转Ry)
cosθsinθ00?sinθcosθ0000100001(旋转Rz)
βx0000βy0000βz00001(缩放)
1000cotθ10000100001(错切)
注意Ry的正负!
- Sampel 4、Classify each of the following 2D homogeneous matrices as follows: (a) rotation, (b) mirror reflection, (c) uniform scale, (d) nonuniform scale, (e) translation, (f) shear, or (g) combination,and explain the effect of each matrix.
Maybe there is not a one-to-one mapping between the matrices and the categories, earlier categories take precedence over later categories if more than one applies. (14 points)
- 级联:从右往左
q=Mp, M=CBA => p->A->B->C
当前变换矩阵CTM(可设置成某个矩阵或用某个矩阵左乘、右乘
- M=T(p0)Rx(?θx)Ry(?θy)Rz(θ)Ry(θy)Rx(θx)T(?p0)
Rx(θx): az/d, ?ay/d
Ry(θy): d, ?ax
- eg: 绕经过原点和(1,2,3)的直线45度
关于x轴,az/d=3÷13 ̄ ̄ ̄√,
所以Rx(?θx)=Rx(?arccos(3÷13 ̄ ̄ ̄√))
关于y轴,d=13÷14 ̄ ̄ ̄ ̄ ̄ ̄ ̄√,
所以Ry(?θy)=Ry(arccos(13÷14 ̄ ̄ ̄ ̄ ̄ ̄ ̄√)) // 因为z轴朝外?
4 观察 ?
- Perspective意义
- 在应用领域生成比较自然的图像
- 注意:投影后尺寸会缩短
- 三点透视:沿主方向的平行线投影相交于有限远处的灭点;两点透视:一个主方向平行于投影平面;一点透视
- OpenGL关于两种变换的实现方式
- 模-视变换:应用旋转和平移改变,从而间接指定照相机方位
- 在对象标价下描述照相机的方向、指定投影变换矩阵来获得所需投影类型(规范化变换)
- 注意:使照相机朝着z轴正方向那面成像,且仍指向z轴负方向,T=…-d,d为正数
- 指定照相机方向:观察平面法向量VPN,观察正向向量VUP
v=vup?(vup`n÷(n`n))n, u=vXn
- 斜投影:N=MorthSTH,M裁剪,ST缩放和平移,H错切
- 透视投影:xp=x/(z/d), yp=y/(z/d), zp=z/(z/d)=d
P=NSH
- 隐藏面消除 8.9
5 光照和明暗绘制 ?
- 5.1-5.9 填空
- 光源和对象表明的颜色决定了帧缓存中一个或多个像素的颜色。对象的明暗值还依赖于它们表面的方向
- 光源:看作仅通过内部能量来源发射光线的对象。6个自变量的照明函数
- 镜面反射表面、漫反射表面、半透明表面
- Sample 5、The Blinn shading model is given by the expression: I =kd Id (L · n) + ks Is (h · n )r + ka Ia
Explain the meaning of all the terms (i.e., Kd, Ks, Ka, Id, Is, Ia, L, n, h, r) in this equation. Mention for each term if it is a scalar value, a geometric vector, or if it represents a color. (10 points)
- I=LR,光源*材质
- !Phong反射模型
- 环境光反射系数ka
- Lambert定律:只有入射光线的垂直分量才对照明起作用。l`n
- 镜面ks决定在入射的镜面反射光中有多大一部分被反射,指数α是高光系数,增加-反射的光线越集中于理想反射器的反射角附近。
- 反射角r=2(l`n)n?l
- 改进-h=l+v/|l+v|, (n`h)e′代替(r`v)e
- Phone着色:基于片元,离线
- 全局比局部多考虑什么
- 阴影、反射成像以及对光线的遮挡,都具有全局效应
- 光线跟踪:以虚拟照相机模型为基础;辐射度:基于能量守恒
6 从顶点到片元 ?
- 描述clipping算法,三维裁剪
- 裁剪:把位于视见体之外的对象删掉
- 隐藏面消除:就是确定可见对象(视见体之内,并且在视线方向没有被其他靠近视点的对象所遮挡的对象)的片元
- Cohen-Sutherland裁剪算法:端点编码
- Liang-Barsky裁剪算法:交点排序
- 以上两种均可扩散到三维,如Cohen-Sutherland改6位编码,Liang-Barsky的线段三维表示。即用平面去裁剪
- 光栅化:负责把颜色值赋给片元,且这些颜色是帧缓存中与这些片元对应的像素的颜色
- 多边形光栅化算法:Filling Polygons?,insight/outsight编码
- 线段扫描DDA:四舍五入计算,斜率 < 4,对x计算最佳y,斜率 > 4,则相反。
- !Bresenham算法:已知(i+1/2,j+1/2),则下一个点必为(i+3/2,j+1/2)或(i+3/2,j+3/2),利用a、b表示x=i+1/2处,距离上、下方候选像素的距离。d=a-b > 0,则选下方(i+3/2,j+1/2),否则上方。
法二:dk+1=dk?2dety(dk>0)或 ?2(dety?detx)
- 内外测试:相交测试/奇偶测试/环绕测试法
- 隐藏面消除:
- 章4
- 删除观察者看不到的表面
- 对象空间算法:试图对场景中的对象的表明排序,使得按照所排列的顺序来绘制表面
- 图像空间算法:试图确定每一条投影线与对象表明形成的所有交点之间的关系
- Z-Buffer算法:需要深度缓存/Z buffer。复杂度正比于光栅化生存的片元数目,并且和不进行隐藏面消除的多边形投影和显示过程相比,只增加很少运算量。对任何多边形的组合都有效。
- 背面剔除:只有对单个凸对象才能得到正确的图像。章6
- 本章
- 基于逐片元处理的模式
- 对象空间、图像空间,具体算法
- 扫描线填充
- 背面剔除
- cosθ>=0 或 n`v>=0,朝向观察者
- ax+by+cz+d=0 ,看c的符号
- 计算面积a=1/2∑i(yi+1+yy)(xi+1?xi),负值,背面多边性
- Z-Buffer 算法
- 工作在图像空间,但外层遍历多个多边形
- 二进制-深度分辨率
- 透视变换,非线性,可能导致数值上的不精确性,尤其是离裁剪面距离很小时
- 实现过程计算开销小,对每个多边形只计算一次
- 深度排序和画家算法
- 使用对象空间消隐算法来减少多边形的数量
- 循环重叠-分割
- 相互穿透-复杂求交
- Sample 3、This question concerns the following algorithms which address the hidden surface removal problem:
1). The binary space partitioning algorithm (BSP)
2). The Painter’s algorithm
3). Back facing polygon removal
4). Z-buffering
(a) Briefly describe the hidden surface removal problem. (3 points)隐藏面消除,即删除观察者看不到的表面
(b) Give the number (or numbers) of the relevant algorithms for the following questions (if none of the algorithms have the sated property, write ‘none’): (12 points)
Which algorithms
A. involve area subdivision? [1
B. require building a tree?[1
C. often use extra memory hardware?[4;1其实也可以算?
D. require significant preprocessing time?[2;13也需预处理
E. require knowing polygon orientations?[13
F. involve comparing pixel depths?[4
G. can be easily implemented in hardware?[4
H. which algorithm is clearly insufficient to solve the hidden surface removal problem?[13
- 反走样
- Sample 2、1)、Describe 3 aliasing artifacts present in Computer Graphics. Describe one method of antialiasing. (10 points)
- 由于帧缓存的离散特性-三个原因引起走样误差
- 存储像素数量固定,并且我们只能通过生成某种像素图案来近似表示一条线段,许多不同连续线段可能使用相同的像素图案来近似表示。给定某个像素序列,无法确定由哪条线段生成
- 像素固定放置在均匀的栅格上,无论把它放在何处都不能把它们放在等间隔分布的其他栅格位置上
- 像素具有固定的大小和形状
- 区域平均反走样技术:根据像素在理想直线上所占的面积比例来设置像素的亮度
- 也可以把Bresenham算法看做一种使用真实像素来尽速表示一个像素宽的理想直线的光栅化方法。
- 多重采样技术
- Z-Buffer算法:某个像素由三个多边形共享,则基于在像素中所占面积进行加权平均后赋给该像素
- 由于帧缓存的离散特性-三个原因引起走样误差
- Sample 2、1)、Describe 3 aliasing artifacts present in Computer Graphics. Describe one method of antialiasing. (10 points)
7 离散技术
- 7.5-7.6 纹理映射,OpenGL
- 周期性映射,走样尤为严重
- 两步映射:纹理-三维中间表面-绘制的对象表面(利用中间对象表面的法向量,对象表明的法向量,对象的中心)
- 线性滤波,GL_LINEAR代替GL_NEAREST,Mipmapping技术
- 7.12 采样与走样:频率大于真实的两倍采样,基本原理
- 采样-量化,重构,傅立叶变换
- 奈奎斯特采样定理:(一)当且仅当对连续函数的采样频率大于该函数最高频率的两倍时,改连续函数的理想采样值才包含原函数的所有信息。(二)我们可以从连续函数f(x)的采样点|fi|重构改连续函数
8 层级建模方法
- 8.1-8.5, 8.11
- 如何组织场景图
- 图元及构成的几何对象、灯光和虚拟照相机等
- group节点=压栈和出栈函数,属性和模-视变换矩阵
- CSG、四叉树、八叉树等结构、节点、边
- CSG:构造实体几何表示法
- 交并差
- 场景图和CSG树描述了对象各部分之间的层级关系
- BSP树:二叉空间区分树
- 划分平面和用于划分的顺序
- 改变观察者位置-改变遍历算法
- 缺点:用于划分多边形的平面可以具有任意方向,计算开销大
- 四叉树和八叉树
- 使用与坐标轴平行的划分平面或直线
- 减少存储图像所需的内存空间
- 可以按像素或体素划分空间,也可以把空间按对象进行划分
9 过程建模方法
- 了解 9.4:求解粒子系统方程,欧拉法:数值不稳定性-改进/二阶龙格-库塔法
- 9.7:树文法,如海龟图形系统、Hilbert曲线
- 9.8:递归方法和分形,几何尺寸和自相似性,lnk/lnn;中点划分及布朗运动
10 曲线和曲面
- 了解,无曲面
- 知道Bezier性质,表达方法:打印较为麻烦,见笔记
- Hermite插值:给定会算
11 高级绘制
- 11.1-11.3
- 掌握 Ray tracing:个人认为有编程
- 光线跟踪适合处理同时具有反射和折射属性的表面(反射模型计算对该交点的贡献,理想反射光方向投射,折射光线方向投射)-光线跟踪树
- 递归
- 程序
virtual double Intersection(Vector3f viewPoint, Vector3f l) {
double t = -1.0;
Vector3f diff = viewPoint - center;
// ray sphere intersection
// sphere: mag(x - c)^2 = r^2
// line: x = t*l + l0
// a*t^2 + b*t + c = 0
// t = -b+/-sqrt(b^2-4ac)/2a
double a = (l.abs())*(l.abs());
double b = 2*(l.dot(diff));
double c = ((diff.abs()*diff.abs())-(radius*radius));
double d = b*b-4*a*c;
if(d>0) {
double t1=(-b-sqrt(d))/(2*a);
double t2=(-b+sqrt(d))/(2*a);
// find closest, positive, interestion
if(t2<t1 && t2>0) {
t1=t2;
}
// positive?
if(t1>=0) {
t=t1;
}
}
return t;
}
virtual double Intersection(Vector3f viewPoint, Vector3f l) {
double t = -1;
// normal
Vector3f n = (a2-a1).cross(a3-a1);
// ray plane intersection
// plane: (p - p0) dot n = 0
// line: p = t*l + l0
// (t*l + l0 - p0) dot n = 0
t = -1.0*(((viewPoint-a1).dot(n))/(l.dot(n)));
if(t < 0) {
return -1;
}
// find point on plane
Vector3f p = viewPoint + (l*t);
// check if point is inside triangle
Vector3f v1 = (a1-p).cross(a2-p);
Vector3f v2 = (a2-p).cross(a3-p);
Vector3f v3 = (a3-p).cross(a1-p);
// if the dot product of all of the vectors is the same (should be 1 or -1 depending on triangle orientation)
// then all the vectors point in the same direction, and the point is inside the triangle.
// don‘t check equivalence becasue of numerical precision issues, use < or >
if((v1.dot(v2)<0)||(v2.dot(v3)<0)||(v3.dot(v1)<0)) {
return -1;
}
return t;
}
- Sample 6、
- (1) Implement a function intersectUnitSphere(p, d) that returns the t value of the first intersection of the ray with the sphere = 1, or the t value of the point which is closest to the sphere if there is no intersection. (15 points)
- (2) Give a procedure for intersecting a ray (returns the t value of the first intersection, or + if there is no intersection) with the surface defined by -1, in which (10 points)
100020001(M)
- 计算交点:
- 球面:(p?pc)`(p?pc)?r2=0
光线方程:p(t)=p0+td
=> d`dt2+2(p0?pc)`dt+(p0?pc)`(p0?pc)?r2=0
- 平面:p`n+c=0
=> t=?(p0`n+c)/(n`d)
- A sphere:
(x?a)2+(y?b)2+(z?c)2=r2
The ray-sphere intersection:
(xo+tu?a)2+(yo+tv?b)2+(zo+tw?c)2=r2
Rearrangement then gives:
(u2+v2+w2)t2+
2(u(xo?a)+v(yo?b)+w(zo?c))t+
(u2+v2+w2)t2+(xo?a)2+(yo?b)2+(zo?c)2?r2=0
i.e. a quadratic in t. If the quadratic has real roots then the ray intersects the sphere, otherwise it does not.
- 球面:(p?pc)`(p?pc)?r2=0
- 了解 subdivision、碰撞检测、picemand-based model?
- 了解CCD、包围盒类型、要求、特点
- 12.7 Bounding Boxes [Last Used: Fall 2000 Midterm]
Bounding boxes are one method of increasing the speed of a ray tracer. Typically, the boundingboxes are aligned with the coordinate axes.
- Discuss the benets/costs of axis aligned bounding boxes vs bounding boxes that are not axisaligned.
- Oriented Bounding Box (OBB): unaligned with the axis ,储存8 corners:xyz, Xyz, xYz, XYz, xyZ, XyZ, xYZ, XYZ 或者 点和三个法向量及长度,在随后的计算中比AABB复杂,但是准确,计算次数较少
- Axis Aligned Bounding Box (AABB) in World Space:axis aligned,储存8 corners:minimum、maximum。处理简单,但可能失去一些accuracy
- Discrete oriented polytopes (k-DOPs)
- Note: this bounding box data can be calculated just once when you first load / initialise your graphic entity and held as a member variable array in your class.
- Discuss the benets/costs of using bounding spheres instead of bounding boxes.
- Bounding boxes:线性约束,建立时计算量小(松弛边界)
bounding spheres:建立时计算量大(可以离线?),球与球的碰撞检测计算量小
- 取决于错误报告潜在碰撞(如果空较多)和准确性:看形状和大小来选择
- sphere collision detection is less costly than bounding box detection
- Bounding boxes:线性约束,建立时计算量小(松弛边界)
- Discuss the benets/costs of axis aligned bounding boxes vs bounding boxes that are not axisaligned.
其他
- Sample 2、3)、Name two color coordinate systems and describe their defining axes. For each system, indicate the shape of the region containing the colors they can define. (10 points)
- Sample 1、Answer the following questions. ( 6 points)
- 1) Which of the following statements about the homogeneous-coordinates representation is(are) correct? 齐次坐标
a) It can be used to differentiate 3D vectors and 3D points. 对
b) It enables the 4x4 matrix representation for all affine transformations.放射变换 对
c) (0, 1, 0, 1) and (0, 3, 0, 3) refers to two different 3D points. 错
d) Both of the orthographic and the perspective viewing may change the value of w component of a 3D point’s homogeneous coordinates. 正投影、透视投影 对
- 2) Local lighting computes the color or shade of each object independently. So it can’t deal with situations such as [acd]
a) Some objects are blocked from the light.
b) Real time illumination.
c) Light can reflect from object to object.
d) Some objects might be translucent. 半透明
- 3) Which one of the following gives the correct steps for the normalization of an orthogonal projection defined by glOrtho(left, right, bottom, top, near, far)? a
a) A translation first and a scaling next.
b) A rotation first and a scaling next.
c) A shear, a translation and a scaling in order.斜投影
d) A scaling, a translation and a shear in order.
- 1) Which of the following statements about the homogeneous-coordinates representation is(are) correct? 齐次坐标