Title: CS 248 Template
1CS148 Introduction to Computer Graphics and
Imaging Scanline Rendering
Electric Sheep screensaver by Scott Draves Image
created collectively by users on the internet
2Human Eye
Light comes from light sources, is absorbed and
reflected off of objects, and goes through the
pupil of the eye.
3Without the pupil light scatters everywhere and
does not make a coherent image
4With a pinhole model of the pupil light makes a
coherent image inside the eye
5Human Retina Rods and cones
- Retina contains rods and cones
- Rods are responsible for light intensity
- Cones are responsible for color vision
-
6Three Types of Cones
From http//webvision.med.utah.edu/imageswv/fovmos
wv.jpeg
7Rods Capture Intensities
8Color Matching Experiment
- Adjust brightness of three primaries
- Lasers R 700 nm, G 546 nm, B 435 nm
- until a human mistakenly thinks it matches
another color C x nm - Result all colors can be matched with three
colors - Therefore humans have trichromatic color vision
C R G B
9Trichromatic Theory
- Since the human eye works in this fashion, we
work this way with images, printers, and
displays. - Image formats store values in the R, G, and B
channels. - The values are between 0 and 255.
- The relative values give the color, and the
overall values give the intensity. - This is similar to the cones of the human eye.
- The monitor can be used to increase or decrease
the image intensities (brightness/darkness). - This is similar to the rods of the human eye.
10Cameras
- A camera works similarly to the eye.
- Light passes through the lens, bends to come to a
point of focus, and makes an upside-down image on
the film.
11Pinhole Camera
- Linear perspective with viewpoint at pinhole
12Laws of Pinhole Cameras
- Common assumptions
- Light leaving an object travels in straight lines
- These lines converge to a point (e.g. pinhole)
- Infinite depth of field which means everything is
in focus - Perspective image is formed by the intersection
of these lines with an image plane - More distant objects subtend smaller visual
angles and appear smaller - Objects in front occlude the objects behind them
13OpenGL Camera
- OpenGL uses a pinhole camera.
- In OpenGL the image plane is in front of the
focal point which means the image is right side
up. - The frustum is the volume of our view (shown in
blue below). - The image plane is the plane of the frustum
nearest to the camera.
14Specifying the Camera in OpenGL
void gluLookAt(eye.x, eye.y, eye.z, at.x, at.y,
at.z, up.x, up.y, up.z)
- gluLookAt creates a camera from an eye point, a
reference point indicating the center of the
scene, and an up vector.
15Specifying the Frustum in OpenGL
void gluPerspective(fovy, aspect, near, far)
- gluPerspective specifies a viewing frustum for
the camera into the world coordinate system. - fovy specifies the field of view angle.
- aspect specifies the aspect ratio of the
associated image plane. - near/far specify the distance from the camera to
the new/far clipping plane.
16Drawing a Triangle in front of your Camera
glColor3f(1.f,0.f,0.f) glBegin(GL_TRIANGLES) glV
ertex3f(0.f,0.f,0.f) glVertex3f(1.f,0.f,0.f) glV
ertex3f(.5f,.86f,0.f) glEnd()
- void glBegin(Glenum mode)
- glBegin delimits the vertices of a primitive.
- mode specifies the primitive that will be created
from vertices presented between glBegin and
glEnd.
- void glVertex(x,y,z)
- glVertex specifies a vertex to form the
primitive.
17Fundamental Primitive Triangles
- Why triangles?
- Lowest common denominator
- Easily break convex polygons into triangles
- Optimize the implementation of one primitive
- Triangles have unique properties
- Guaranteed to be planar
- Guaranteed to have a well-defined
- interior
- Well-defined method (barycentric interpolation)
for interpolating values in the interior
18Triangle Meshes
Stanford Bunny 69,451 triangles
David, Digital Michelangelo Project 28,184,526
vertices, 56,230,343 triangles
19OpenGL Drawing Primitives
Bitmaps
Images
20Graphics Rendering Pipeline
Commands Processor
triangles, lines, points images
Vertices
Transformed vertices
Primitives
Fragments
Shaded fragments
pixels in the framebuffer
Display
21Command Processor
- Command queue
- Command interpretation
- Unpack and perform format conversion
- Maintain graphics state
glBegin(GL_TRIANGLE_STRIP) glColor3f(.0f, 1.f,
.0f) glVertex3f( .0f, .0f, .0f ) glVertex3f(
0.f, 1.f, .0f ) glColor3f(1.f, .0f,
.0f) glVertex3f( 1.f, .0f, .0f ) glVertex3f(
1.f, 1.f, .0f ) glEnd()
22Per-vertex Operations
- Vertex transformation
- Normal transformation
- Texture coordinate generation
- Texture coordinate transformation
- Lighting (light sources and surface reflection)
- Projection
World-space triangles
Screen-space shaded triangles
23Primitive Assembly
- Combine transformed/shaded vertices into
primitives - 1 vert -gt point
- 2 verts -gt line
- 3 verts -gt triangle
- Clipping
- Transform to window coordinates (viewport)
- Determine orientation (CW/CCW)
- Back-face cull
24Rasterization
- Setup (per-triangle)
- Sampling (triangle fragments)
- Interpolation (interpolate colors and coordinates)
Triangles
Fragments
25Texturing
- Textures are arrays indexed by floats (Sampler)
- Texture address calculation
- Texture bilinear interpolation and filtering
Texture Fragments
Fragments
26Per-fragment Operations
- Combine texture sampler outputs
- Per-fragment shading
Fragments
Textured Fragments
27Frame buffer Operations
- Operation
- Test window ownership
- Test scissor and stencil mask
- Test alpha
- Test depth
- Blending or compositing
Textured Fragments
Framebuffer Pixels
28Testing Depth using Z-Buffer
- Initialize z-buffer to zmax
- Interpolate z across the triangle
- Draw fragment if closer
- if(frag.ZltZfrag.Xfrag.Y)
- Zfrag.Xfrag.Yfrag.Z
- Cfrag.Xfrag.Yfrag.C
http//en.wikipedia.org/wiki/FileZ_buffer.svg
29Frame Buffering
- Frame Buffer
- Store image in a buffer to separate refresh rate
from drawing rate - Single-buffer
- Draw into display buffer directly
- May see picture being drawn
- Double-buffer
- Display front buffer
- Draw into back buffer (cant see drawing)
- Swap front and back (wait until vertical sync)
- Triple buffer
- Avoid waiting for vertical sync
30Framebuffer
Example Framebuffer 1440 x 900
All coordinates are integers they refer to
pixel locations in the framebuffer
31Window
Example Framebuffer 1440 x 900
The window is the portion of the display usable
by the application (under control of the window
system)
Window (512 x 512)
All coordinates are integers they refer to
pixel locations in the framebuffer
32Viewport
Example Framebuffer 1440 x 900
The viewport is the portion of the window that
can be drawn in, no pixels will appear outside
the viewport
Viewport (256x256)
Window (512 x 512)
All coordinates are integers they refer to
pixel locations in the framebuffer
33Specifying the Viewport in OpenGL
void glViewport(x, y, w, h)
- glViewport specifies the location and the size of
the viewport in the screen coordinate system.
Here x, y, w, and h are all integers. - x and y specify the lower left corner of the
viewport rectangle. - w and h specify the width and height of the
viewport. w/h should agree with the aspect ratio
you set in gluPerspective.
34Windows Virtual Framebuffers
- Like virtual memory enables us to share the
physical memory, - virtual framebuffers allows us to share the
physical framebuffer - Abstract properties
- Location and size on the screen
- Stacking order
35Window Coordinate Systems
top 1.0
Window (512 x 512)
right 1.0
left -1.0
bottom -1.0
Each window has a user coordinate system A 2D
coordinate system is specified by assigning
coordinates to the edges of the window left need
not be less than right ...
36Exposure
- Parts of the window that are not visible can
become visible - When opening
- When unhiding
- When brought to front
- How do you update the visible parts of the
window? - Redraw entire window (or a part of it)
- Save the drawn window in a backing store, and
copy onto screen when needed
37Display
- Gamma correction
- Analog to digital conversion
- Display
Light
Framebuffer Pixels
38CPU
glBegin(GL_TRIANGLES) glVertex3fv(v1)
glVertex3fv(v2) glVertex3fv(v3) glEnd()
-90
GPU
OpenGL
-90
39Graphics processing unit
A graphics processing unit (GPU), also
occasionally called visual processing unit (VPU),
is a specialized electronic circuit designed to
rapidly manipulate and alter memory to accelerate
the building of images in a frame buffer intended
for output to a display.
NVIDIAs GeForce GTX 690
VisionTek Radeon 7970
40Whats in a GPU?
Primitive Assembly
Tex
Tex
Tex
Work Distributor
Tex
41Modern PC
System board (Intel D975)
12.8 GB/sec
PCIe Bus (v1 4 GB/sec)
84 GB/sec
NVIDIA 8800GTX
42Game Machines Xbox 360
controllers/ethernet/ audio/DVD/etc.
Display (TV)
43Game Machines PS3
controllers/ethernet/ audio/DVD/etc.
Display (TV)
44Hybrid CPU-GPUs
Intel Sandybridge
Apple A5
45NVIDIA GPU Performance
Year Product Triangle/s Fragment/s
1998 Riva ZX 3m 100m
1999 Riva TNT2 9m 350m
2000 GeForce2 GTS 25m 664m
2001 GeForce3 30m 800m
2002 GeForce Ti 4600 60m 1200m
2003 GeForce FX 167m 2000m
2004 GeForce 6800 Ultra 170m 6800m
2005 GeForce 7800 GTX 940m 10300m
2006 GeForce 7900 GTX 1400m 15600m
2007 GeForce 8800 GTX 1800m 36800m
2008 GeForce GTX 280 48160m
2010 GeForce GTX 480 42000m
2011 GeForce GTX 580 49400m