H331: Computer Graphics Philip Dutré Department of Computer Science Wednesday, February 25.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
Clipping Lines Lecture 7 Wed, Sep 10, The Graphics Pipeline From time to time we will discuss the graphics pipeline. The graphics pipeline is the.
CS 4731: Computer Graphics Lecture 4: 2D Graphic Systems
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools Ureerat Suksawatchon Department of Computer.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
Ch 1 Intro to Graphics page 1CS 367 First Day Agenda Best course you have ever had (survey) Info Cards Name, , Nickname C / C++ experience, EOS experience.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
1 Chapter 1: Graphics Systems and Models. 2 Applications of C. G. – 1/4 Display of information Maps GIS (geographic information system) CT (computer tomography)
1 Computer Graphics Week3 –Graphics & Image Processing.
Drawing Basic Graphics Primitives Lecture 4 Wed, Sep 3, 2003.
CSE 381 – Advanced Game Programming Basic 3D Graphics
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
CGMB214: Introduction to Computer Graphics
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
2D Coordinate Systems and Drawing
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Implementation of a Renderer Consider Programs are processd by the system line & polygon, outside the view volume Efficiently Understanding of the implementation.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
1 Chapter 1: Graphics Systems and Models. 2 Applications of C. G. – 1/4 Display of information Maps GIS (geographic information system) CT (computer tomography)
1 Perception and VR MONT 104S, Fall 2008 Lecture 20 Computer Graphics and VR.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization.
Drawing and Coordinate Systems. Coordinate Systems Screen Coordinate system World Coordinate system World window Viewport Window to viewport mapping.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
Lecture 13: Raster Graphics and Scan Conversion
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools PART I.
Chapter 1 Graphics Systems and Models Models and Architectures.
OUTPUT PRIMITIVES A.Aruna/Faculty of Information technology/SNSCE13/19/2016.
Chapter #03 More Drawing Tools 1. Viewport 2 Do not have use the entire window for the image: glViewport(x,y,w,h) Values in pixels (screen coordinates)
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics Shading in OpenGL
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Programming with OpenGL Part 2: Complete Programs
Chapter #03 More Drawing Tools.
OpenGL API 2D Graphic Primitives
Models and Architectures
Implementation I Ed Angel
Programming with OpenGL Part 2: Complete Programs
Models and Architectures
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Coordinate Systems and Transforming the Coordinates
Lecture 13 Clipping & Scan Conversion
Models and Architectures
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Implementation I Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

H331: Computer Graphics Philip Dutré Department of Computer Science Wednesday, February 25

Today u Graphics programming u Book: Chapters 3, 4, 10

Announcements u Practicum 1 available – u Practicum 1 & 2: 7 points / 20 –Best: 4 –2 nd best: 3

Announcements u SIGGRAPH Los Angeles August 8-12 u u Student volunteers! (Deadline: February 25)

3D  2D u How to transform the 3D world to a 2D image? u 3 aspects: –Objects: exist in space, independent of viewer –Viewer: camera, human, …. –Lights: shading, shadows, …

3D  2D Objects (points, lines, polygons) Described by vertices Lights (e-m spectrum) ( nm) Viewer = camera

Pinhole camera

Synthetic Camera Projection plane in front of center-of-projection:

Synthetic Camera Clipping: looking through a window

3D APIs u Synthetic camera is basis of 3D API –OpenGL, PHIGS, Direct 3D, VRML, JAVA-3D, GKS, … u We need to functions to specify: –Objects: vertices that describe points, lines, polygons –Camera: position, orientation, width, height –Light sources: position, color –Materials: reflection characteristics

3D APIs glBegin(GL_POLYGON) glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.1); glEnd(); … gluLookAt(posx, posy, posz, atx, aty, atz, …); glPerspective(view_angle, …);

3D APIs u 3D API performs modeling + rendering u But … modeling can also be done ‘off-line’ –Write model to file –Read file in 3D API and transform to 3D API modeling commands u RenderMan (Pixar) –Prepares off-line model for rendering –Rendering takes ‘converted’ model

Graphics hardware u 3D ‘world’ coordinates  2D ‘screen’ coordinates

Graphics hardware u 3D vertex  2D pixel Transform to camera coordinate system Clip away things we don’t see in the camera window 3D coordinates  2D coordinates Transform to pixels in the frame buffer

How to draw things? u Given: window on the screen u Graphics API (e.g. OpenGL) has something of the form: plotPixel(int x, int y)

How to draw things? u plotPixel(289,190) u plotPixel(320,128) u plotPixel(239,67) u plotPixel(194,101) u plotPixel(129,83) u plotPixel(75,73) u plotPixel(74,74) u plotPixel(20,10) window

How to draw things? window screen x y plotPixel(x,y) X Y

Why is this impractical? u Coordinates are expressed in screen space, but objects live in (3D) world space u Resizing window implies we have to change coordinates of objects to be drawn u We want to make a separation between: –values to describe geometrical objects –values needed to draw these objects on the screen

How to draw things? u Specify points to OpenGL glVertex*( … ) glVertex2i( … )glVertex3i( … ) glVertex2f( … )glVErtex3f( … ) glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd(); glBegin(GL_POINTS); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd();

How to draw things? For (k=0; k<500; k++) { … // compute point k x = …; y = …; glBegin(GL_POINTS); glVertex2f(x, y); glEnd(); } glFlush();

More about OpenGL… u OpenGl = set of libraries

More about OpenGL… u OpenGl supports geometric primitives and raster primitives

Geometric Primitives in OpenGL u Geometric primitives are defined by vertices –GL_POINTS –GL_LINES –GL_LINE_STRIP, GL_LINE_LOOP

Geometric Primitives in OpenGL u Closed loops = polygons u Polygons: describe surfaces

Geometric Primitives in OpenGL u GL_POLYGON, GL_QUADS, …

Viewing in OpenGL u Scene is independent of camera u gluOrtho2D(left, tight, bottom, top)

3D primitives void triangle(point3 a, point3 b, point3 c) { glBegin(GL_POLYGON) glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); glEnd(); } void tetrahedron () { glColor3f(1.0,0.0,0.0); triangle(v[0], v[1], v[2]); … }

3D primitives u Hidden surfaces? u Z-buffer –Keep depth for each pixel u Initialize! –glClear(GL_COLOR_BUFFER_BIT); –glClear(GL_DEPTH_BUFFER_BIT); –… –glFlush();

World window & viewport u World window: specifies what part of the world should be drawn u Viewport: rectangular area in the screen window in which we will draw

World window & viewport window viewport screen window world window

Mapping: world window to viewport window WlWr Wb Wt VlVr Vb Vt

Mapping: world window to viewport window WlWr Wb Wt VlVr Vb Vt Maintain proportions!

Mapping: world window to viewport WlWr VlVr xsx

Mapping: world window to viewport u If x = Wl, then sx = Vl u If x = Wr, then sx = Vr u If x = f*(Wr-Wl), then sx = f*(Vr-Vl) u If x < Wl, then sx < Vl u If x > Wr, then sx > Vr u … also for y and sy

World window u Pick size automatically world window

Automatic setting to preserve aspect ratio & center window W H Aspect ratio R R > W/H

Automatic setting to preserve aspect ratio & center window Aspect ratio R R < W/H W H

Clipping u Lines outside of world window are not to be drawn. u Graphics API clips them automatically. u But clipping is a general tool in graphics!

Clipping

clipSegment(…): u Return 1 if line within window u Return 0 if line outside window u If line partially inside, partially outside: clip and return 1 A B C D E

Cohen-Sutherland clipping u Trivial accept/reject test! Trivial reject Trivial accept

Cohen-Sutherland region outcodes u 4 bits: TTFF Left of window? Above window? Right of window? Below window?

Cohen-Sutherland region outcodes u Trivial accept: both endpoints are FFFF u Trivial reject: both endpoints have T in the same position FFFF TTFF TFFF FTTFFTFF TFFTFFTT FFTF FFFT

Cohen-Sutherland: chopping u If segment is neither trivial accept or reject: –Clip against edges of window in turn

Cohen-Sutherland: chopping Trivial accept

Cohen-Sutherland line clipper u int clipSegment (point p1, point p2) Do { If (trivial accept) return (1) If (trivial reject) return (0) If (p1 is outside) if (p1 is left) chop left else if (p1 is right) chop right … If (p2 is outside) … } while (1)

Raster Graphics u What is an image? –Array of pixels u How to convert lines and polygons to pixels? –Continuous to discrete –Scan conversion

Displays u Early displays were vector displays –Electron beam traces lines –Image is sequence of endpoints –Wireframes, no solid fills

Displays u Raster displays –Electron beam traces regular pattern –Image is 2D array of pixels –Fast, but discretisation errors u Every pixel has b bits for color –B&W: 1 bit –Basic colors: 8, 15, 16, 24 bits –High-end: 96 bits

Displays

Displays and Framebuffers u Raster image is stored in memory as a 2D array of pixels = framebuffer u The color of each pixel determines the intensity of the beam u Video hardware scans framebuffer at 60Hz –Changes in framebuffer show on screen => double buffering –Switch buffers when one buffer is finished

Displays and Framebuffers Video controller Framebuffer (double buffer) display Graphics software (rasterizer)

Rasterizer: Example u How to rasterize a line, once its 2D screen coordinates are known? u Given: endpoints of a line u What pixels to draw?

Scan converting lines

u find the pixels closest to the ideal line u assume slope  m   1: illuminate one pixel per column, work incrementally u if  m  1 : x  y.

Scan converting lines y = y1; for (i = x1; i<=x2; i++) { plotPixel(i, round(y)); y += m; }

Scan converting lines u Inefficient: compute round(y) for each integer x and floating point addition u Bresenham’s algorithm: only integer arithmetic u Standard for most HW+SW rasterizers

Scan converting lines u What’s the next pixel? u Decision variable d = a – b if (d>0) … else …  Or d =  x(a-b)

Scan converting lines  d k+1 = d k – 2  y or d k+1 = d k – 2(  y-  x)