An Introduction to Computer Graphics
Joaquim Madeira
Beatriz Sousa Santos
Universidade de Aveiro
L ë 1 Computer Graphics
¢ The technology with which pictures, in the broadest sense of the word, are ß Captured or generated, and presented ß Manipulated and / or processed ß Merged with other, non-graphical application data
¢ It includes: ß Integration with other kinds of data – Multimedia ß Advanced dialogue and interactive technologies
[CG Topics – Darmstadt]
2 Computer Graphics
¢ Computer Graphics deals with all aspects of creating images with a computer ß Hardware ß Software ß Applications
[Angel]
3 Computer Graphics: 1950 – 1960
¢ Earliest days of computing ß Pen plotters ß Simple calligraphic displays
¢ Issues ß Cost of display refresh ß Slow, unreliable, expensive computers
4 Computer Graphics: 1960 – 1970
¢ Wireframe graphics ß Draw only lines !
[Angel]
5 Computer Graphics: 1960 – 1970
¢ Ivan Sutherland’s Sketchpad ß PhD thesis at MIT (1963) ß Man-machine interaction ß Processing loop ¢ Display something ¢ Wait for user input ¢ Generate new display
[http://history-computer.com]
6 Computer Graphics: 1970 – 1980
¢ Raster graphics ß Allows drawing polygons
¢ First graphics standards
¢ Workstations and PCs
7 Raster graphics
¢ Image produced as an array (the raster) of picture elements (pixels) in the frame buffer
[Angel]
8 Raster graphics
¢ Drawing polygons
¢ Illumination models
¢ Shading methods
[Angel]
9 Computer Graphics: 1980 – 1990
¢ The quest for realism
Smooth shading Environment mapping Bump mapping
[Angel]
10 Computer Graphics: 1980 – 1990
¢ Special purpose hardware
¢ Industry-based standards ß PHIGS ß RenderMan http://renderman.pixar.com/view/future-of-renderman
¢ Human-Computer Interaction
11 Computer Graphics: 1990 – 2000
¢ OpenGL API
¢ First successful computer-generated feature- length animation film: Toy Story
¢ New hardware capabilities
12 Computer Graphics: 2000 – …
¢ Photorealism
¢ Graphics cards for PCs dominate the market ß Nvidia ß ATI
¢ Game boxes / players determine the market
¢ CG is routine in the film industry
13 Gouraud shading – 1971
[Wikipedia]
14 Gouraud shading
Poor highlight Very high polygon count
http://en.wikipedia.org/wiki/Gouraud_shading
15 Phong shading– 1973
[Wikipedia]
16 Phong reflection model – 1973
[Wikipedia]
17 Can you see the differences ?
18 Ray-Tracing example
http://radsite.lbl.gov/radiance/book/img/plate10.jpg
19 “Vermeer’s Studio”
Wallace & Cohen, 1987: Radiosity and Ray-Tracing
20 Another Ray-Tracing example
http://www.tjhsst.edu/~dhyatt/superap/samplex.jpg
21 Radiosity
Without radiosity With radiosity
[Burdea]
Smooth shading Environment mapping Bump mapping
[Angel]
23 Textures – Simulating Ray-Tracing
[http://www.okino.com]
¢ Increased realism !! ß 11 light sources + 25 texture maps
24 CG – Application areas
¢ Entertainment ß Computer games ß Animation films ß Special effects ¢ Engineering / Architecture ß Computer-Aided Design (CAD) ß Data Visualization ¢ Medicine ß Visualization ¢ …
25 Games – Lara Croft
1996 2007 2013
[Wikipedia] 26 Animation films – Pixar
Toy Story – 1995 Ratatouille – 2007 Toy Story – 2014
[www.pixar.com]
27 Animation films – Pixar
Toy Story 3 – 2010 Brave – 2012 [www.pixar.com]
28 Special effects – ILM
1991 1994 1999
[Wikipedia]
29 Special effects – ILM
2005 2009 2013 [Wikipedia]
30 Computer-Aided Design
CAD mockup
[Wikipedia]
31 CAD – Simulation
[Wikipedia]
32 Visualization
¢ Techniques / tools for creating ß Images ß Diagrams ß Animations ß …
¢ Aims ß Convey a message – Static Visualization ! ß Allow interactive exploration / analysis
33 Virtual and Augmented Reality Virtual Reality – examples Industry
Jaguar/ Land Rover
http://www.youtube.com/watch?v=j3qcnvgVlNk 35 http://www.youtube.com/watch?v=CMU0HtmBt48
36 Medicine
http://www.youtube.com/ watch?v=zJmrcEM-uvA
37 Entertainment
Oculus Rift 2014; ~300 USD
http://www.oculusvr.com/
http://www.youtube.com/watch?v=N8uuDT53A8 Yts CG is not alone… Visualization
¢ Core areas: IP HCI ß CG, IP, CV and HCI CG CV ¢ Satellite areas: Geometric ß Geometric Modeling Modeling ß Data and Information Visualization ¢ What is common? ß CG, IP : image file formats, color models, … ß CG, CV : 3D model representations, … ß IP, CV : noise removal, filters, …
39 CG is not alone… Visualization
IP ¢ Geometric Modeling CG HCI ß CV : 3D scanning CV
ß CG : 2D and 3D models Geometric Modeling ß HCI : interaction techniques
¢ Visualization ß HCI : interaction techniques ß GeoM : 2D and 3D models ß CG : rendering
40 Example – Medical Imaging
¢ Processing pipeline ß Noise removal ß Segmentation ß Generating 2D / 3D models ß Data visualization ß User interaction ß …
[www.mevislab.de]
RVA - 2014/2015 41 CG Main Tasks
¢ Modeling ß Construct individual models / objects ß Assemble them into a 2D or 3D scene
¢ Animation ß Static vs. dynamic scenes ß Movement and / or deformation
¢ Rendering ß Generate final images ß Where is the observer? ß How is he / she looking at the scene?
42 Basic Graphics System
[Angel]
¢ Image formed in the frame buffer
43 Computer Graphics APIs
¢ Create 2D / 3D scenes from simple primitives
¢ OpenGL ß Rendering ß No modeling or interaction facilities
¢ Direct 3D – Microsoft
¢ VTK ß 3D CG + Image processing + Visualization
¢ …
44 API contents
¢ Functions for specifying / instantiating ß Geometric primitives ß Viewer / Camera ß Light sources ß Materials ß …
¢ Functions for simple user interaction ß Input from devices: mouse, keyboard, etc.
45 Geometric Primitives
¢ Simple primitives ß Points ß Line segments ß Polygons
¢ Geometric primitives ß Parametric curves / surfaces ß Cubes, spheres, cylinders, etc.
46 Camera specification
¢ Six degrees of freedom ß Position of lens center
¢ Lens
¢ Film size
¢ Orientation of film plane
[Angel]
47 Lights and materials
¢ Types of light sources ß Point vs distributed light sources ß Spot lights ß Near and far sources ß Color properties
¢ Material properties ß Absorption: color properties ß Scattering: diffuse and specular ß Transparency
48 OpenGL
¢ Multi-platform API for rendering 2D and 3D computer graphics
¢ Interaction with the GPU to achieve hardware-accelerated rendering
¢ Application areas ß CAD ß Virtual reality ß Scientific and Information Visualization ß …
49 OpenGL
¢ OpenGL ES ß Subset for use in embedded systems and portable devices
¢ WebGL ß JavaScript API based on OpenGL ES 2.0 ß Rendering interactive 2D and 3D graphics on any compatible browser, without the use of plug-ins
50 OpenGL Primitives
¢ Set of points
ß GL_POINTS
ß Point coordinates ß Color ß Marker size ß Marker shape
51 OpenGL Primitives
¢ Line segments
ß GL_LINES
ß GL_LINE_STRIP and GL_LINE_LOOP
ß Vertex coordinates ß Color ß Width ß Stipple
52 OpenGL Primitives
¢ Triangles
ß GL_TRIANGLES ß GL_TRIANGLE_STRIP + GL_TRIANGLE_FAN
ß Fill color and edge color ß Drawing mode
¢ General Polygons
ß Define as sets of triangles
53 OpenGL Primitives
[OpenGL – The Red Book]
54 2D Visualization
¢ Define a 2D scene in the world coordinate system
¢ Select a clipping window in the XOY plane ß The window contents will be displayed
¢ Select a viewport in the display ß The viewport displays the contents of the clipping window
55 2D Visualization
56 Clipping W indow to Viewport Mapping
57 Coordinate mapping
58 OpenGL
¢ Default definitions are mostly used!
¢ Square clipping window ß Corners: (-1, -1) and (+1, +1)
¢ Viewport occupies the whole display window
¢ Changes can be made: ß The viewport might occupy only part of the display window ß The clipping window can be larger or smaller
¢ Pay attention to the aspect ratios!
59 Basic 2D Transformations
p = (x, y) ‰ original point
p’ = (x’, y’) ‰ transformed point
• Basic transformations: Vector notation
- Translation Note: Some older books and libraries use a different notation: :each point is represented by a - Scaling line matrix P = [ x y ]
- Rotation
60 Translation
• It is a rigid body transformation (it does not deform the object)
• To apply a translation to a line segment we need only to transform the end points
• To apply a translation to a polygon we need only to transform the vertices
61 Translation
• It is necessary to specify translations in x and y
transformation matrix Rotation
• To apply a rotation we need to specify:
- a point (center of rotation)
(xr,yr)
- A rotation angle (positive - counter-clockwise)
Positive rotation
63 Rotation around the origin
• The simplest case: x’= r cos ( + ) = r cos cos – r sin sin y’= r sin ( + ) = r cos sin + r sin cos
Polar coordenates of the original point: x = r cos r sin ( + ) y = r sin
Replacing:
x’ = x cos – y sin y´ = x sin + y cos r cos ( + )
64 Scaling
• Modifies the size of an object; we need to specify scaling
factors: sx and sy
x’ = x . sx y’ = y . sy
Trasformation matrix Transforming a square into a larger square applying a P’ = S . P scaling sx=2, sy=2 2D Transformations
¢ Matrix representation ß Homogeneous coordinates !! ß Concatenation = Matrix products
¢ Complex transformations ? ß Decompose into a sequence of basic transformations
66 Homogeneous coordinates
• Most applications involve sequences of transformations
• For instance:
- visualization transformations involve a sequence of translations and rotations to render an image of a scene
- animations may imply that an object is rotated and translated between two consecutive frames
• Homogeneous coordinates provide an efficient way to represent and apply sequences of transformations
67 ¢ It is possible to combine in a matrix the multiplying and additive terms if we use 3x3 matrices
¢ All transformations may be represented by multiplying matrices
¢ Each point is now represented by 3 coordinates
( x, y ) ‰ (xh, yh, h),h = 0
x = xh / h y = yh / h
( x.h, y.h, h)
68 2D Translation
69 2D Rotation r sin ( + )
r cos ( + )
70 2D Scaling
71 Concatenation
72 Concatenation
73 Arbitrary Rotation
Translation + Rotation + Inverse Translation
74 Arbitrary Scaling
Translation + Scaling + Inverse Translation
75 Order is important !
76 3D Transformations
¢ Translation
¢ Scaling
77 3D Rotation
78 Rotation around ZZ’
79 Rotation around XX’
80 Rotation around YY’
81 Example
82 OpenGL (Pre-3.1)
83 OpenGL
RVA - 2014/2015 84 OpenGL
mat 4 m = Identity(); m = Translate(1.0, 2.0, 3.0)* Rotate(30.0, 0.0, 0.0, 1.0)* Translate(-1.0, -2.0, -3.0);
° What happens here ?
RVA - 2014/2015 85 3D Viewing
86 3D Viewing
87 Projections
Parallel Projection Perspective Projection
88 Projections
Parallel Projection Perspective Projection
89 Parallel Projections
90 Perspective Projections
91 Perspective Projections
92 How to represent ?
93 How to limit what is observed ?
Clipping plane Clipping window
Clipping plane
94 3D visualization pipeline
[Hearn & Baker]
95 3D visualization pipeline
¢ Instantiate models ß Position, orientation, size ¢ Establish viewing parameters ß Camera position and orientation ¢ Compute illumination and shade polygons ¢ Perform clipping ¢ Project into 2D ¢ Rasterize
96 3D visualization pipeline
¢ Main operations represented as point transformations ß Homogeneous coordinates ß Transformation matrices ß Matrix multiplication
97 Lighting
¢ Compute surface color based on ß Type and number of light sources ß Illumination model ¢ Phong: ambient + diffuse + specular components ß Reflective surface properties ß Atmospheric effects ¢ Fog, smoke ¢ Polygons making up a model surface are shaded ß Realistic representation
98 Phong reflection model – 1973
[Wikipedia]
99 Phong Model – Ambient illumination
100 Phong Model – Ambient illumination
101 Phong Model – Diffuse reflection
102 Phong Model
103 Phong Model – Specular reflection
104 Phong Model – Specular reflection
105 Phong Model – Specular reflection
and
or
106 Phong Model – Specular reflection
107 Phong Model – Specular reflection
108 More than one light source
109 OpenGL – Material properties
[OpenGL – The Red Book]
110 Lighting
¢ How to optimize? ß Fewer light sources ß Simple shading method
¢ BUT, less computations mean less realism ß Wireframe representation ß Flat-shading ß Gouraud shading ß Phong shading
111 Gouraud shading
[Wikipedia]
112 Flat shading vs Phong shading
[Wikipedia]
113 Can you see the differences ?
114 Some reference books
115 Acknowledgments
¢ Thanks are due to ß Paulo Dias ß Samuel Silva
116