Introduction • Instructor: Yung-Yu Chuang (莊永裕) • E-mail: [email protected] • Office: CSIE 527 Computer Graphics • Grading: a MatchMove project
Com pu ter Sci ence & Info rmat io n Tec hno logy Yung-Yu Chuang
What is computer graphics ? Computer graphics • Definition • Create a 2D image/animation of a 3D world –the pictor ilial synthihesis of real or imag inary objects from their computer-based models
OUTPUT
descriptions images descriptions Computer Graphics PUT NN I images Computer Vision Image Processing Applications Computer graphics •Movies • IiInteractive entertainment • Industrial design • Architecture modeling rendering • Culture heritage
animation
A simple example
(0,0) (1.5,0) # vertices 000.0, 000.0, 000.0 1.5, 0.0, 0.0 000.0, 151.5, 000.0 Modeling 1.5, 1.5, 0.0
# triangles 0210, 2, 1 (0,1.5) (1.5,1.5) 1, 2, 3 z x
y The power of triangles More complex examples • Every thing can be represented by triangles to a degree of precision.
20 triangles 80 triangles 320 triangles
a real buddha 4K mesh rendered 2.4M mesh
Modeling Triangle meshes • The position of the model can be acquired by 3D scanner or made by artists using modeling {f1}{} : { v1 , v2 , v3 } connectivity tools. {f2} : { v3 , v2 , v4 } … • There are other ways for represen ting {v } : (x,y,z) geometric objects, but triangles have many 1 geometry {v2} : (x,y,z) adtdvantages. … {f1} : “skin material” face attributes {f2}:} : “brown hair”hair … {v ,f }}:(n : (n ,n ,n ))(uv) (u,v) 2 1 x y z corner attributes {v2,f2} : (nx,ny,nz) (u,v) … Copyright©1998, Microsoft Composition of a scene Graphics pipeline
z
x y
z x y
Representation
Transformations Representation 2D transformations
Identity Scaling Scaling Reflection
Shearing Rotation Limitations of a 2X2 matrix Homogeneous coordinate • Scaling • RiRotation • Reflection • Shearing
• What do we miss?
Translation 3D scaling 3D translation 3D rotation
3D shearing Graphics pipeline Imaging with the synthetic camera
Projections
Specifying a viewer Projections Parallel and perspective projections Orthographic transformation
orthographic perspective
Perspective projection Perspective transform Triangle meshes
{f1}{} : { v1 , v2 , v3 } connectivity {f2} : { v3 , v2 , v4 } … Graphics pipeline review {v1} : (x,y,z) geometry {v2} : (x,y,z) … {f1} : “skin material” face attributes {f2}:} : “brown hair”hair … {v ,f }}:(n : (n ,n ,n ))(uv) (u,v) 2 1 x y z corner attributes {v2,f2} : (nx,ny,nz) (u,v) … Copyright©1998, Microsoft
Review of graphics pipeline Review of graphics pipeline Transformation Projection & clipping Review of graphics pipeline • Rasterization • Vis ibility
Visibility (Hidden surface removal)
Hidden surface removal Hidden surfaces: why care? • Determining what to render at each pixel. • Occlusion: Closer (opaque) objects along same • A poi nt is vi sibl e if t here ex ists a direct line-of- viewing ray obscure more distant ones sight to it, unobstructed by another other • Reasons for removal object s (viiblisible surface dtdeterm ina tion). – Effici ency: As with • Moreover, some objects may be invisible clipping, avoid wasting work on invisible because there are behind the camera, outside objects of the field-of-view, too far away (clipping) or – Correctness: The image back faced (backface culling). will look wrong if we don’t model occlusion properly Hidden surface removal algorithms Painter’s algorithm
• Painter’s algorithm • Binary space partitioning • Z-buffer • Ray casting Draw primitives • And many others from back to front to avoid need for depth comparisons
from Shirley
Painter’s algorithm Z-buffer algorithm • Idea: Sort primitives by minimum depth, then • Resolve depths at the pixel level rasterize from furthest to nearest • Idea: add Z to frame buffer, when a pixel is • When there are depth overlaps, do more tests drawn, check whether it is closer than what’s of boun ding areas, etc. to see one actua lly already in the framebuffer occludes the other • Proposed by Ed Catmull in 1975, widely used today, especially in hardware.
• Z-buffer, texture, subdivsion surface, RenderMan • Cyyppclical overlaps are a problem • Co-founder of Pixar • 3 Oscars (1993, 1996, 2001), SIGGRAPH Steven Coons Award (()1993) Z-buffer algorithm Z-buffer algorithm
The z-Buffer Algorithm Z-buffer: example
+=
+ =
color buffer depth buffer Z-Buffer Clipping (view frustum culling) • Benefits – Easy to ilimplemen t – Works for any geometric primitive – Parall el operation in hdhardware (id(indepen den t of order of polygon drawn) • Lim ita tions – Memory required for depth buffer – Quantization and aliasing artifacts –Overfill – Transparency does not work well
Review of graphics pipeline Review of graphics pipeline • Rasterization • Shading • Vis ibility Z-buffer algorithm
Shading
What is normal? Normal for a triangle
n plane n ·(p - v0 ) = 0 v2
n = (v2 - v0 ) ×(v1 - v0 )
p v1 normalize n n/ |n| v0
NtNote th thtihtat right-hdhand rul ldte determi nes out ward df face Using average normals Using average normals
N = true (i)l(geometric) normal N N2
N1
Using average normals Using average normals
N1234NNN N N 1234NNN 1 N N NN12 N N 2 2 More generally, N1 n N N i N1 i 1 N2 N n N4 N i N i 1 3
It can also be area-weighte d. Triangle meshes Illumination (shading) models • Interaction between light sources and objects in scene that results in perception of intensity {f1}{} : { v1 , v2 , v3 } connectivity and color at eye {f2} : { v3 , v2 , v4 } … • Local vs. global models {v1} : (x,y,z) geometry – Local: perception of a particular primitive only {v2} : (x,y,z) deppgends on light sources directly affecting that one … primitive {f1} : “skin material” face attributes •Geometry {f2}:} : “brown hair”hair • Material properties … • Shadows cast (global?) {v ,f }}:(n : (n ,n ,n ))(uv) (u,v) – Global: also take into account indirect effects on 2 1 x y z corner attributes light of other objects in the scene {v2,f2} : (nx,ny,nz) (u,v) … • Light reflected/refracted • IdiIndirec t lihtilighting Copyright©1998, Microsoft
Local vs. global models Setup
vL vE
• Point P on a surface through a pixel p •NormalN at P • Lighting direction vL • Viewing direction vE Direct lighting Indirect lighting • Compute color L for pixel p Surface types Basics of local shading • The smoother a surface, the more reflected light is • Diffuse reflection concentrated in the direction a perfect mirror would – light goes everyw here; colore d by objtbject color reflected the light • Specular reflection •A veryyg rough surface scatters li ght in all directions – happens only near mirror configuration; usually white • Ambient reflection – constant accounted for other source of illumination
smooth surface rough surface
Ambient shading Diffuse shading • add constant color to account for disregarded • Assume light reflects equally in all directions illumination and fill in black shadows; a cheap – Theref ore surface llkooks same color from all views; hack. “view independent” ambient light Diffuse shading Diffuse shading (Gouraud 1971) • Illumination on an oblique surface is less than • Applies to diffuse, Lambertian or matte on a normal one (Lambertian cosine law) surfaces
– Generally, illumination falls off as cosθ
(()albedo)
Diffuse shading Diffuse shading For color objects, apply the formula for each color channel separately
0.4 0.55 0.7 0.85 1.0
diffuse-reflection model with different kd
0.0 0.15 0.3 0.45 0.6
ambient and diffuse-reflection model with different ka and Ia Ip 1.0,kd 0.4 Specular shading Specular shading (Phong 1975) • Some surfaces have highlights, mirror like • Also known as glossy, rough specular and reflection; view direction dependent; directional diffuse reflection especially for smooth shinny surfaces
Specular shading Specular shading • Fall off gradually from the perfect reflection • Increasing n narrows the lobe direction
cosn
n=1 n=2 n=3 n=10 90 0 90 Specular shading Specular shading
ks
0.1
0.25
0.5 diffuse diffuse + specular n 3.0 n 5.0 n 10.0 n 27.0 n 200.0
Put it all together Choosing the parameters • Include ambient, diffuse and specular
• Sum over many lights Computing lighting at each pixel Shading models for polygons • Most accurate approach: Compute component • Flat Shading illumination at each pixel with individual – Facet e d Sha ding positions, light directions, and viewing – Constant Shading directions •Gouraudhdd Shading • But this could be expensive... – Intensity Interpolation Shading y – Color Interpolation Shading y 1 •Phonggg Shading I – Normal-Vector Interpolation Shading p Scan line ys
y2
y3
Flat Shading Intensity Interpolation (Gouraud) • Compute constant shading function,,pyg over each polygon • Same normal and light vector ys y2 y1 ys across whole ppygolygon Ia I1 I2 y1 y2 y1 y2 I • Constant shading for polygon I 1 1 I I y y y y a b I I s 3 I 1 s I p I y b 1 3 y s y1 y3 y1 y3 s
I2 x x x x I b p p a 3 I I I I2 I p a x x b x x I p b a b a p I3 Normal Interpolation (Phong) Normal Interpolation (Phong)
~ y y y y N x x x x s 2 1 s 1 Na b p Nb p a Na N1 N2 N y y y y p 1 2 1 2 Na N x x x x b Na b a Nb b a y ~ s y y y y N p N N s 3 N 1 s N b 1 3 p ~ Normalizing makes y1 y3 y1 y3 N 2 N p N p this a unit vect or N3
Gouraud v.s. Phong Shading Flat shading
Gouraud Phong Gouraud Phong Gouraud shading Phong shading
Triangle meshes
{f1}{} : { v1 , v2 , v3 } connectivity {f2} : { v3 , v2 , v4 } … Graphics Pipeline {v1} : (x,y,z) geometry {v2} : (x,y,z) … {f1} : “skin material” face attributes {f2}:} : “brown hair”hair … {v ,f }}:(n : (n ,n ,n ))(uv) (u,v) 2 1 x y z corner attributes {v2,f2} : (nx,ny,nz) (u,v) … Copyright©1998, Microsoft Review of graphics pipeline Review of graphics pipeline Transformation Projection & clipping
Review of graphics pipeline Review of graphics pipeline • Rasterization • Shading • Vis ibility Hierarchical modeling: a robot arm
Animation
Hierarchical modeling Animator demos Videos • TigerWang • RiRacing
Advanced topics
Global illumination Complex materials Realistic motion Graphics hardware
Nvidia GT200 GPU
200 cores
Animation production pipeline
Animation production story tttext tttreatmen t stbdtoryboard
voice storyreal look and feel Animation production pipeline
What’s next? modli/deling/ar tiltiticulation ltlayout animation
shading/lighting rendering final touch
Related courses Related courses