Download Intro to 3D computer graphics - Electronic Visualization Laboratory

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
Transcript
CS 426
Intro to 3D
Computer Graphics
© 2003, 2004, 2005 Jason Leigh
Electronic Visualization Lab,
University of Illinois at Chicago
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Coordinate Systems
Left-handed
Coordinate System
(typical computer graphics
Reference system – Blitz3D, DarkBASIC)
Right-handed
Coordinate System
(conventional Cartesian
reference system)
Y
Y
Z
X
X
Z
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Polygons, Meshes & Scan Conversion
V1
Raster
Scan line
V3
V2
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Transformations
• Transformation
occurs about the
origin of the
coordinate system’s
axis
Translate
Scale
Rotate
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Order of Transformations Make a
Difference
Box centered at
origin
Rotate about Z 45;
Translate along X 1
Translate along X 1;
Rotate about Z 45
Evaluation order in Blitz3D, DarkBASIC’s
position, scale, orientation commands: Scale, Rotate, Translate
University of Illinois at Chicago
Electronic Visualization Laboratory (EVL)
Hierarchy of Coordinate Systems
• Also called:
– Scene graphs
– Parent and Child
Entities in Blitz3D
– Called Skeletons in
DarkBASIC because it is
usually used to represent
people (arms, legs, body).
Electronic Visualization Laboratory (EVL)
Local coordinate system
University of Illinois at Chicago
The Camera
Parallel Projection
Perspective Projection
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
The Camera
Near Clipping
Plane
Projection Plane
Far Clipping
Plane
View Volume
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Lighting
• Ambient – basic, even
illumination of all objects in a
scene
• Directional – all light rays are in
parallel in 1 direction - like the
sun
• Point – all light rays emanate
from a central point in all
directions – like a light bulb
• Spot – point light with a limited
cone and a fall-off in intensity –
Penumbra angle
like a flashlight
(light starts to drop off
to zero here)
University of Illinois at Chicago
Electronic Visualization Laboratory (EVL)
Diffuse Reflection
(Lambertian Lighting Model)
The greater the angle between the normal and the vector from
the point to the light source, the less light is reflected. Most light
is reflected when the angle is 0 degrees, none is reflected at 90
degrees.
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Specular Reflection
(Phong Lighting Model)
•
•
•
•
•
•
•
Electronic Visualization Laboratory (EVL)
Maximum specular reflectance occurs
when the viewpoint is along the path
of the perfectly reflected ray (when
alpha is zero).
Specular reflectance falls off quickly
as alpha increases.
Falloff approximated by cosn(alpha).
n varies from 1 to several hundred,
depending on the material being
modelled.
n=1 provides broad, gentle falloff
Higher values simulate sharp, focused
highlight.
For perfect reflector, n would be
infinite.
University of Illinois at Chicago
Fall off in Phong Shading
Large n
Electronic Visualization Laboratory (EVL)
Small n
University of Illinois at Chicago
Approximating Curved Surfaces with
Flat Polygons
Flat Shading – each
polygon face has a normal
that is used to perform
lighting calculations.
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Gouraud Shading
• Compute vertex normals by
averaging face normals.
• Compute intensity at each
vertex.
• Interpolate the intensity along
the edges of the polygon.
I1
I1,2
I1,2,3,4
I1,3
Raster
Scan line
I3
I2
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Phong Shading
N1
N1,2
N1,2,3,4
N1,3
Raster
Scan line
N3
N2
N1,2
N1,3
Electronic Visualization Laboratory (EVL)
• Interpolate the
Normals between
the end points of
the scan line
rather than just the
intensity.
• Used with Phong
lighting model to
produce specular
highlights.
University of Illinois at Chicago
Texture Mapping
• Apply picture to a polygon surface to add realism
without explicitly creating geometry.
v
u
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Texture Maps Used in Tank Game
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Billboarding
Billboards
Real
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Backface Culling &
Flipping Surface Normals
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Normal Mapping
Regular texture map
•
Modify normals on a per-pixel
basis using a Normal Map
•
The map is an R,G,B map
where the 3 components
represent the direction of the
normal vector relative to the
tangent of the polygon’s
surface
Texture map + normal map
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Normal Mapping
• In modern games, normal maps are
computed for high polygon scenes and then
mapped onto low polygon models giving
them incredible levels of detail
• See 1st segment of UnReal Video on
Normal Mapping
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Bump Mapping
• Predecessor to Normal Mapping where a greyscale texture
is used as a height field to modify the shading normal on
the surface of a polygon (on a per pixel basis)
• Creates very similar effect as Normal Mapping
Perturbed normals
Height field
Polygon surface
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Weakness of Normal/Bump Mapping
• If you look at the polygon on its
Bump
side, it will still look flat.
• Answer: Use Displacement
Mapping to perturb the actual
geometry of the mesh
• Height field is used to displace
the geometry of the mesh
Displacement
along its normal
• See UnReal video on
displacement map (right after
Normal Map)
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Double Buffering, Drawing Order,
Z Buffering
Back Buffer
Front
Buffer
Image is drawn to the back
buffer while the front buffer
is displayed to the viewer.
Swapping is usually done
during vertical blank of the
monitor (50Hz).
Most PCs tend to turn this
synch off resulting in
flickering of graphics.
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago
Depth Sorting of Polygons
•
•
•
•
•
•
•
PS1 did not have Z Buffering
Polygons had to be sorted
back-to-front to draw them in
the right order.
Z Buffer ~ 16-32bits/pixel.
Buffer that stores depth
information on a per pixel
basis.
Used to determine which
pixel is in front of the other.
Small Z values are in front.
Avoids having to sort
polygons in Z when
rasterizing.
Electronic Visualization Laboratory (EVL)
3
2 4
8
University of Illinois at Chicago
Transparency & the Effect of Drawing
Order
Drawing order 1
2
3
Viewpoint
Viewpoint
Alpha
blending
occurs
Electronic Visualization Laboratory (EVL)
University of Illinois at Chicago