Grading Programming Assignmens: 4% Chaper 2 2D Game: Inro o (6%) ou now 3D Transformaions modeling/animaion (11%) Basics of Compuer Graphics: Rendering pipeline (11%) Ray racing (12%) compuer graphics exper Grading Course Info/Policies (boring suff): hp:www.ugrad.cs.ubc.ca/~cs314 Paricipaion (2%) Classroom: Clicke responses + classroom involvemen Pos wo weekly review quesions Based on maerial covered each week Submi via DB (privae, rev# ag) ill Mon 9AM Include: quesion, muliple choice answers, explanaion Grading Programming Assignmens: 4% Weekly Mini Home Quizes: 3% Paricipaion 2% Classroom Review quesion composiion Two Miderms: 25% 12% +13% Final Exam: 3% compuer graphics exper Grading Mini Home Quizes: (3%) Online (connec.ubc.ca) quiz each week (from week 2) Released by Tue AM, Due Friday 9AM Muliple choice quesions Suden/insrucor composed If your quesion seleced - double your quiz grade!!! If wo seleced riple.. compuer graphics exper Page 1 1
Imporan Daes Assignmen 1 due: Sep 21 Assignmen 2 due: Oc 12 Assignmen 3 due: Nov 2 Assignmen 4 due: Nov 3 Miderm 1: Oc 19 Miderm 2: Nov 9 Lieraure (opional) Fundamenals of Compuer Graphics Third ediion (second is OK oo bu noe syllabus changes) Peer Shirley, A.K. Peers Programming Guide J. Neider, T. Davis and W. Mason, Addison- Wesley Course Organizaion Programming assignmens: C++, Windows or Linux ed on deparmen Linux machines graphics library / GLUT for user inerface Face o face grading in lab Opporuniy o show all he cool exra suff ha you do know wha every piece of your code does Learning This is a graphics course using no a course ON Upper-level class: learning APIs mosly on your own only minimal lecure coverage basics, some of he ricky bis Red Book many uorial sies on he web hp://www.xmission.com/~nae/opengl.hml Hall of fame cooles projecs from 22 on Lae/Missing Work Programming Assignmens: 3 grace days TOTAL for unforeseen circumsances srong recommendaion: don use early in erm handing in lae uses up auomaically unless you ell us Home Quizes/Review Quesion Ses Can miss wo of each Excepion: severe illness/crisis, as per UBC rules MUST Ge approval from me ASAP (in person or email) Turn in proper documenaion Plagiarism and Cheaing Shor Summary: Don chea Home quizes and programming assignmens are individual work Can discuss ideas (including on DB), browse Web Bu canno copy code or answers/quesions If you REALLY hink using a source is OK cie i Mus be able o explain algorihms during faceo-face demo or no credi for ha assignmen, possible prosecuion Page 2 2
Basics of Compuer Graphics: Rendering Pipeline Rendering Goal: Transform (3D) compuer models ino images Phoo-realisic (or no) Ineracive rendering: Fas, bu unil recenly low qualiy Roughly follows a fixed paerns of operaions Rendering Pipeline Offline rendering: Ray-racing Global illuminaion Rendering Pipeline Absrac model of sequence of operaions o ransform geomeric model ino digial image graphics hardware workflow Underlying API (applicaion programming inerface) model for programming graphics hardware Direc 3D Acual implemenaions vary Rendering Tasks (no paricular order) Projec 3D geomery ono image plane ransformaions Deermine which primiives/pars of primiives are visible Hidden surface removal Deermine which pixels geomeric primiive covers conversion Compue color of every visible surface poin, shading, exure mapping Advanages of pipeline srucure? Logical separaion of differen componens, modulariy Easy o parallelize: Earlier sages can already work on new daa while laer sages sill work wih previous daa Similar o pipelining in modern CPUs Bu much more aggressive parallelizaion possible (special purpose hardware!) Imporan for hardware implemenaions! Only local knowledge of he scene is necessary Page 3 3
Disadvanages? Limied flexibiliy Some algorihms would require differen ordering of pipeline sages Hard o achieve while sill preserving compaibiliy Only local knowledge of scene is available Shadows Global illuminaion API for graphics hardware Sared in 1989 by Kur Akeley Designed o exploi graphics hardware Implemened on many differen plaforms Pipeline processing Even driven Communicaion via sae seing (Tenaive) Lecure Syllabus Inroducion + Rendering Pipeline (week 1/2) Transformaions (week 2/3) (week 4/5) (week 5) Hidden Surface Removal (week 6/7) Review & Miderm (week 7) Miderm: Oc 19 Models (week 8) Texure mapping (week 9/1) Review & Miderm (week 1) Miderm: Nov 9 Ray Tracing (week 11) Shadows (week 11/12) Modeling (conen creaion) (week 12/13) Review (las lecure) GLUT: Uiliy Toolki Even driven!!! in main(in argc, char **argv) { // Iniialize GLUT and open a window. gluini(&argc, argv); gluinidisplaymode(glut_rgb GLUT_DOUBLE); gluiniwindowsize(8, 6); glucreaewindow(argv[]); // Regiser a bunch of callbacks for GLUT evens. gludisplayfunc(display); glureshapefunc(reshape); // Pass conrol o GLUT. glumainloop(); } reurn ; Even-Driven Programming Rendering Pipeline Implemenaion: /GLu Main loop no under your conrol vs. procedural Conrol flow hrough even callbacks redraw he window now key was pressed mouse moved Callback funcions called from main loop when evens occur mouse/keyboard, redrawing Page 4 4
Graphics Sae (global variables) Se sae once, remains unil overwrien glcolor3f(1., 1.,.) se color o yellow glseclearcolor(.,.,.2) dark blue bg glenable(light) urn on ligh glenable(gl_depth_test) hidden surf. GLUT Inpu Evens // you supply hese kind of funcions void reshape(in w, in h); void keyboard(unsigned char key, in x, in y); void mouse(in bu, in sae, in x, in y); // regiser hem wih glu glureshapefunc(reshape); glukeyboardfunc(keyboard); glumousefunc(mouse); /GLUT Example void display(void) {// Called when need o redraw screen. // Clear he buffer we will draw ino. glclearcolor(,,, 1); glclear(gl_color_buffer_bit); } // Iniialize he modelview marix. glmarixmode(gl_modelview); MODELVIEW); glloadideniy(); // Draw STUFF // Make he buffer we jus drew ino visible. gluswapbuffers(); GLUT and GLU primiives glusphere(...) glucylinder(...) glusolidsphere(gldouble radius, GLin slices, GLin sacks) gluwiresphere(...) glusolidcube(gldouble size) gluwirecube(...) glusolidtorus(...) o us(...) gluwiretorus(...) glusolidteapo(...) gluwireteapo(...) Noe: Have limied se of parameers Conrol via global ransformaions (see a1 emplae) Need o save/resore seing GLUT Example in main(in argc, char *argv[]) {... // Schedule he firs animaion callback ASAP. glutimerfunc(, animae, ); // Pass conrol o GLUT. glumainloop(); reurn ; } void animae(in las_frame = ) { // Do suff // Schedule he nex frame. in curren_ime = gluge(glut_elapsed_time); in nex_frame = las_frame + 1 / 3; glutimerfunc(max(, nex_frame - curren_ime), animae, curren_ime); } GLUT and GLU primiives Example (from a1): void Pad::draw() { glcolor3f(1, 1, 1); glpushmarix(); Save previous sae gltranslaef(x_, y_, ); glscalef(widh_, l heigh_, h 1); glnormal3f(,, 1); glbegin(gl_quads); glverex3f(-.5, -.5, ); glverex3f(-.5,.5, ); glverex3f(.5,.5, ); glverex3f(.5, -.5, ); glend(); glpopmarix(); Resore previous sae } Page 5 5
GLUT and GLU primiives Basic Transformaions: Assignmen 1 Experience & GLUT // Differen basic ransformaions gltranslaef( ); glroaef( ); glscalef( ); Have FUN Descripion: hp://www.ugrad.cs.ubc.ca/~cs314/vsep212/a1/a1.pdf Deadline: Sep 21 Your asks for he weekend Piazza Discussion Group: Regiser Pos review quesions by Mon 9AM Use privae opion, rev1 ag Rendering Pipeline in (More) Deail Assignmen 1 programming environmen on lab compuers/se lapop environmen (opional) Should have all he necessary background afer his class Your asks for he weekend Sign and Submi Plagiarism Form hp://www.ugrad.cs.ubc.ca/~cs314/vsep212/plag.hml Opional reading (Shirley: Inroducion o CG) Mah refresher: Chapers 2, 4 Los of mah coming in he nex few weeks Background on graphics: Chaper 1 Page 6 6
3D Needs o represen models for Shapes (objecs) Relaions beween differen shapes Objec maerials Ligh sources Camera Explici Funcions Curves: y is a funcion of x: Only works in 2D Surfaces: z is a funcion of x and y: y sin(x) Canno define arbirary shapes in 3D z sin( x) cos( y) Shapes Differen philosophies: Volumeric Boolean algebra wih volumeric primiives Spheres, cones, cylinders, ori, Boundary represenaion Single basic primiive Triangles or riangle meshes, poins, lines Higher order surface primiives wih adjusable parameers E.g. all polynomials of degree 2 Splines, NURBS (deails in CPSC 424) Implicis Parameric Funcions Curves: 2D: x and y are funcions of a parameer value 3D: x, y, and z are funcions of a parameer value cos( ) C ( ) sin( ) Curves/Surfaces Mahemaical represenaions: Explici funcions Parameric funcions Implici funcions Parameric Funcions Surfaces: Surface S is defined as a funcion of parameer values s, Names of parameers can be differen o mach inuiion: cos( )cos( ) S(, sin( )cos( ) sin( ) Page 7 7
Shapes Implici Surfaces: Surface defined by zero se (roos) of funcion E.g: 2 2 2 S ( x, y, z ) : x y z 1 Shape Primiives How o inerpre geomery glbegin(<mode of geomeric primiives>) mode = GL_TRIANGLE, GL_POLYGON, ec. Feed verices glverex3f(-1.,., -1.) glverex3f(1.,., -1.) glverex3f(., 1., -1.) Done glend() Shapes Triangles and Triangle Meshes: How o define a riangle? Open GL: (Some) Shape Primiives glpoinsize( floa size); gllinewidh( floa widh); glcolor3f( floa r, floa g, floa b);... Modeling and Viewing Transformaions Placing objecs - Modeling ransformaions Map poins from objec coordinae sysem o world coordinae sysem TRIANGLE... glcolor3f(,1,); glbegin( GL_TRIANGLES ); glverex3f(.f,.5f,.f ); glverex3f( -.5f, -.5f,.f ); glverex3f(.5f, -.5f,.f ); glend(); Placing camera - Viewing ransformaion Map poins from world coordinae sysem o camera (or eye) coordinae sysem Page 8 8
Compuer Graphics 9 Page 9 Modeling Transformaions: Objec Placemen Viewing Transformaion: Camera Placemen Types of ransformaions: Roaions, scaling, shearing Modeling & Viewing Transformaions Translaions Oher ransformaions (no handled by rendering pipeline): Freeform deformaion Linear ransformaions Roaions, scaling, shearing Can be expressed as 3x3 marix E.g. scaling (non uniform): Modeling & Viewing Transformaion z y x z y x 1 3 2 ' ' ' Affine ransformaions Linear ransformaions + ranslaions Can be expressed as 3x3 marix + 3 vecor E.g. scale+ ranslaion: Modeling & Viewing Transformaion Anoher represenaion: 4x4 homogeneous marix z y x z y x z y x 1 3 2 ' ' '
Transformaion Purpose: Projec 3D geomery o 2D image plane Simulaes a camera Camera model: Pinhole camera (single view poin) Oher, more complex camera models also exis in compuer graphics, bu are less common Thin lens cameras Full simulaion of lens geomery Complex and Shading Projecion Page 1 1
Transformaion In compuer graphics: Image plane concepually in fron of cener of projecion ransformaions subse of projecive ransformaions Linear & affine ransformaions also belong o his class All projecive ransformaions can be expressed as 4x4 marix operaions / Conver coninuous 2D geomery o discree Raser display discree grid of elemens Terminology Pixel: basic elemen on device drawing Resoluion: number of rows & columns in device Measured in Absolue values (1K x 1K) Densiy values (3 dos per inch) Screen Space: Discree 2D Caresian coordinae sysem of he screen pixels Removing invisible geomery Geomery ouside viewing frusum Plus oo far or oo near one Page 11 11
Color inerpolaion Linearly inerpolae per-pixel color from verex color values Trea every channel of RGB color separaely color s Problem: Color inerpolaion Line is infiniely hin, bu image has finie resoluion Resuls in seps raher han a smooh line Example: Jaggies Aliasing red green blue One of he fundamenal problems in compuer graphics s s s Page 12 12
Displacemen Mapping (s, ) (s 2, 2 ) (s 1, 1 ) s Issues: (s, ) (s 2, 2 ) (s 1, 1 ) Compuing 3D/2D map (low disorion) How o map pixel from exure (exels) o screen pixels Texure can appear widely disored in rendering Magnificaion / minificaion of exures Filering of exures Prevening aliasing (ani-aliasing) s Texure Mapping Page 13 13
Wihou Hidden Line Removal /Hidden Surface Removal Remove invisible geomery Pars ha are hidden behind oher geomery Possible Implemenaions: Per-fragmen decision buffer Objec space decision polygons agains each oher Soring polygons by disance from camera Hidden Line Removal /Hidden Surface Removal Hidden Surface Removal Page 14 14
: Final image: wrie fragmens o pixels Draw from farhes o neares No blending replace previous color : combine new & old values wih some arihmeic operaions Frame Buffer : video memory on graphics board ha holds resuling image & used o display i No Handled: Reflecion/Shadows Basics of Compuer Graphics: Rendering Pipeline Page 15 15