Lecture 5: 3D Rendering Pipeline (II) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology
2 Parallel Projection Viewer’s position View plane Project from 3D space to viewer’s 2D space
3 Perspective Projection The farther the object is, the smaller it appears Some photo editing software allows you to perform “Perspective Correction” Viewer’s position View plane
4 Perspective Projection x y z (x,y,z) (xs,ys,d) d xs ys x y z
5 Perspective Projection x y z (x,y,z) (xs,ys,d) d xs ys x y z
6 Viewing Frustum Far plane Viewer’s position Near plane Think about looking through a window in a dark room
7 Viewing Frustum Near plane Far plane Viewer’s position
8 Define Viewing Frustum (Projection Transformation) Viewer’s position +z Parameters: Fov: Field of View Aspect ratio = Width/Height Near z Far z fov/2 +y Far z Near z Width Height
9 Viewport Transformation The actual 2D projection to the viewer Copy to your back buffer (frame buffer) Can be programmed, scaled,..
10 Other Geometry Optimizations Backface Culling Clipping Hidden surface removal (Occlusion)
11 Backface Culling Determine “facing direction” Triangle order matters How to compute a normal vector for 2 given vectors? Cross product –Using Cross product of 2 given vectors (c1, c2, c3) (b1, b2, b3) (a1, a2, a3) Cross product 2 Vectors
12 Compute the Surface Normal for a Triangle (0, 0, 0) (4, 0, 0) (3, 3, 0) Compute Normals (Clockwise vectors) v1 v2 x z y
13 Compute the Surface Normal for a Triangle (0, 0, 0) (4, 0, 0) (3, 3, 0) Compute Normals v2 v1 x z y
14 Backface Culling Method Check if the normal is facing the camera How to determine that? –Use Dot Product Surface vectors Eye vector
15 Backface Culling Method (dot product) A B
16 Backface Culling Method (dot product)
17 When to Perform Backface Culling? ClippingPerspective DivideViewport Transform Rasterization Projection TransformWorld TransformView TransformLighting Backface Culling ClippingPerspective DivideViewport Transform Rasterization Projection TransformWorld TransformView TransformLightingBackface Culling How? Transform your camera to the world space first!
18 3D Clipping Test 6 planes if a triangle is inside, outside, or partially inside the view frustum Clipping creates new triangles (triangulation) –Interpolate new vertices info
19 How to Clip Against a Plane? Test each vertex of a triangle –Outside –Inside –Partially inside Incurred computation overhead Save unnecessary computation (and bandwidth) later Need to know how to determine a plane Need to know how to determine a vertex is inside or outside a plane
20 What it Takes to Determine a Plane? You need two things to specify a plane –A point on the plane (p0, p1, p2) –A vector (normal) perpendicular to the plane (a, b, c) –Plane a*(x – p0) + b*(y – p1) + c*(z - p2) = 0 V=(5, 6, 7) P=(1, 2, 3) K=(x, y, z) Plane equation 5*(x-1)+6*(y-2)+7*(z-3)=0
21 Distance Calculation from a Plane Given a point R, calculate the distance –Distance > 0 inside the plane –Distance = 0 on the plane –Distance < 0 outside the plane Normal R d d P
22 Distance Calculation from a Plane R d P 180-
23 Triangulation using Interpolation (a2, b2, c2) (a1, b1, c1) (x, y, z) d1 d2
24 Illumination Models It won’t look 3D without lighting Part of geometry processing Illumination Types –Ambient –Diffuse –Specular –Emissive
25 Local vs. Global Illumination Local Illumination –Direct illumination: Light shines on all objects without blocking or reflection –Used in most games Global Illumination –Indirect illumination: Light bounces from one object to other objects –Add more realism (non real-time rendering) –Computationally much more expensive –Ray tracing, radiosity ?
26 Common Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone) Inner cone outer cone
27 Illumination: Ambient Lighting Not created by any light source A constant lighting from all directions Contributed by scattered light in a surrounding RGB multiplies separately Material ColorLight Color
28 Illumination: Diffuse Lighting Light sources are given Assume light bounces in all directions Refelcted Light will reach the eyes no matter where the camera is! Diffuse surface
29 Reflected Light Intensity Calculation Reflectivity the entry angle Use Lambert’s cosine Law intensity F( )=cos( ) Surface Normal n Surface Normal n Surface Normal n Dot product Reflection Full None Partial L
30 Diffuse Illumination: Diffuse Lighting Material Color Light Color Ambient + Diffuse Ambient + Diffuse
31 Illumination: Specular Lighting Create shining surface (surface perfectly reflects) Viewpoint dependent Ambient + Diffuse + Specular Material Color Light Color Specular
32 Jim Blinn’s Specular Model An improved version from Phong Specular model which uses Reflective vector R S“S” controls the bright region around surface E L n R Half-way vector H
33 Brightness Effect (S) L1 L2 n1 n2 H1 H2 More shining E1 E2
34 Brightness Effect (S) intensity cos cos 2 cos 8 cos 64 cos > cos ~0.65 ~0.95 cos 8 >>> cos 8 ~0.62 n1 n2 H1 H2 S=1 n1 n2 H1 H2 S=8 ~0.05 radian
35 Specular Lighting Effect A larger S shows more concentration of the reflection
36 Illumination: Emissive Lighting Color is emitted by the material only Ambient + Diffuse + Specular + Emissive Material Emissive Color + Ambient + Diffuse + Specular
37 Common Light Sources Directional Light (Infinitely far away) Point Light (Emit in all directions) Spot Light (Emit within a cone) Inner cone outer cone
38 Light Source Properties Position Range –Specifying the visibility Attenuation –The farther the light source, the dimmer the color
39 Falloff effect Spotlight Effect Similar idea to specular lighting Falloff factor determines the fading effect of a spotlight “f” exponentially decreases the cos value L d