Rendering Pipeline/ OpenGL

Similar documents
Rendering Pipeline/ OpenGL

OpenGL/GLUT Intro. Week 1, Fri Jan 12

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Outline. Intro. Week 1, Fri Jan 4. What is CG used for? What is Computer Graphics? University of British Columbia CPSC 314 Computer Graphics Jan 2013

Intro. Week 1, Fri Jan 4

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Precept 2 Aleksey Boyko February 18, 2011

Graphics Programming

Basic Graphics Programming

Lecture 4 of 41. Lab 1a: OpenGL Basics

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

Basic Graphics Programming

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

OpenGL refresher. Advanced Computer Graphics 2012

Exercise 1 Introduction to OpenGL

CHAPTER 1 Graphics Systems and Models 3

Graphics Hardware and OpenGL

Graphics Pipeline 2D Geometric Transformations

CS559: Computer Graphics. Lecture 12: OpenGL Li Zhang Spring 2008

Computer Graphics Introduction. Taku Komura

Computer Graphics. Instructor: Oren Kapah. Office Hours: T.B.A.

CSC 8470 Computer Graphics. What is Computer Graphics?

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

CS 4204 Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University

The Traditional Graphics Pipeline

2 Transformations and Homogeneous Coordinates

1.2 Basic Graphics Programming

Graphics Pipeline & APIs

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations


Graphics Pipeline & APIs

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

OpenGL. Toolkits.

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

CS451Real-time Rendering Pipeline

The Traditional Graphics Pipeline

Introduction to Computer Graphics with OpenGL/GLUT

Pipeline Operations. CS 4620 Lecture 10

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Pipeline Operations. CS 4620 Lecture 14

Introduction to Computer Graphics with WebGL

Announcements OpenGL. Computer Graphics. Spring CS4815

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Rendering. Part 1 An introduction to OpenGL

The Traditional Graphics Pipeline

Computer Graphics and Visualization. Graphics Systems and Models

CSC 470 Computer Graphics

CS 464 Review. Review of Computer Graphics for Final Exam

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Lecture 3. Understanding of OPenGL programming

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Intro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin

Computer Graphics (Basic OpenGL)

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Transformation Pipeline

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

OpenGL Transformations

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Models and Architectures

3D Graphics and OpenGl. First Steps

CSE4030 Introduction to Computer Graphics

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Visualizing Molecular Dynamics

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Computer Graphics Fundamentals. Jon Macey

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CIS 581 Interactive Computer Graphics

Lectures OpenGL Introduction

Introduction to OpenGL

Graphics and Interaction Rendering pipeline & object modelling

3D computer graphics: geometric modeling of objects in the computer and rendering them

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Lahore University of Management Sciences. CS 452 Computer Graphics

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

CIS 581 Interactive Computer Graphics (slides based on Dr. Han-Wei Shen s slides) Requirements. Reference Books. Textbook

yahoo.com

Drawing Primitives. OpenGL basics

Interaction. CSCI 480 Computer Graphics Lecture 3

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Sign up for crits! Announcments

Lecture 1. Computer Graphics and Systems. Tuesday, January 15, 13

RECITATION - 1. Ceng477 Fall

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Interaction Computer Graphics I Lecture 3

Computer Graphics I Lecture 11

Transcription:

Chapter 2 Basics of Computer Graphics: Course Info/Policies (boring stuff): Course Info/Policies (boring stuff): http:www.ugrad.cs.ubc.ca/~cs314 Page 1 1

Grading Programming Assignments: 40% Weekly Mini i Home Quizes: 3% Participation 2% Classroom Review question composition Two Midterms: 25% 12% +13% computer graphics expert Final Exam: 30% Grading Programming Assignments: 40% 2D Game: Intro to (6%) out now 3D Transformations modeling/animation (11%) Rendering pipeline (11%) Ray tracing (12%) computer graphics expert Page 2 2

Grading Participation (2%) Classroom: Clicke responses + classroom involvement Post two weekly review questions Based on material covered each week Submit via DB (private, rev# tag) till Mon 9AM Include: question, multiple choice answers, explanation Grading Mini Home Quizes: (3%) Online (connect.ubc.ca) quiz each week (from week 2) Released by Tue AM, Due Friday 9AM Multiple choice questions Student/instructor composed If your question selected - double your quiz grade!!! If two selected triple.. computer graphics expert Page 3 3

Important Dates Assignment 1 due: Sep 21 Assignment 2 due: Oct 12 Assignment 3 due: Nov 2 Assignment 4 due: Nov 30 Midterm 1: Oct 19 Midterm 2: Nov 9 Course Organization Programming assignments: C++, Windows or Linux Tested on department Linux machines graphics library / GLUT for user interface Face to face grading in lab Opportunity to show all the cool extra stuff Test that you do know what every piece of your code does Hall of fame coolest projects from 2002 on Page 4 4

Late/Missing Work Programming Assignments: 3 grace days TOTAL for unforeseen circumstances strong recommendation: don t use early in term handing in late uses up automatically unless you tell us Home Quizes/Review Question Sets Can miss two of each Exception: severe illness/crisis, as per UBC rules MUST Get approval from me ASAP (in person or email) Turn in proper documentation Literature (optional) Fundamentals of Computer Graphics Third edition (second is OK too but note syllabus changes) Peter Shirley, A.K. Peters Programming g Guide J. Neider, T. Davis and W. Mason, Addison- Wesley Page 5 5

Learning This is a graphics course using not a course ON Upper-level class: learning APIs mostly on your own only minimal lecture coverage basics, some of the tricky bits Red Book many tutorial sites on the web http://www.xmission.com/~nate/opengl.html Plagiarism and Cheating Short Summary: Don t cheat Home quizes and programming assignments are individual work Can discuss ideas (including on DB), browse Web But cannot copy code or answers/questions If you REALLY think using a source is OK cite it Must be able to explain algorithms during faceto-face demo or no credit for that assignment, possible prosecution Page 6 6

Basics of Computer Graphics: Rendering Pipeline Rendering Goal: Transform (3D) computer models into images Photo-realistic (or not) Interactive rendering: Fast, but until recently low quality Roughly follows a fixed patterns of operations Offline rendering: Ray-tracing Global illumination Rendering Pipeline Page 7 7

Rendering Tasks (no particular order) Project 3D geometry onto image plane Geometric transformations Determine which primitives/parts of primitives are visible Hidden surface removal Determine which pixels geometric primitive covers Scan conversion Compute color of every visible surface point Lighting, shading, texture mapping The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 8 8

Rendering Pipeline Abstract model of sequence of operations to transform geometric ti model linto digital it limage graphics hardware workflow Underlying API (application programming interface) model for programming graphics hardware Direct 3D Actual implementations vary Advantages of pipeline structure? Logical separation of different components, modularity Easy to parallelize: Earlier stages can already work on new data while later stages still work with previous data Similar to pipelining in modern CPUs But much more aggressive parallelization possible (special purpose hardware!) Important for hardware implementations! Only local knowledge of the scene is necessary Page 9 9

Disadvantages? Limited flexibility Some algorithms would require different ordering of pipeline stages Hard to achieve while still preserving compatibility Only local knowledge of scene is available Shadows Global illumination (Tentative) Lecture Syllabus Introduction + Rendering Lighting Models (week 8) Pipeline (week 1/2) Texture mapping (week 9/10) Transformations (week 2/3) Review & Midterm (week 10) Scan Conversion (week 4/5) Midterm: Nov 9 Clipping (week 5) Ray Tracing (week 11) Hidden Surface Removal Shadows (week 11/12) (week 6/7) Modeling (content creation) Review & Midterm (week 7) (week 12/13) Midterm: Oct 19 Review (last lecture) Page 10 10

Rendering Pipeline Implementation: /GLut API for graphics hardware Started in 1989 by Kurt Akeley Designed to exploit graphics hardware Implemented on many different platforms Pipeline processing Event driven Communication via state setting Page 11 11

GLUT: Utility Toolkit Event driven!!! int main(int argc, char **argv) { // Initialize GLUT and open a window. glutinit(&argc, argv); glutinitdisplaymode(glut_rgb GLUT_DOUBLE); glutinitwindowsize(800, 600); glutcreatewindow(argv[0]); // Register a bunch of callbacks for GLUT events. glutdisplayfunc(display); glutreshapefunc(reshape); // Pass control to GLUT. glutmainloop(); } return 0; Event-Driven Programming Main loop not under your control vs. procedural Control flow through event callbacks redraw the window now key was pressed mouse moved Callback functions called from main loop when events occur mouse/keyboard, redrawing Page 12 12

Graphics State (global variables) Set state once, remains until overwritten glcolor3f(1.0, 1.0, 0.0) set color to yellow glsetclearcolor(0.0, 0.0, 0.2) dark blue bg glenable(light0) turn on light glenable(gl_depth_test) hidden surf. /GLUT Example void display(void) {// Called when need to redraw screen. // Clear the buffer we will draw into. glclearcolor(0, 0, 0, 1); glclear(gl_color_buffer_bit); // Initialize the modelview matrix. glmatrixmode(gl_modelview); glloadidentity(); // Draw STUFF } // Make the buffer we just drew into visible. glutswapbuffers(); Page 13 13

GLUT Example int main(int argc, char *argv[]) {... // Schedule the first animation callback ASAP. gluttimerfunc(0, animate, 0); // Pass control to GLUT. glutmainloop(); return 0; } void animate(int last_frame = 0) { // Do stuff // Schedule the next frame. int current_time = glutget(glut_elapsed_time); int next_frame = last_frame + 1000 / 30; gluttimerfunc(max(0, next_frame - current_time), animate, current_time); } GLUT Input Events // you supply these kind of functions void reshape(int w, int h); void keyboard(unsigned char key, int x, int y); void mouse(int but, int state, int x, int y); // register them with glut glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmousefunc(mouse); Page 14 14

GLUT and GLU primitives glusphere(...) glucylinder(...) glutsolidsphere(gldouble radius, GLint slices, GLint stacks) glutwiresphere(...) glutsolidcube(gldouble size) glutwirecube(...) glutsolidtorus(...) glutwiretorus(...) glutsolidteapot(...) glutwireteapot(...) Note: Have limited set of parameters Control via global transformations (see a1 template) Need to save/restore setting GLUT and GLU primitives Example (from a1): void Pad::draw() { glcolor3f(1, 1, 1); glpushmatrix(); Save previous state gltranslatef(x_, y_, 0); glscalef(width_, height_, 1); glnormal3f(0, 0, 1); glbegin(gl_quads); glvertex3f(-0.5, -0.5, 0); glvertex3f(-0.5, 0.5, 0); glvertex3f(0.5, 0.5, 0); glvertex3f(0.5, -0.5, 0); glend(); glpopmatrix(); Restore previous state } Page 15 15

GLUT and GLU primitives Basic Transformations: // Different basic transformations gltranslatef( ); glrotatef( ); glscalef( ); Your tasks for the weekend Piazza Discussion Group: Register Post review questions by Mon 9AM Use private option, rev1 tag Assignment 1 Test programming environment on lab computers/set laptop environment (optional) Should have all the necessary background after this class Page 16 16

Your tasks for the weekend Sign and Submit Plagiarism Form http://www.ugrad.cs.ubc.ca/~cs314/vsep2012/plag.html Optional reading (Shirley: Introduction to CG) Math refresher: Chapters 2, 4 Lots of math coming in the next few weeks Background on graphics: Chapter 1 Assignment 1 Experience & GLUT Have FUN Description: http://www.ugrad.cs.ubc.ca/~cs314/vsep2012/a1/a1.pdf Deadline: Sep 21 Page 17 17

Rendering Pipeline in (More) Detail The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 18 18

3D Content Needs to represent models for Shapes (objects) Relations between different shapes Object materials Light sources Camera Shapes Different philosophies: Volumetric Boolean algebra with volumetric primitives Spheres, cones, cylinders, tori, Boundary representation Single basic primitive Triangles or triangle meshes, points, lines Higher order surface primitives with adjustable parameters E.g. all polynomials of degree 2 Splines, NURBS (details in CPSC 424) Implicits Page 19 19

Curves/Surfaces Mathematical representations: Explicit functions Parametric functions Implicit functions Explicit Functions Curves: y is a function of x: Only works in 2D y sin(x) Surfaces: z is a function of x and y: z sin( x) cos( y) Cannot define arbitrary shapes in 3D Page 20 20

Parametric Functions Curves: 2D: x and y are functions of a parameter value t 3D: x, y, and z are functions of a parameter value t cos( t) C ( t ) sin( t ) t Parametric Functions Surfaces: Surface S is defined as a function of parameter values s, t Names of parameters can be different to match intuition: cos( )cos( ) S (, sin( )cos( ) sin( ) Page 21 21

Shapes Implicit Surfaces: Surface defined by zero set (roots) of function E.g: S( x, y, z) : x 2 y 2 z 2 1 0 Shapes Triangles and Triangle Meshes: How to define a triangle? Page 22 22

Open GL: (Some) Shape Primitives glpointsize( float size); gllinewidth( float width); glcolor3f( float r, float g, float b);... TRIANGLE... glcolor3f(0,1,0); glbegin( GL_TRIANGLES ); glvertex3f( 0.0f, 0f 0.5f, 0.0f 0f ); glvertex3f( -0.5f, -0.5f, 0.0f ); glvertex3f( 0.5f, -0.5f, 0.0f ); glend(); Shape Primitives How to interpret geometry glbegin(<mode of geometric primitives>) mode = GL_ TRIANGLE, GL_ POLYGON, etc. Feed vertices glvertex3f(-1.0, 0.0, -1.0) glvertex3f(1.0, 0.0, -1.0) glvertex3f(0.0, 1.0, -1.0) Done glend() Page 23 23

The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Modeling and Viewing Transformations Placing objects - Modeling transformations Map points from object coordinate system to world coordinate system Placing camera - Viewing transformation Map points from world coordinate system to camera (or eye) coordinate system Page 24 24

Modeling Transformations: Object Placement Page 25 25

Viewing Transformation: Camera Placement Modeling & Viewing Transformations Types of transformations: Rotations, scaling, shearing Translations Other transformations (not handled by rendering pipeline): Freeform deformation Page 26 26

Computer Graphics 27 Page 27 Linear transformations Rotations, scaling, shearing Modeling & Viewing Transformation Can be expressed as 3x3 matrix E.g. scaling (non uniform): y x y x 0 3 0 0 0 2 ' ' z z 1 0 0 ' Affine transformations Linear transformations + translations Modeling & Viewing Transformation Can be expressed as 3x3 matrix + 3 vector E.g. scale+ translation: y x t t y x y x 0 3 0 0 0 2 ' ' Another representation: 4x4 homogeneous matrix z y t z z 1 0 0 '

The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Lighting Page 28 28

Complex Lighting and Shading The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 29 29

Perspective Transformation Purpose: Project 3D geometry to 2D image plane Simulates a camera Camera model: Pinhole camera (single view point) Other, more complex camera models also exist in computer graphics, but are less common Thin lens cameras Full simulation of lens geometry Perspective Projection Page 30 30

Perspective Transformation In computer graphics: Image plane conceptually in front of center of projection Perspective transformations subset of projective transformations Linear & affine transformations ti also belong to this class All projective transformations can be expressed as 4x4 matrix operations The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 31 31

Clipping Removing invisible geometry Geometry outside viewing frustum Plus too far or too near one The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 32 32

Scan Conversion/Rasterization Convert continuous 2D geometry to discrete Raster display discrete grid of elements Terminology Pixel: basic element on device Resolution: number of rows & columns in device Measured in Absolute values (1K x 1K) Density values (300 dots per inch) Screen Space: Discrete 2D Cartesian coordinate system of the screen pixels drawing Scan Conversion Page 33 33

Scan Conversion Scan Conversion Problem: Line is infinitely thin, but image has finite resolution Results in steps rather than a smooth line Jaggies Aliasing One of the fundamental problems in computer graphics Page 34 34

Scan Conversion Scan Conversion Color interpolation Linearly interpolate per-pixel color from vertex color values Treat every channel of RGB color separately color t s Page 35 35

Scan Conversion Color interpolation Example: red green blue t t t s s s The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 36 36

Texturing (s 0,t 0 ) (s 2,t 2 ) t (s 1,t 1 ) s Texturing (s 0,t 0 ) (s 2,t 2 ) t (s 1,t 1 ) s Page 37 37

Texture Mapping Displacement Mapping Page 38 38

Texturing Issues: Computing 3D/2D map (low distortion) How to map pixel from texture (texels) to screen pixels Texture can appear widely distorted in rendering Magnification / minification of textures Filtering of textures Preventing aliasing (anti-aliasing) The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 39 39

Without Hidden Line Removal Hidden Line Removal Page 40 40

Hidden Surface Removal Depth Test /Hidden Surface Removal Remove invisible geometry Parts that are hidden behind other geometry Possible Implementations: Per-fragment decision Depth buffer Object space decision Clipping polygons against each other Sorting polygons by distance from camera Page 41 41

Depth Test /Hidden Surface Removal The Rendering Pipeline Geometry Processing Geometric Content Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Framebuffer Rasterization Fragment Processing Page 42 42

Blending Blending: Final image: write fragments to pixels Draw from farthest to nearest No blending replace previous color Blending: combine new & old values with some arithmetic operations Frame Buffer : video memory on graphics board that holds resulting image & used to display it Not Handled: Reflection/Shadows Page 43 43

Basics of Computer Graphics: Basics of Computer Graphics: Rendering Pipeline Page 44 44