08-3D Graphics and Rendering System
08-3D Graphics and Rendering System
1/30
Goals 2
2/30
Approaches to graphics rendering 3
• Ray-tracing approach
• Inverse-mapping approach: starts from pixels
• A ray is traced from the camera through each pixel
• Takes into account reflection, refraction, and diffraction in a multi-
resolution fashion
• High quality graphics but computationally expensive
• Not for real-time applications
• Pipeline approach
• Forward-mapping approach
• Used by OpenGL and DirectX
• State-based approach:
• Input is 2D or 3D data
• Output is frame buffer
• Modify state to modify functionality
• For real-time and interactive applications, especially games 3/30
Ray-tracing – Inverse mapping 4
4/30
Pipeline – Forward mapping 5
5/30
The general view (Transformations)
Modeling
Transformation
Lighting
Viewing
Transformation
Projection
Transformation
3D scene, Camera
Parameters, and Clipping
Framebuffer
light sources Viewport
Transformation Display
Rasterization
• Input:
• Geometric model
• Objects
• Light sources geometry and transformations
• Lighting model
• Description of light and object properties
• Camera model
• Eye position, viewing volume
• Viewport model
• Pixel grid onto which the view window is mapped
• Output:
• Colors suitable for framebuffer display
7/30
Graphics pipeline 8
• What is it?
The nature of the processing steps to display a computer graphic and the
order in which they must occur.
• Primitives are processed in a series of stages
• Each stage forwards its result on to the next stage
• The pipeline can be drawn and implemented in different ways
• Some stages may be in hardware, others in software
• Optimizations and additional programmability are available at some
stages
• Two ways of viewing the pipeline:
• Transformation perspective
• Operation perspective
8/30
Modeling transformation 9
Modeling • 3D models defined in their own coordinate
Transformation system (object space)
Lighting • Modeling transforms orient the models
Viewing within a common coordinate frame (world
Transformation space)
Projection
Transformation
Clipping
Viewport
Transformation
World space
Rasterization Object space
9/30
Lighting (shading) 10
Modeling • Vertices lit (shaded) according to material
Transformation properties, surface properties (normal) and
Lighting light sources
Viewing • Local lighting model (Diffuse, Ambient,
Transformation Phong, etc.)
Projection
Transformation
Clipping
Viewport
Transformation
Rasterization
10/30
Lighting Simulation 11
• Direct illumination
• Ray casting
• Polygon shading
• Global illumination
• Ray tracing
• Monte Carlo methods
• Radiosity methods
11/30
12
12/30
13
13/30
14
14/30
15
15/30
Viewing transformation 16
Modeling • It maps world space to eye (camera) space
Transformation • Viewing position is transformed to origin and
Lighting viewing direction is oriented along some axis
(usually z)
Viewing
Transformation
Projection
Transformation
Clipping
Viewport
Transformation
Rasterization
16/30
17
17/30
Projection transformation
(Perspective/Orthogonal) 18
Modeling • Specify the view volume that will
Transformation ultimately be visible to the camera
Lighting • Two clipping planes are used: near plane
Viewing and far plane
Transformation
• Usually perspective or orthogonal
Projection
Transformation
Clipping
Viewport
Transformation
Rasterization
18/30
19
19/30
Clipping 20
Modeling • The view volume is transformed into
Transformation standard cube that extends from -1 to 1 to
Lighting produce Normalized Device Coordinates.
Viewing • Portions of the object outside the NDC cube
Transformation are removed (clipped)
Projection
Transformation
Clipping
Viewport
Transformation
Rasterization
20/30
Why clip? 21
21/30
What is clipping? 22
22/30
Clipping 23
23/30
Trivial Accepts 24
24/30
Trivial Rejects 25
25/30
Clipping Lines To Viewport 26
26/30
Clipping Lines To Viewport 27
27/30
Others Line clipping algorithms 28
• Cohen–Sutherland
• Liang–Barsky
• Cyrus–Beck
• Nicholl–Lee–Nicholl
• Fast clipping
• O(lg N) algorithm
• Skala
• What is the best? What is the differences?
28/30
Clipping Polygons 29
29/30
Why Is Clipping Hard? 30
30/30
How many sides? 31
• Seven……..
31/30
Why Is Clipping Hard? 32
32/30
Why Is Clipping Hard? 33
• Basic idea:
• Consider each edge of the view window
individually
• Clip the polygon against the view window
edge’s
equation
34/30
35
35/30
Sutherland-Hodgman Clipping 36
36/30
Sutherland-Hodgman Clipping 37
37/30
Sutherland-Hodgman Clipping 38
38/30
Sutherland-Hodgman Clipping 39
• Four cases:
• s inside plane and p inside plane
• Add p to output
• Note: s has already been added
• s inside plane and p outside plane
• Find intersection point i
• Add i to output
• s outside plane and p outside plane
• Add nothing
• s outside plane and p inside plane
• Find intersection point i
• Add i to output, followed by p
39/30
Point-to-Plane test 40
40/30
Finding Line-Plane Intersections 41
(L (t) - q) • n = 0
(L0 + (L1 - L0) t - q) • n = 0
t = [(q - L0) • n] / [(L1 - L0) • n]
• The intersection point i = L(t) for this value of t
41/30
Viewport Transformation 42
Modeling
Transformation
• Maps NDC to 3D viewport:
• xy gives the screen window
Lighting • z gives the depth of each point
Viewing
Transformation
Projection
Transformation
Clipping
Viewport
Transformation
Rasterization
42/30
Rasterization 43
Modeling • Rasterizes objects into pixels
Transformation
• Interpolate values as we go (color, depth, etc.)
Lighting
Viewing
Transformation
Projection
Transformation
Clipping
Viewport
Transformation
Rasterization
43/30
Summary of transformations 44
44/30
Recap: Rendering Pipeline 45
• Modeling transformations
• Viewing transformations
• Projection transformations
• Clipping
• Scan conversion
• We now know everything about how to draw
a polygon on the screen, except visible surface
determination
45/30
Invisible Primitives 46
46/30
View Frustum Clipping 47
47/30
Back-Face Culling 48
48/30
Back-Face Culling 49
49/30
Back-Face Culling 50
50/30
Occlusion 51
51/30