- 计算机图形学:describes any use of computers to create and manipulate images
- 一般包括specific hardware, file formats, a graphic API
- 本书尽量避免依赖于任何特定硬件或API
- 本章内容:基础概念,历史背景,信息资源
Graphics Areas
major areas
-
Modeling: deals with the mathematical specification of shape and appearance properties in a way that can be stored on the computer.
-
Rendering: a term inherited from art and deals with the creation of shaded images from 3D computer models.
-
Animation: a technique to create an illusion of motion through sequences of images.
other areas (maybe not core areas)
-
User interaction: the interface between input devices to the user in imagery, and other sensory feedback.
-
Virtual reality: attempts to immerse the user into a 3D virtual world.
-
Visualization: attempts to give users insight into complex information via visual display.
-
Image processing: deals with the manipulation of 2D images, is used in both the fields of graphics and vision.
-
3D scanning: uses range-finding technology to create measured 3D models.
-
Computational photography: new ways of photographically capturing objects, scenes, and environments.
Major Applications
- Video games
- Cartoons
-
Visual effects: modern films, some not real characters
- Animated films
-
CAD/CAM: computer-aided design, computer-aided manufacturing
-
Simulation: can be thought of as accurate video gaming
-
Medical imaging: creates meaningful images of scanned patient data. 如computed tomography (CT)
- Information visualization
Graphic APIs
- API (application program interface): a standard collection of functions to perform a set of related operations
- graphics API: a set of functions that perform basic operation such as drawing images and 3D surfaces into windows on the screen
每个图形程序都需要两种API:
- a graphics API for visual output
- a user-interface API to get input from the user
目前的两种dominant paradigms for graphics and user-interface APIs:
- the integrated approach, 如Java, always fully standardized and supported as part of the language
- Direct3D and OpenGL, part of a software library tied to a language such as C++
Graphics Pipeline
- 3D graphics pipeline: a special software/hardware subsystem that efficiently draws 3D primitives(基本体) in perspective(透视)
- 处理前后透视关系采用z-buffer
- 图形管线中主要使用四维空间,4×4矩阵,4维向量——3 traditional geometric coordinates + a fourth homogeneous(齐次) coordinate (helps with perspective viewing)
- 大多数情况下,重要性排序:速度 > 质量
-
level of detail (LOD): fewer triangles are needed than when the model is viewed from a closer distance
Numerical Issues
曾经的数码处理非常混乱,直到出现了IEEE floating-point standrad,下面是一些比较重要的规则:
- 一些特殊值:正无穷(
∞
∞
)、负无穷(−∞)、不是个数(NaN)
- 有关这些特殊值的一些计算结果:
+a/(+∞)=+0
+
a
/
(
+
∞
)
=
+
0
−a/(+∞)=−0
−
a
/
(
+
∞
)
=
−
0
+a/(−∞)=−0
+
a
/
(
−
∞
)
=
−
0
−a/(−∞)=+0
−
a
/
(
−
∞
)
=
+
0
∞+∞=+∞
∞
+
∞
=
+
∞
∞−∞=NaN
∞
−
∞
=
N
a
N
∞×∞=∞
∞
×
∞
=
∞
∞/∞=NaN
∞
/
∞
=
N
a
N
∞/a=∞
∞
/
a
=
∞
∞/0=∞
∞
/
0
=
∞
0/0=NaN
0
/
0
=
N
a
N
- 一些bool判断规则
- all finite valid numbers <
+∞
+
∞
- all finite valid numbers >
−∞
−
∞
-
−∞<+∞
−
∞
<
+
∞
- any arithmetic expression that includes NaN results in NaN
- any boolean expression involving NaN is false
- 这些IEEE规则减少了很多条件判断和程序出错的频率
Efficiency
优化重点与当前哪项技术的发展较为落后有关,即优化方式是随着时代发展不断变化的。但仍然有reasonable approach to making code fast:
- Write the code in the most straightforward way possible. Compute intermediate(中间) results as needed on the fly(不工作?) rather than storing them.
- Compile in optimized mode.
- Use whatever profiling tools exist to find critical bottlenecks.
- Examine date structures to look for ways to improve locality. If possible, make data unit sizes match the catch/page size on the target arthitecture.
- If profiling reveals bottlenecks in numeric computations, examine the assembly code generated by the compiler for missed efficiencies. Rewrite source code to solve any problems you find.
最重要的其实是第一步,不能为了优化放弃代码的可读性和可扩展性。
Designing and Coding Graphics Programs
Class Design
- vector2
- vector3
-
hvector: a homogeneous vector with four components
- rgb
-
transform: a 4×4 matrix for transformations
-
image: a 2D array of RGB pixels with an output operation
Float vs. Double
- float: keeping memory use down and maintaining coherent memory access
- double: avoiding numerical problems
根据自己的项目决定~
Debugging Graphics Programs
很少使用traditional debuggers,因为找BUG效率太低,常用的方法有这些~:
-
The Scientific Method: create an image and observe what is wrong with it → develop a hypothesis(假设) about what is causing the problem and test it. 如,关闭环境光,看看变化~
-
Images as Coded Debugging Output: copy the value directly to the output image and skip the rest of the calculations that would normally be done. 如,直接把法线值copy到图片中输出
-
Using a Debugger: 图形学中debug难点是,每个操作都要重复很多遍(每个像素点一遍)。因此一种debug方法是,在找到问题所在位置后,加上特定的breakpoint,如~
if x = 126 and y = 247 then
print "blarg!"
-
Data Visualization for Debugging: 为自己设计好怎样显示数据能更有利于debug~
some annual conferences related to computer graphics:
- ACM SIGGRAPH
- SIGGRAPH Asia
- Graphics Interface
- the Game Developers Conference (GDC)
- Eurographics
- Pacific Graphics
- High Performance Graphics
- the Eurographics Symposium on Rendering
- IEEE VisWeek