CS148: Introduction to Computer Graphics and Imaging

Slides:



Advertisements
Similar presentations
15.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 15 – Visible Surfaces and Shadows.
Advertisements

9.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture.
8.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 8 Polygon Rendering.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Computer Graphics Visible Surface Determination. Goal of Visible Surface Determination To draw only the surfaces (triangles) that are visible, given a.
I3D Fast Non-Linear Projections using Graphics Hardware Jean-Dominique Gascuel, Nicolas Holzschuch, Gabriel Fournier, Bernard Péroche I3D 2008.
1 Lecture 4 Graphical primitives Rasterization: algorithmic approach Rasterization: geometric approach 2D discrete lines, triangles Discrete planes 3D.
Gopi -ICS186AW03 - Slide1 Graphics Pipeline: First Pass.
Rasterization May 14, Triangles Only We will discuss the rasterization of triangles only. Why? –Polygon can be decomposed into triangles. –A triangle.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Textures – Magnification and Minification Lecture 30 Mon, Nov 17, 2003.
CS 445 / 645 Introduction to Computer Graphics Lecture 18 Shading Shading.
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.
COMP 175: Computer Graphics March 24, 2015
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
COMP 261 Lecture 16 3D Rendering. input: set of polygons viewing direction direction of light source(s) size of window. output: an image Actions rotate.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
CAP4730: Computational Structures in Computer Graphics
Computer Graphics Basic 3D Geometry CO2409 Computer Graphics Week 5-1.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
Basic Ray Tracing CMSC 435/634.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
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.
CS559: Computer Graphics Lecture 27: Texture Mapping Li Zhang Spring 2008 Many slides from Ravi Ramamoorthi, Columbia Univ, Greg Humphreys, UVA and Rosalee.
Lecture 6 Rasterisation, Antialiasing, Texture Mapping,
Computer Graphics, KKU. Lecture 41 The Computer Programming Laws Any given program, when running, is obsolete. Any given program costs more and.
Chapter III Rasterization
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Lecture 15: Raster Graphics and Scan Conversion
Introduction to Meshes Lecture 22 Mon, Oct 20, 2003.
Lecture 13: Raster Graphics and Scan Conversion
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 5 Hidden Surface Removal and Rasterization Taku Komura.
2 3D Viewing Process  3D viewing process MC Model Space Model Transformation Model Transformation WC World Space Viewing Transformation Viewing Transformation.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition Chapter 14.
Basic Ray Tracing CMSC 435/634.
Rendering Pipeline Fall, 2015.
Good practices that help minimize the need for debugging
Constructing Objects in Computer Graphics
Week 2 - Friday CS361.
Hidden Surface Removal
CS G140 Graduate Computer Graphics
Intro to 3D Graphics.
3D Graphics Rendering PPT By Ricardo Veguilla.
Constructing Objects in Computer Graphics By Andries van Dam©
CS451Real-time Rendering Pipeline
Lecture 03: Linear Algebra
Fitting Curve Models to Edges
Agenda Polygon Terminology Types of polygons Inside Test
Digital Media Dr. Jim Rowan ITEC 2110.
Introduction to Computer Graphics
Projection in 3-D Glenn G. Chappell
Lecture 13 Clipping & Scan Conversion
Chapter VII Rasterizer
Introduction to Meshes
Shading Polygons Lecture 36 Wed, Nov 28, 2007.
CS5500 Computer Graphics April 24, 2006.
Introduction to Artificial Intelligence Lecture 22: Computer Vision II
Introduction to Meshes
Presentation transcript:

CS148: Introduction to Computer Graphics and Imaging Triangles CS148 Lecture 3

How to draw a triangle on the screen Rasterization CS148 Lecture 3

Window edges at integers Pixel Coordinates Window edges at integers y (4,3) Pixels inside window (0,1) (1,1) (0,0) (1,0) x

Pixel Coordinates OpenGL: Pixel centers correspond to half-integer coordinates y (.5, 1.5) (1.5, 1.5) (1.5, .5) (.5, .5) Note: Other graphics packages may use a different convention x

Triangle Rasterization Rule Output fragment if pixel center is inside the triangle CS148 Lecture 3

Triangle Rasterization rasterize( vert v[3] ) { for( int y=0; y<YRES; y++ ) for( int x=0; x<XRES; x++ ) if( inside3(v,x,y) ) fragment(x,y); } v0 l2 l1 Get rid of bounds l0 v2 v1 CS148 Lecture 3

Normal to the Line CS148 Lecture 3 Break into three slides. First, just p0, p1, and t Second, define Perp Third, Explain the function Perp(t) Perp((x,y)) = (-y,x) Line orientation is backwards; inside is normally to the left CS148 Lecture 3

Line Equation This equation must be true for all point p on the line Convention that n points to the left as we move from p0 to p1 Half-plane equation Show this derivation This equation must be true for all point p on the line CS148 Lecture 3

Line Divides Plane into 2 Half-Spaces Normal n points to the right of the line; Inside (negative values) to the left of the line. CS148 Lecture 3

Make a Line from Two Vertices makeline( vert& v0, vert& v1, line& l ) { l.a = v1.y - v0.y; l.b = v0.x - v1.x; l.c = -(l.a * v0.x + l.b * v0.y); } V1.y * v0.x– v1.x*v0.y If inside all three lines int mkedgev( e, x1, y1, x2, y2 ) struct edge *e; value x1, y1; value x2, y2; { e->a = -(y1 - y2); e->b = (x1 - x2); e->c = -(e->a * x1 + e->b * y1); e->v = 0.; }   v0 v1 l CS148 Lecture 3

Triangle Orientation v1 v2 v0 v1 v0 v2 CW (Back Facing) CCW (Front Facing) Convention: Inside a CCW polygon is equivalent to inside every lines of the polygon (on their left) CS148 Lecture 3

Point Inside Triangle Test rasterize( vert v[3] ) { line l0, l1, l2; makeline(v[0],v[1],l2); makeline(v[1],v[2],l0); makeline(v[2],v[0],l1); for( y=0; y<YRES; y++ ) { for( x=0; x<XRES; x++ ) { e0 = l0.a * x + l0.b * y + l0.c; e1 = l1.a * x + l1.b * y + l1.c; e2 = l2.a * x + l2.b * y + l2.c; if( e0<=0 && e1<=0 && e2<=0 ) fragment(x,y); } v0 l2 l1 l0 v2 v1 CS148 Lecture 3

Singularities Singularities: Edges that touch pixels (e == 0) Causes two fragments to be generated Wasted effort drawing duplicated fragments Problems with transparency (later lecture) Not including singularities (e < 0) causes gaps CS148 Lecture 3

Handling Singularities Create shadowed edges (thick lines) Don’t draw pixels on shadowed edges Solid drawn; hollow not drawn int shadow( line l ) { return (l.a>0) || (l.a == 0 && l.b > 0); } int inside( value e, line l ) { return (e == 0) ? !shadow(l) : (e < 0); CS148 Lecture 3

Better Point Inside Triangle Test rasterize( vert v[3] ) { line l0, l1, l2; makeline(v[0],v[1],l2); makeline(v[1],v[2],l0); makeline(v[2],v[0],l1); for( y=0; y<YRES; y++ ) { for( x=0; x<XRES; x++ ) { e0 = l0.a * x + l0.b * y + l0.c; e1 = l1.a * x + l1.b * y + l1.c; e2 = l2.a * x + l2.b * y + l2.c; if( inside(e0,l0)&&inside(e1,l1)&&inside(e2,l2) ) fragment(x,y); } v0 l2 l1 l0 v2 v1 CS148 Lecture 3

Compute Bounding Rectangle (BBox) bound3( vert v[3], bbox& b ) { b.xmin = ceil(min(v[0].x, v[1].x, v[2].x)); b.xmax = ceil(max(v[0].x, v[1].x, v[2].x)); b.ymin = ceil(min(v[0].y, v[1].y, v[2].y)); b.ymax = ceil(max(v[0].y, v[1].y, v[2].y)); } Calculate tight bound around the triangle Round coordinates upward (ceil) to the nearest integer CS148 Lecture 3

Compute Bounding Rectangle (BBox) bound3( vert v[3], bbox& b ) { b.xmin = ceil(min(v[0].x, v[1].x, v[2].x)); b.xmax = ceil(max(v[0].x, v[1].x, v[2].x)); b.ymin = ceil(min(v[0].y, v[1].y, v[2].y)); b.ymax = ceil(max(v[0].y, v[1].y, v[2].y)); } Tested points indicated by filled circles Don’t need to test hollow circles CS148 Lecture 3

More Efficient Bounding Box Version rasterize( vert v[3] ) { bbox b; bound3(v, b); line l0, l1, l2; makeline(v[0],v[1],l2); makeline(v[1],v[2],l0); makeline(v[2],v[0],l1); for( y=b.ymin; y<b.ymax, y++ ) { for( x=b.xmin; x<b.xmax, x++ ) { e0 = l0.A * x + l0.B * y + l0.C; e1 = l1.A * x + l1.B * y + l1.C; e2 = l2.A * x + l2.B * y + l2.C; if( inside(e0,l0)&&inside(e1,l1)&&inside(e2,l2) ) fragment(x,y); } CS148 Lecture 3

Interpolation Convert discrete values to a continuous function by filling in “in between” values CS148 Lecture 3

Linear Interpolation 0 1 CS148 Lecture 3 0 1 let’s say we have points y1 and y2 and we want to move smoothly between the two. one way to do this is via the line connecting the two points CS148 Lecture 3

Barycentric Interpolation Edge talk about balance point of the triangle negative mass? Triangle CS148 Lecture 3

Barycentric Interpolation on Triangles Can be used to interpolate colors r = a0 r0 + a1 r1 + a2 r2 g = a0 g0 + a1 g1 + a2 g2 b = a0 b0 + a1 b1 + a2 b2 Can be used to interpolate texture coordinates u = a0 u0 + a1 u1 + a2 u2 v = a0 v0 + a1 v1 + a2 v2 Can be used to interpolate z or depth z = a0 z0 + a1 z1 + a2 z2 Can be used to interpolate normals… CS148 Lecture 3

Finding Barycentric Coordinates CS148 Lecture 3

How to Compute Triangle Area B A CS148 Lecture 3

Barycentric Coordinates: Linear System Determinant of matrix is equal to zero if the points are co-linear CS148 Lecture 3

Barycentric Coordinates: Basis Vectors CS148 Lecture 3

Barycentric Coordinates vs. Basis Vector Coordinates A point p inside triangle p0p1p2 can be expressed using barycentric coordinates as Point p can also be expressed in the basis vector coordinates (of last slide as) Therefore, we get the relations CS148 Lecture 3