Hidden Surface Removal & Antialiasing¶
Hidden Surface Removal¶
Related OpenGL Functions¶
glEnable/ glDisable(GL_CULL_FACE);
glCullFace(mode);
glutInitDisplayMode(...| GLUT_DEPTH);
glEnable(GL_DEPTH_TEST);
Visible Surface Determination¶
-
Goal
- Given: a set of 3D objects and view specification
- Determine: those parts of the objects that are visible when viewed along the direction of projection
-
Approaches: object space algorithm and image space algorithm
-
Object Precision Algorithm
for (each object in the world) {
determine the parts of the object whose view is unobstructed by other parts or any other object;
draw those parts;
}
- Image Precision Algorithm

-
Back-face Culling: elimination of back-faces
- 在封闭多边形表面 like surface of a polyhedral volume or a solid polyhedron 很显然地我们看不到背面的部分
- back face: part of the object surface facing away from the eye
-
Algorithm
- 找到eye-vector/normal和面之间的角度
- 如果这个角度在0°~90°,则为背面,剔除
-
处理不了的情况:
-
Painter's Algorithm: draw back to front
- Failure case: 排不出序
-
Warnock's Area Subdivision
- Start with whole image
- If one of the easy cases is satisfied, draw what's in front
- front polygon covers the whole window or
- there is at most one polygon in the window.
- Otherwise, subdivide region into 4 windows and repeat
- If region is single pixel, choose surface with smallest depth
- Advantages:
- No over-rendering 不会重复绘制
- Anti-aliases well. Go deeper to get sub-pixel information
- Disadvantages: 不同情况运行效率差距大
- Tests are quite complex and slow
- Not amenable for hardware implementation 不适合做硬件实现
-
Z-buffer Algorithm
- 除了一个frame buffer存color值,还需要一个一样size的z-buffer存储depth(z) value
- Code
for ( j=0; j<SCREEN HEIGHT; j++ ) for ( i=0; i<SCREEN WIDTH; i++ ) { WriteToFrameBuffer(i, j, BackgroundColor); WriteToZBuffer(i, j, MAX); } for ( each polygon ) for ( each pixel in polygon's projection ) { z = polygon's z value at (i, j) ; if( z< ReadFromZBuffer(i, j) ) { WriteToFrameBuffer(i, j, polygon's color at (i, j)); WriteToZBuffer(i, j, z); } }
- Related OpenGL Functions
-
BSP Tree: 对画家算法很有效,帮助找到前后顺序。树可以预先计算
-
Very efficient for a static group of 3D polygons as seen from an arbitrary viewpoint
-
Correct order for Painter's algorithm is determined by a traversal of the binary tree of polygons
-
Pros
- simple, elegant scheme
- only write to framebuffer
-
Cons
- 需要较为繁琐的预处理过程,适用于静态场景
- splitting会增大场景中多边形数量
-
-
k-d Tree
-
Ray Casting
Aliasing¶
- Aliasing是由于display设备的离散性,如用一些有限性采样连续信号,如果采样不充分,信息就会丢失
- 影响:jagged edges(锯齿), incorrectly rendered fine details, small objects might miss(有些细节没采样到)

Anti-aliasing¶
- Super-sampling:增加采样率
- 低通滤波:滤去高频部分
- Area sampling: Intensity of the boundary pixels is adjusted depending on the percent of the pixel area covered by the primitive.