Computer Graphics - Handouts
Computer Graphics - Handouts
Computer Graphics
Handouts
1
Computer Graphics
Introduction:
This handout provides supporting material of computer graphics to accompany with the video lectures.
The content is mainly delivered in the lectures and this handout will follow the same order as that of
used in video lectures.
Computer Graphics: The study of using computers to create and manipulate images is called Computer
Graphics. Storage of geometric objects and their images also fall in category of Computer Graphics.
Graphics Areas
Modeling
The area of Computer graphics that deals with the mathematical specification of shape and appearance
properties in a way that can be stored on the computer is called Modeling.
Rendering
Illumination
Animation
The technique to create an illusion of motion through sequences of images is referred to as Animation.
Applications
Computer Graphics are utilized in almost every wake of life. Graphics are used in for
• Entertainment
o Video Games
o Cartoons
o Animated Films
• Industry
o CAD/CAM: These fields use computer technology to design parts and products on the
computer and then, using these virtual designs, to guide the manufacturing process, e.
g. AutoCAD from AUTODesk Microsoft Visio and Adobe’s Photoshop etc.
• Simulations
o Can be taken as accurate video games e.g. Flight Simulator, Power Plant Simulator,
Firefighter Simulator
• Medicine
2
o Medical Imaging
o Meaningful images of patients scanned data
o MRI
o CT Scan
o Guided Surgery
• Scientific Visualization
• Education and Training
• Everyday Uses
Visualization
Representing data with graphical illustrations is called visualization. Visualization can be categorized as
• Producing graphical representations for scientific, engineering, and medical data sets and
processes is generally referred to as scientific visualization
• The business visualization is used in connection with data sets related to commerce, industry,
and other nonscientific areas.
Image Processing
Image processing applies techniques to modify or interpret existing pictures, enhancing images and
videos
Machine vision
Graphical User Interfaces display menus and icons for fast selection of any processing required.
The user does not have to memorize commands or capabilities of computer software. All options
provided by the software can be explored just by navigating using mouse clicks.
A windows manager allows user to display multiple windows. Each window can process different data
(weather graphical or text). A window can be made active just by clicking mouse on it.
Output Devices
Filament (acts as heating element, electrons emit from it in the form of beam). Electrons move towards
positive plate (Anode) focusing cylinder (because of Electric field). Vertical and horizontal deflection
plates have magnetic field in between them and control the position of the electron beam. The beam
strikes phosphor coating on front of tube producing illumination. Stronger the beam, brighter is the
screen. Longer the beam stays on a point brighter is the screen.
3
Figure 1: Cathode Ray Tube
Characteristics of CRT
• Size of tube
• Brightness of the phosphors vs. darkness of the tube
• Speed of electron gun
• Diameter of the beam
• Pixels
• Disadvantages are
• Size of the tube
• High power consumption
• Flicker
• Costly to refresh
4
Phosphorescence is Light emitted once the electron beam is removed
Persistence: The time from the removal of the excitation to the moment when phosphorescence has
decayed to 10% of the initial light output
Interlacing:
A frame is divided into odd (only odd numbered lines are shown at an instant) and even (only even
numbered lines are shown at next instant) fields as shown in the Figure 2
Video Formats
5
• RGB - 3 independent video signals and synchronization signal, vary in resolution and refresh rate
• Time-multiplexed color - R,G,B one after another on a single signal, vary in resolution and
refresh rate
Raster Displays
Raster displays
Frame Buffer
Raster images require frame buffers. Frame buffer - A block of memory, dedicated to graphics output,
that holds the contents of what will be displayed. If we want a frame buffer of 640 pixels by 480 pixels,
we should allocate a frame buffer = 640*480 bits.
Movie Standards
Films play at 24 fps by U.S. film projectors. Projectors have a shutter to block light during frame advance.
To reduce flicker, shutter opens twice for each frame – resulting in 48 fps flashing which is perceptually
acceptable. European film projectors play film at 25 fps. American films are played ‘as is’ in Europe,
resulting in everything moving 4% faster. Faster movements and increased audio pitch are considered
perceptually acceptable.
A 24 film fps must be converted to NTSC U.S. television interlaced 29.97 fps 768x494 or PAL Europe
television 25 fps 752x582. Use 3:2 Pull – down. First frame of movie is broken into first three fields (odd,
even, odd), Next frame of movie is broken into next two fields (even, odd), Next frame of movie is
broken into next three fields (even, odd, even) and so on.
Liquid crystal displays use small flat chips which change their transparency properties when a voltage is
applied. LCD elements are arranged in an n x m array call the LCD matrix. Level of voltage controls gray
6
levels. LCDs elements do not emit light, use backlights behind the LCD matrix. Color is obtained by
placing filters in front of each LCD element. Image quality depends on viewing angle.
Advantages of LCD
Resolution
The Resolution is defined as the number of dot per inch or centimeter that can be plotted horizontally &
vertically. Higher the resolution, smaller is the spot size. Resolution is related with quality of the graphics
system. Higher the resolution better is the graphics system. High quality resolution is 1280x1024, for
example. The intensity distribution of spots on the screen has Gaussian distribution. Adjacent points will
appear distinct as long as their separation is greater than the diameter at which each spot has intensity
of about 60% of that at the center of the spot.
Aspect Ratio
The Aspect Ratio is the ratio between number of scan lines in a rater and the number of pixels in a scan
line necessary to produce equal length lines in both directions on the screen.
LED Display
LED, actually, stands for Light Emitting Diode. LED displays use the same technology for display but it
uses LED’s for back light while LCD displays generally use Cold Cathode Fluorescent technology
Plasma Panel
Plasma display panels are similar in principle to fluorescent light tubes. Small gas-filled capsules
are excited by electric field, emits UV light, and UV excites phosphor, phosphor relaxes, emits
some other color.
Plasma panels are fairly bright and offer large viewing angle and are good for large format display.
Plasma panels, however, are expansive, have large pixel size (~1mm as compared to ~0.2mm). Phosphor
depletes with time and are less bright than CRT
Vector Display
The electron beam illuminates only the parts of the screen where a picture is to be drawn. It works like a
plotter i.e. draws a one picture line at a time and is used in line drawing and wireframe displays. Picture
definition is stored as a set of line-drawing commands stored in a refresh display file. Number of lines
derive Refresh rate and refresh cycle which is between 30 and 60 per second. Vector display can draw
100,000 short lines at this refresh rate.
7
Resolution of vector displays is higher than raster and line drawings are smooth while these displays are
not suitable for realistic shaded scenes.
Hardcopy Devices
• Inkjet Printer
• Laser Printer
• Film Recorder
• Electrostatic Printer and
• Pen Plotter
Input Devices
Locator Devices: used to indicate a position and/or orientation and to select a displayed entity e.g.
Tablet, Mouse, Trackball, Joystick, Touch Panel, Light Pen
Keyboard devices: to input a character string e.g. Alphanumeric keyboard (coded - get single ASCII
character, un-encoded - get state of all keys - more flexible)
Valuator Devices: to input a single value in the space of real numbers Rotary dials (Bounded or
Unbounded), such as Linear sliders.
Function keys
Rods and cones are energized by electromagnetic energy in the range 350-780 nm. Size (number) of
rods and cones determines the resolution of HVS – our visual acuity. The sensors in the human eye do
not react uniformly to the light energy at different wavelengths. HVS responds differently for single
frequency light – red/green/blue.
Ray Tracing
Building an imaging model by following light from a source is known as Ray Tracing. A Ray is a semi –
infinite line that emerges from s source and continues to infinity in one direction. Parts of ray that
contribute in making image are computed by the contribution from all arrays whether they are incident
directly or reflected from other objects.
Surfaces of the objects may be diffusing, reflecting or refracting. For each pixel intensity must be
computed, contributions of all rays must be taken into account.
8
Many algorithms exist to make this not only feasible, but remarkably efficient. Tracing one ray is a
complex problem and requires serious work to make it run at an acceptable speed. Of course, the big
problem is the fact that one needs to trace lots of rays to generate a high quality image.
Lighting
Once we have the key intersection information (position, normal, color, texture coordinates, etc.) we
can apply any lighting model we want. This can include procedural shaders, lighting computations,
texture lookups, texture combining, bump mapping, and more. Many of the most interesting forms of
lighting involve spawning off additional rays and tracing them recursively. The result of the lighting
equation is a color, which is used to color the pixel
Ray generation, which computes the origin and direction of each pixel’s viewing ray based on the
camera geometry.
A ray when intercepted by a surface splits into two rays, Absorbed or Reflected.
Shading, which computes the pixel color based on the results of ray intersection.
Pixel Formats
There are many pixel formats following pixel formats are more common.
• 1-bit gray scale—text and other images where intermediate grays are not desired (high
resolution required)
• 8-bit RGB fixed-range color (24 bits total per pixel)—web and email applications, consumer
photographs
• 8- or 10-bit fixed-range RGB (24–30 bits/pixel)—digital interfaces to computer displays;
• 12- to 14-bit fixed-range RGB (36–42 bits/pixel)—raw camera images for professional
photography
• 16-bit fixed-range RGB (48 bits/pixel)—professional photography and printing, intermediate
format for image processing of fixed-range images;
• 16-bit fixed-range gray scale (16 bits/pixel)—radiology and medical imaging;
• 16-bit “half-precision” floating-point RGB—HDR images; intermediate format for real-time
rendering;
• 32-bit floating-point RGB—general-purpose intermediate format for software rendering and
processing of HDR images.
Image Storage
RGB images result in almost 3MB for 1 million pixel image. To reduce storage space, various
compression techniques are employed and used in image compression. Generally compression is
categorized as
9
• Lossy Compression (some quality may be compromised)
Storage Formats
• jpeg. This lossy format compresses image blocks based on thresholds in the human visual
system. This format works well for natural images.
• tiff. This format is most commonly used to hold binary images or losslessly compressed 8- or 16-
bit RGB although many other options exist.
• ppm. (Portable Pixel Map)This very simple lossless, uncompressed format is most often used for
8-bit RGB images although many options exist.
• png. (Portable Network Graphics) This is a set of lossless formats with a good set of open source
management tools.
Views:
Parallel Projection: 3D points are mapped to 2D by moving them along a projection direction until they
hit the image plane
Projections
When projection lines are parallel and perpendicular to the image plane, the resulting views are called
orthographic. The image plane is perpendicular to the view direction, the projection is called
orthographic otherwise it is called oblique
Creating View
In three-point perspective, an artist picks “vanishing points” where parallel lines meet. Parallel
horizontal lines will meet at a point on the horizon. Every set of parallel lines has its own vanishing
points. These rules are followed automatically if we implement perspective based on the correct
geometric principles.
We start by ‘shooting’ rays from the camera out into the scene. We can render the pixels in any order
we choose (even in random order!), but we will keep it simple and go from top to bottom, and left to
right. We loop over all of the pixels and generate an initial primary ray (also called a camera ray or eye
ray). The ray origin is simply the camera’s position in world space. The direction is computed by first
finding the 4 corners of a virtual image in world space, then interpolating to the correct spot, and finally
computing a normalized direction from the camera position to the virtual pixel.
10
Shadow Rays
Shadow rays behave slightly differently from primary (and secondary) rays. Normal rays (primary &
secondary) need to know the first surface hit and then compute the color reflected off of the surface.
Shadow rays, however, simply need to know if something is hit or not. In other words, we don’t need to
compute any additional shading for the ray and we don’t need to find the closest surface hit. This makes
them a little faster than normal rays.
Viewing Problems
Some viewing techniques perform better in viewing objects than a whole scene.
Internal Viewing: Viewing from inside. e.g. internal of a building specially in games.
Projections
Project N-Dimensions Coordinates onto <N Dimensions Coordinates. When projection lines are parallel
and perpendicular to the image plane, the resulting views are called orthographic. The image plane is
perpendicular to the view direction, the projection is called orthographic otherwise it is called oblique
Perspective
The process of creating 2D images of 3D objects/scenes. In linear perspective, 3D objects are projected
onto an image plane in such a way that straight lines in the scene become straight lines in the image.
Parallel Projection: 3D points are mapped to 2D by moving them along a projection direction until they
hit the image plane.
11
• Parallel
• Orthographic: The projectors are orthogonal to the projection surfaces
• Top (Plan): Projection planes can move relative to the object
• Axonometric: Projection planes can move relative to the object. Axonometric projections are
classified by how many angles of a corner of a projected cube are the same.
• Trimetric (none of the angles is same)
• Dimetric (two angles are same)
• Isometric (all three angles are same)
• Oblique Projections: Relationship between projectors and projection plane is arbitrary
• Perspective Projections: Perspective views are characterized by diminution of size. When
objects are moved farther from the viewer, their images become smaller
• Three Point Perspective: None of the principal face is parallel to projection plane. No. of
vanishing points is three in a cube
• Two Point Perspective: One of the principal directions is parallel to projection plane. No. of
vanishing points is two in a cube
• One Point Perspective: One of the principal faces is parallel to projection plane. No. of vanishing
points is one in a cube
Geometry is a subject that relates objects in n – dimensional space (In computer graphics we deal with 3
dimensional spaces). Scalars, vectors and points form minimum set of primitives and are used to build
sophisticated objects.
A point is a location in space that neither has size nor shape. Real numbers (magnitudes) such as
distance between two points are scalars.
Scalars: Scalars are members of sets which can be combined by addition and multiplication and obey
associativity, commutivity and inverses axioms. Scalars don’t possess any geometric properties e.g. Real
and Complex numbers
Vectors: A quantity defined by magnitude and direction such as Velocity, Force etc. For computer
graphics, a directed line segment (can be used for any vector) is most significant example.
Properties of Vectors
Scalar Multiplication: A vector can be multiplied by a scalar (magnitude changes only not the direction)
Zero vector is also defined with zero magnitude and undefined direction
12
A Euclidean space is an extension of a vector space that adds a measure of size or distance and allows us
to define such things as the length of a line segment.
An affine space is an extension of the vector space that includes an additional type of object: the point.
Operations between vectors and points are allowed
v=P–Q
P=Q+v
Lines
P(α) = P0 + α d
where P0 is an arbitrary point d is an arbitrary vector and α is a scalar (that can vary over a range). This
relation can be interpreted as the set of all points that pass through P0 in the direction of the vector d.
Dot product:
v1. v2 = v1 v2Cosθ
13
Cross Product
The product of two vectors (a and b) is another vector which is orthogonal to both the vectors (a and b).
The new vector is called Cross Product or Vector Product of the two vectors. Right hand rule determines
the direction of the product.
Transformations (2D)
Scaling
Scaling is achieved by multiplying each graphic component by a scalar. Scaling will be uniform if this
scalar is same for all components. Different components are scaled differently, scaling in uniform. E. g
Rotation: Let a point (x, y) rotates through an angle θ and its new location is (x’, y’) as shown in the
figure 3. The coordinates of new point can be calculated using following transformation matrix. (For
proof watch the relevant lecture)
Translation
Shear
Reflection
14
• (0, 0, 0) is not allowed
The transforms in which angles and lengths are preserved are called rigid body transforms. The body or
object is not distorted after the application of transformation. Rotation and Translation are examples
Affine Transformations
Parallelism of lines is preserved but angles between the lines are not preserved in affine
transformations.
15
Implementation: Implementation can be explained by the following block diagram
Modeling: The usual results of the modeling process are sets of vertices that specify a group of
geometric objects supported by the rest of the system.
Geometry Processing
Geometry processing means to determine which geometric objects can appear on the display and to
assign shades or colors to the vertices of these objects.
Shading
Rasterization
Calculation of pixel values based upon the previous steps i. e. Projection, Primitive assembly, Clipping
and Shading. The rasterizer starts with vertices in normalized device coordinates but outputs fragments
whose locations are in units of the display—window coordinates.
Fragment Processing
Each fragment is assigned a color by the rasterizer and this color is placed in the frame buffer at the
locations corresponding to the fragment’s location. Some of the possibilities are merging with the
results of the geometric pipeline at the rasterization stage, for example shaded and texture-mapped
polygon is processed. Hidden-surface removal process is typically carried out on a fragment-by-fragment
basis. Fragment colors may have to be blended with the colors of pixels already in the color buffer due
to some translucent object
Clipping
Identification of the portions of geometric primitives by analytical calculations within the view windows
in known as clipping. Not to clip means rasterize outside framebuffer and waste time to convert pixels
outside the view window.
Line Clipping
A clipper decides which primitive, or part of primitives can possibly be displayed and be passed on to
rasterizer. Primitives that fit within the specified view volume pass through the clipper, or are accepted.
16
Primitives that cannot appear on the display are eliminated, or rejected or culled. Primitives that are
partially within the view volume must be clipped such that any part lying outside the volume is removed
Clipping Algorithms
If both endpoints lie inside all the edges of view window, accept the line “trivially”. If both endpoints lie
outside the same edge of view window, reject the line “trivially”. Otherwise, split the line in two
segments and accept and reject each segment trivially.
Most significant bit (MSB) called bit 1 indicates y-value of points are above ymax
Consider a line segment whose outcodes are given by o1 = outcode(x1, y1) ando2 = outcode(x2, y2). We
can now reason on the basis of these outcodes. There are four cases
1. (o1= o2 = 0). Both endpoints are inside the clipping window, as is true for segment AB in Figure.
The entire line segment is inside, and the segment can be sent on to be rasterized.
2. (o1 ≠ 0, o2 = 0; or vice versa). One endpoint is inside the clipping window; one is outside (see
segment CD in Figure). The line segment must be shortened. The nonzero outcode indicates
which edge or edges of the window are crossed by the segment. One or two intersections must
be computed. Note that after one intersection is computed, we can compute the outcode of the
point of intersection to determine whether another intersection calculation is required.
17
3. (o1 & o2 ≠ 0). By taking the bitwise AND of the outcodes, we determine whether or not the two
endpoints lie on the same outside side of the window. If so, the line segment can be discarded
(see segment EF in Figure).
4. (o1 & o2 = 0). Both endpoints are outside, but they are on the outside of different edges of the
window. As we can see from segments GH and IJ in Figure, we cannot tell from just the outcodes
whether the segment can be discarded or must be shortened. The best we can do is to intersect
with one of the sides of the window and to check the outcode of the resulting point.
Liang-Barsky Clipping
Polygon Clipping
1. Original Polygon
2. New polygon
3. Nothing
Sutherland-Hodgman Clipping
Surfaces: Surfaces play important role in lighting and shading. Surfacetypes according to their reflective
properties are as under.
Specular Surfaces: Specular surfaces appear shiny because most of the light that is reflected or
scattered is in a narrow range of angles close to the angle of reflection. Mirrors are perfectly specular
surfaces
18
Diffusive Surfaces: Diffuse surfaces are characterized by reflected light being scattered in all directions.
Walls painted with matte or flat paint are diffuse reflectors. Perfectly diffuse surfaces scatter light
equally in all directions. Flat perfectly diffuse surface appears the same to all viewers.
Translucent Surfaces: Translucent surfaces allow some light to penetrate the surface and to emerge
from another location on the object. This process of refraction characterizes glass and water. Some
incident light may also be reflected at the surface.
Shadows
1. Diffuse
2. Specular
3. Ambient
1. normal
2. to source
3. to viewer
4. perfect reflector
Ideal Reflector
Local orientation of the surface determines the normal vector. Law of reflection is obeyed. The three
vectors must lie in same plane
19
Lambertian Surface
Perfectly diffuse reflector. Light scattered equally in all directions. Amount of light reflected is
proportional to the vertical component of incoming light reflected light ~cos i.
There are also three coefficients, kr, kb, kg that show how much of each color component is reflected
Specular Surfaces
Most surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors). Specular highlights
appear on smooth surfaces due to incoming light being reflected in directions close to the direction of a
perfect reflection.
According to Phong, Reflected intensity Ir goes as absorption coeff. ks and projection of incoming
intensity along viewer (α is shinness coeff)
Ir ~ ks I cos
Values of vary between 100 and 200 for metals. Values vary between 5 and 10 for surfaces that look
like plastics.
Ambient Light
Ambient light is the result of multiple interactions between (large) light sources and the objects in the
environment. Amount and color depend on both the color of the light(s) and the material properties of
the object. Add ka Ia (reflection coef * intensity of ambient light) to diffuse and specular terms
Distance Terms
The light from a point source that reaches a surface is inversely proportional to the square of the
distance between them. We can add a factor of the form 1/(ad + bd +cd2) to the diffuse and specular
terms. The constant and linear terms soften the effect of the point source.
Light Sources
In the Phong Model, we add the results from each light source. Each light source has separate diffuse,
specular, and ambient terms to allow for maximum flexibility even though this form does not have a
physical justification. Separate red, green and blue components are included. Hence, 9 coefficients for
each point source contribute.
20
Material Properties
Material properties match light source properties. Nine absorbtion coefficients also contribute.
For each light source and each color component, the Phong model can be written (without the distance
terms) as
I =kd Id l · n + ks Is (v · r ) + ka Ia
A program may be judged by UI rather than its functionality. A poor interface may cause user to make
errors. A poor UI may be a hurdle in making people use. Most of the system whether business or
engineering are available with Graphical User Interfaces (GUI) thus enabling users to interact with these
systems through graphical interfaces.
• Windows
• Multiple windows enable variety of information to be prompted on the user’s screen at the
same time.
• Icons
• may represent files or processes
• Menus
• Command selection possible from a menu instead of typing
• Pointing Device
• Mouse may be used for selecting choices from a menu
• Graphics
• Text and Graphical element can be mixed
Advantages
• Simple to use
• Easy to learn
• Maneuvering within the program and other applications possible (quick switching)
• Full screen is available to be accessed immediately (Fast)
Design Process
A good design is user centered design and requires analyses and understanding of user activities. Design
process is given as
21
• Design prototype (paper based)
• Evaluated by end user (modify if required)
• Design prototype
• Evaluated by end user (modify if required)
• Produce dynamic design prototype
• Evaluated by end user (modify if required)
• Executable prototype
• Evaluated by end user (modify if required)
• Experience and capabilities and needs of the system users must be taken into account during
design process of UI
• Designers should be aware of people’s physical and mental limitations and should be convinced
that people make mistakes
• User familiarity: The interface should use terms and concepts drawn from the experience of the
users.
• Consistency i.e. minimal surprise
• Recoverability e.g. undo
• User guidance: help and prompts etc.
• User diversity: Various people with various background may use
Direct Manipulations
Advantages
Disadvantages
22
Menu Selection
Menu Selection
Advantages
Disadvantages
Form fill-in
Advantages
Disadvantages
Command Language
Disadvantages
• Hard to learn
• Poor error management
Operating systems
Natural Language
Advantages
Disadvantages
23
• Requires more typing
It may be presented
Digital presentation is compact so takes lesser screen space and can present precise value while Analog
presentation give good information by just getting an overview and present information of outliers etc.
Dynamic Display
• Time
• Temperature
• Pressure
24
• Data Visualization
• Used to display large amount of information
• Reveals trends
Examples
Weather information from a number of sources and Traffic information at toll plazas.
Use of Colors
Extra dimension can be added and can also be used for warning.
User Facilitation
The user guidance system (like on – line help, error messages and manuals) should be integrated with
the user interface
Animation
We perceive motion persistence of vision (1/25 seconds). If 25 frames are played in one second are
perceived as motion.
Kinematics
Study of movement and motion of the structure that have joints (without consideration of cause of
motion)
Animation Types
• Cel Animation: based on changes that occur from one frame to another.
• Path Animation which is created using Key frames by tweening
25
References:
Fundamentals of Computer Graphics Third Edition by Peter Shirley and Steve Marschner
Interactive Computer Graphics, A Top-down Approach with OpenGL (Sixth Edition) by Edward Angel.
26