University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Prog 2, Kangaroo Hall.

Slides:



Advertisements
Similar presentations
Graphics Pipeline.
Advertisements

2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
3D Graphics Rendering and Terrain Modeling
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Transformations III Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Display Lists, Viewing.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures I Week 8, Mon.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Transformations III Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections I.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections IV.
Transformations II Week 2, Wed Jan 17
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Projections II Week 4,
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections III.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Lighting/Shading I Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections II.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Transformations II Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections III.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Lighting and Shading Week.
University of British Columbia CPSC 314 Computer Graphics May-June 2005 Tamara Munzner Viewing, Projections.
Transformations IV Week 3, Wed Jan 23
Graphics Programming: Polygon Filling
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Rasterization Week 6,
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Mon 6 Oct 2003 recap: Bresenham line algorithm scan.
Projections and Picking Wed 24 Sep 2003
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Viewing and Projections Wed 17 Oct 2003 project 1 recap: display lists viewing.
Scan Conversion Week 6, Wed 8 Oct 2003
University of British Columbia CPSC 414 Computer Graphics Week 3, Monday 15 Oct 03 © Tamara Munzner 1 Hierarchies, Display Lists recap: matrix hierarchies,
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Transformations III Week.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections I.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Viewing and Projections Mon 22 Sep 2003 project 1 solution demo recap: projections.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Midterm Review Week 7, Wed 16 Oct 2003 midterm review project 1 demos, hall.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
Part I: Basics of Computer Graphics Rendering Polygonal Objects (Read Chapter 1 of Advanced Animation and Rendering Techniques) Chapter
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Lighting and Shading Week.
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by Greg Humphreys)
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
COLLEGE OF ENGINEERING UNIVERSITY OF PORTO COMPUTER GRAPHICS AND INTERFACES / GRAPHICS SYSTEMS JGB / AAS 1 Shading (Shading) & Smooth Shading Graphics.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 14 Going-through.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Lighting/Shading I Week.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 5, Fri 3 Oct 2003 recap: shading scan conversion: lines.
Lecture 6 Rasterisation, Antialiasing, Texture Mapping,
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Viewing/Projections IV.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Rasterization II Week.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Viewing/Projections I.
Final Review I University of British Columbia
- Introduction - Graphics Pipeline
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
CS451Real-time Rendering Pipeline
Viewing/Projections I Week 3, Fri Jan 25
Transformations 6 University of British Columbia
Transformations IV Week 3, Wed Jan 20
Lecture 13 Clipping & Scan Conversion
Rasterization Week 6, Mon Feb 12
Transformations III Week 3, Mon Jan 21
Viewing/Projections I Week 3, Fri Jan 25
Transformations IV Week 3, Wed Jan 23
Clipping University of British Columbia CPSC 314 Computer Graphics
Presentation transcript:

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Prog 2, Kangaroo Hall of Fame, Midterm Review, (Interpolation if time) Week 6, Wed Feb 9

2 Program 2 Corrections/Clarifications handin 314 proj2 (not 414) ‘f’ not ‘s’ to toggle flat/smooth shading ‘s’ already in use for camera add: ‘t’ to toggle between randomly colored and grey terrain makes it easier to check if lighting correct add: ‘u’ to replace terrain with new randomly generated geometry consider adding for a bit of extra credit: ‘+/-’ toggle to increment/decrement abs cam speed

3 Program 2 Corrections/Clarifications roll/yaw confusion first para. correct, second para. wrong left horiz drag = yaw, right horiz drag = roll image + flying expertise courtesy of Matt Baumann

4 Program 2 Quick Demo

5 Review: Midpoint Algorithm moving incrementally along x direction draw at current y value, or move up to y+1? check if midpoint between two possible pixel centers above or below line candidates top pixel: (x+1,y+1), bottom pixel: (x+1, y) midpoint: (x+1, y+.5) check if midpoint above or below line below: top pixel above: bottom pixel assume, slope

6 Review: Bresenham Algorithm all integer arithmetic cumulative error function y=y0; e=0; for (x=x0; x <= x1; x++) { draw(x,y); if (2(e+dy) < dx) { e = e+dy; } else { y=y+1; e=e+dy-dx; }} y=y0; eps=0 for ( int x = x0; x = dx ){ y++; eps -= dx; } }

7 P Review: Flood Fill draw polygon edges, seed point, recursively set all neighbors until boundary is hit to fill interior drawbacks: visit pixels up to 4x, per-pixel memory storage needed

=0 P Review: Scanline Algorithms set pixels inside polygon boundary along horizontal lines one pixel apart use bounding box to speed up

9 Review: Edge Walking basic idea: draw edges vertically interpolate colors down edges fill in horizontal spans for each scanline at each scanline, interpolate edge colors across span

10 Review: General Polygon Rasterization idea: use a parity test for each scanline edgeCnt = 0; for each pixel on scanline (l to r) if (oldpixel->newpixel crosses edge) edgeCnt ++; // draw the pixel if edgeCnt odd if (edgeCnt % 2) setPixel(pixel);

11 Hall of Fame

12 But Wait, There’s More! nice comment :) this project is fun, only one of the very few that I actually enjoyed. Too bad there's only one CG course in UBC =( two fourth year CG courses await you! 424 Geometric Modelling 426 Animation

13 Midterm Review

14 Midterm Exam Friday Feb 11 10am-10:50am you may use one handwritten 8.5”x11” sheet one side of page no other notes, no books nonprogrammable calculators OK arrive on time! sit every other seat, ID out in front of you coats and bags in front of room

15 What’s Covered transformations viewing and projections coordinate systems of rendering pipeline lighting and shading not scan conversion

16 Reading FCS book, Red book see web page for details you can be tested on material in book but not covered in lecture you can be tested on material covered in lecture but not covered in book

17 Old Exams Posted see course web page

18 The Rendering Pipeline pros and cons of pipeline approach GeometryDatabaseGeometryDatabase Model/ViewTransform.Model/ViewTransform. LightingLightingPerspectiveTransform.PerspectiveTransform.ClippingClipping ScanConversionScanConversion DepthTestDepthTest TexturingTexturing BlendingBlending Frame-bufferFrame-buffer

19 Transformationstranslate(a,b,c) scale(a,b,c)

20 Homogeneous Coordinates x y w w=1

21 Composing Transformations Ta Tb = Tb Ta, but Ra Rb != Rb Ra and Ta Rb != Rb Ta

22 Composing Transformations example: rotation around arbitrary center

23 Composing Transformations example: rotation around arbitrary center step 1: translate coordinate system to rotation center

24 Composing Transformations example: rotation around arbitrary center step 2: perform rotation

25 Composing Transformations example: rotation around arbitrary center step 3: back to original coordinate system

26 Composing Transformations rotation about a fixed point p’ = TRT -1 p rotation around an arbitrary axis considering frame vs. object p’ = DCBAp object frame OpenGL: D C B A draw p

27 Transformation Hierarchies hierarchies don’t fall apart when changed transforms apply to graph nodes beneath

28 Matrix Stacks push and pop matrix stack avoid computing inverses or incremental xforms avoid numerical error World coordinates T 1 (x) T 2 (x) T 3 (x)

29 Matrix Stacks glPushMatrix() glPopMatrix() A B C A B C A B C C glScale3f(2,2,2) D = C scale(2,2,2) trans(1,0,0) A B C D DrawSquare() glTranslate3f(1,0,0) DrawSquare() glPushMatrix() glPopMatrix()

30 Transformation Hierarchies example x y glTranslate3f(x,y,0); glRotatef(,0,0,1); DrawBody();glPushMatrix(); glTranslate3f(0,7,0); glTranslate3f(0,7,0); DrawHead(); DrawHead();glPopMatrix();glPushMatrix(); glTranslate(2.5,5.5,0); glTranslate(2.5,5.5,0); glRotatef(,0,0,1); glRotatef(,0,0,1); DrawUArm(); DrawUArm(); glTranslate(0,-3.5,0); glTranslate(0,-3.5,0); glRotatef(,0,0,1); glRotatef(,0,0,1); DrawLArm(); DrawLArm();glPopMatrix();... (draw other arm)

31 Display Lists reuse block of OpenGL code more efficient than immediate mode code reuse, driver optimization good for static objects redrawn often can’t change contents not just for multiple instances interactive graphics: objects redrawn every frame nest when possible for efficiency

32 Double Buffering two buffers, front and back while front is on display, draw into back when drawing finished, swap the two avoid flicker

33 Projective Rendering Pipeline OCS - object coordinate system WCS - world coordinate system VCS - viewing coordinate system CCS - clipping coordinate system NDCS - normalized device coordinate system DCS - device coordinate system OCS WCS VCS CCS NDCS DCSmodelingtransformationviewingtransformationprojectiontransformationviewporttransformation alter w / w objectworld viewing/ camera device normalized device clipping perspectivedivision glVertex3f(x,y,z) glTranslatef(x,y,z)glRotatef(th,x,y,z)....gluLookAt(...) glFrustum(...) glutInitWindowSize(w,h)glViewport(x,y,a,b)

34 Projection theoretical pinhole camera imageplane eye point point – image inverted, more convenient equivalent imageplane eye point point

35 Projection Taxonomy planarprojections perspective:1,2,3-point parallel oblique orthographic cabinet cavalier top,front,side axonometric:isometricdimetrictrimetric

36 Projective Transformations transformation of space center of projection moves to infinity viewing frustum transformed into a parallelpiped -z x -z x Frustum

37 Normalized Device Coordinates left/right x =+/- 1, top/bottom y =+/- 1, near/far z =+/- 1 -z x Frustum z=-n z=-f right left z x x= -1 z=1 x=1 Camera coordinates NDC z= -1

38 Projection Normalization distort such that orthographic projection of distorted objects is desired persp projection -zxz x

39 Transforming View Volumes x z NDCS y (-1,-1,-1) (1,1,1) orthographic view volume x z VCS y x=left y=top x=right z=-far z=-near y=bottom perspective view volume x=left x=right y=top y=bottom z=-near z=-far x VCS y

40 Basic Perspective Projection similar triangles z P(x,y,z) P(x’,y’,d) z=d y also nonuniform foreshortening not affine but

41 Basic Perspective Projection can express as homogenous 4x4 matrix!

42 Projective Transformations determining the matrix representation need to observe 5 points in general position, e.g. [left,0,0,1] T  [-1,0,0,1] T [0,top,0,1] T  [0,1,0,1] T [0,0,-f,1] T  [0,0,1,1] T [0,0,-n,1] T  [0,0,-1,1] T [left*f/n,top*f/n,-f,1] T  [-1,1,1,1] T solve resulting equation system to obtain matrix

43 OpenGL Orthographic Matrix scale, translate, reflect for new coord sys understand derivation from VCS!

44 OpenGL Perspective Matrix shear, scale, reflect for new coord sys understand derivation from VCS!

45 Viewport Transformation x (0,0)(w,h)DCS a b y (0,0) (w,h) DCS a bxy (-1,-1) (1,1) NDCS xy display viewportxy onscreen pixels: map from [-1,1] to [0, displaywidth] DCS confusion on hw pixel locations should not be negative or huge!

46 Light Sources directional/parallel lights point at infinity: (x,y,z,0) T point lights finite position: (x,y,z,1) T spotlights position, direction, angle ambient lights

47 Reflectance specular: perfect mirror with no scattering gloss: mixed, partial specularity diffuse: all directions with equal energy + + = specular + glossy + diffuse = reflectance distribution

48 Review: Reflection Equations I diffuse = k d I light (n l) nl  2 ( N (N · L)) – L = R

49 Review: Reflection Equations 2 Blinn improvement full Phong lighting model combine ambient, diffuse, specular components lnv h

50 Lighting vs. Shading lighting simulating the interaction of light with surface shading deciding pixel color continuum of realism: when do we do lighting calculation?

51 Shading Models flat shading compute Phong lighting once for entire polygon Gouraud shading compute Phong lighting at the vertices and interpolate lighting values across polygon Phong shading compute averaged vertex normals interpolate normals across polygon and perform Phong lighting across polygon

52 apply nonuniform scale: stretch along x by 2 can’t transform normal by modelling matrix solution: Transforming Normals normal to any surface transformed by inverse transpose of modelling transformation

53 Interpolation

54 Scan Conversion done: how to determine pixels covered by a primitive next: how to assign pixel colors interpolation of colors across triangles interpolation of other properties

55 Interpolation During Scan Conversion interpolate values between vertices z values r,g,b colour components use for Gouraud shading u,v texture coordinates surface normals equivalent methods (for triangles) bilinear interpolation barycentric coordinates

56 Bilinear Interpolation interpolate quantity along L and R edges, as a function of y then interpolate quantity as a function of x y P(x,y) P1P1P1P1 P2P2P2P2 P3P3P3P3 PLPLPLPL PRPRPRPR

57 3. Barycentric Coordinates weighted combination of vertices (1,0,0) (0,1,0) (0,0,1) “convex combination of points” of points”

58 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1 Computing Barycentric Coordinates for point P on scanline

59 Computing Barycentric Coords similarly b 1 : b 2 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1

60 b 1 : b 2 P2P2P2P2 P3P3P3P3 P1P1P1P1 PLPLPLPL PRPRPRPR P d 2 : d 1 c 1 : c 2 Computing Barycentric Coords combining gives

61 Computing Barycentric Coords thus

62 Computing Barycentric Coords can verify barycentric properties