Title: Computer Graphics For Games Part 2
1Computer Graphics For Games Part 2
2The Pink Bunny
- Triangle Rasterization
- Hidden Surface Elimination
- Lighting
- Other stuff
3Triangles
- Why do we use triangles in graphics?
- Normals are unique Important for lighting
- Space filling triangles tile so they can be used
to represent surfaces. - Atomic All polygons decompose into triangles
4Scan Conversion
- Ray tracing determines a pixels color by tracing
the path of light through the scene to arbitrary
precision. - The result is an extremely realistic image.
- In scanline rendering surfaces are projected on
the screen and space filling rasterizing
algorithms are used to fill in the color. - Color values from light are approximated.
5Quick Math!!
6Barycentric Coordinates
- The axis of a coordinate system dont have to be
perpendicular. - If you use two sides of a triangle as axis, you
can create a coordinate system called barycentric
coordinates. - Basically, in the barycentric coordinate system
you have three coordinates ?,?,? which represents
the signed distance from each of the triangle
edges.
7Why are Barycentric coordinates useful?
- For any point x, if the barycentric
representation of that point x?,x?, x? - Also ?,?,? can be used as a mass function across
the surface of a triangle to be used for
interpolation. - This is used to interpolate normals across the
surface of a triangle to make polygon surfaces
look rounder.
8Definitions
- In this example the origin is at point a.
- The ? and ? axis are the normalized vectors
-
A barycentric coordinate can Be represented by
the equation
Where
And
9Calculating ?,? and ? for anarbitrary point,
(x,y)
- These are derived from the implicit line equation.
10Math Done!!
11Rasterize This!(Rasterization intuition)
- When we render a triangle we want to determine if
a pixel is within a triangle. (barycentric
coords) - Calculate the color of the pixel.
- Draw the pixel.
- Repeat until the triangle is appropriately filled.
12Rasterization Pseudo Code
13A simple optimization
14(No Transcript)
15Hidden Surface Removal
- Currently our projection and rasterization
process doesnt preserve any 3d depth
information. - This will cause some problems when triangles
overlap eachother.
16BSP Trees
- A BSP tree is an example of a painters
algorithm. - The polygons are painted in back to front order
from the perspective of the viewer, this handles
the hidden surface problem. - BSP trees are typically pre-computed in games for
performance.
17The Z-Buffer
Note You must use the z value of the 3d
coordinate after perspective projection but
BEFORE the homogenizing step!!
Typically this algorithm is implemented in
hardware
18Surface Shading
- For now we will assume that when light interacts
with objects of various compositions it is either
diffuse or reflected. - Diffuse light represent light that is partially
absorbed by the surface. Diffuse lighting is also
called matte shading. - Reflected light, is light that bounces directly
off of the object (like a mirror) and primarily
maintains the original color of the light source.
19Lamberts Law
- We assume Lamberts Law to approximate light.
- Basically we assume that the effect of a light
source on the color of a surface is proportional
to the cosine of the angle between the surface
normal and the direction to the light. - We know when the surface points away from the
light if the cosine is negative.
20What is a Normal!?
- A normal is a vector that is perpendicular to two
other vectors. - It is calculated as the cross product of the two
vectors. - Triangles are nice b.c. theres a unique normal
(2 actually) for every triangle. - Remember the right-hand/left-hand rule applies
here!
21How do we compute the Cosine betweenTwo vectors
quickly?!
- The dot product of two vectors is equal to the
cosine of the angle between the two vectors! - Note The vectors have to be unit vectors for
this to be true, otherwise youve got to
normalize them.
22Diffuse Shading
To Deal with negative light
Add in the ambient light
23Reflective Shading(phong shading)
- Phong shading is a simplified reflection model.
- Basically it puts a bright spot which is colored
with the light color on surfaces that are nearest
to the light origin. - Generally we want the bright spot to be brightest
when the reflected component r is going right
into the viewers eye and fall off from there.
24Phong Math
p is the phong exponent, which determines the
falloff rate
We can approximate r with h to eliminate negative
values
This gives us our final phong equation
25What happens when you vary p ?
p 1
p 2
p 8
p 4
26Final Lighting
27Our Pipeline is Complete!
The Bunny Model
Triangle and line drawing
Z buffering
Projection matrices
Diffuse/phong shading
28Other topics
- Alpha blending
- Texture mapping
- Bump mapping
- Shadows
- Surface effects
- Tessellation (curved surfaces)
- Level Of detail
29Alpha Blending
30Texture Mapping
31Bump Mapping
32Normal Interpolation
33Hair
34Surface Shaders
35Tessellation
36Shadows
37Level of Detail