Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Similar documents
Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

CS451Real-time Rendering Pipeline

Spring 2009 Prof. Hyesoon Kim

Spring 2011 Prof. Hyesoon Kim

Graphics Programming

Precept 2 Aleksey Boyko February 18, 2011

Models and Architectures

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

Introduction to Computer Graphics with WebGL

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

Lectures OpenGL Introduction

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

Lecture 3. Understanding of OPenGL programming

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

Programming using OpenGL: A first Introduction

OpenGL/GLUT Intro. Week 1, Fri Jan 12

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

Computer Graphics (Basic OpenGL)

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

Programming with OpenGL Part 3: Three Dimensions

Drawing Primitives. OpenGL basics

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Using OpenGL with CUDA

Overview of the Pipeline and OpenGL

Basic Graphics Programming

Basic Graphics Programming

Computer Graphics and Visualization. Graphics Systems and Models

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

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

1.2 Basic Graphics Programming

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

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

OpenGL refresher. Advanced Computer Graphics 2012

Rendering Pipeline/ OpenGL

Graphics Hardware and OpenGL

Rasterization Overview

Lecture 4 of 41. Lab 1a: OpenGL Basics

OpenGL Introduction Computer Graphics and Visualization

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

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

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

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

Introduction to OpenGL

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

Interaction. CSCI 480 Computer Graphics Lecture 3

Interaction Computer Graphics I Lecture 3

CS 4204 Computer Graphics

CSE4030 Introduction to Computer Graphics

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

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


QUESTION 1 [10] 2 COS340-A October/November 2009

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

CIS 441/541: Introduction to Computer Graphics Lecture 14: OpenGL Basics

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

Programming with OpenGL Part 1: Background

Computer graphics MN1

Programming with OpenGL Part 1: Background

Announcements OpenGL. Computer Graphics. Spring CS4815

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

Interaction. CSCI 420 Computer Graphics Lecture 3

C OMPUTER G RAPHICS Thursday

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

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

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

1/12/11. Basic Graphics Programming. What is OpenGL. OpenGL is cross-platform. How does OpenGL work. How does OpenGL work (continued) The result

Introduction to OpenGL: Part 2

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

Rendering Objects. Need to transform all geometry then

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Transformation Pipeline

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Models and Architectures. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Computer Graphics. Bing-Yu Chen National Taiwan University

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

Recall: Indexing into Cube Map

CS 591B Lecture 9: The OpenGL Rendering Pipeline

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

Visualizing Molecular Dynamics

Computer graphic -- Programming with OpenGL I

CSC 8470 Computer Graphics. What is Computer Graphics?

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Computer graphics MN1

Fondamenti di Grafica 3D The Rasterization Pipeline.

COMPUTER GRAPHICS LAB # 3

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

Order of Transformations

Lecture 4. Viewing, Projection and Viewport Transformations

Rendering Pipeline/ OpenGL

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

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

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

Transcription:

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

1. I am located in room 4115 in EDIT-huset 2. Email: 3. Phone: 031-772 1775 (office) 4. Course assistant: Tomas Akenine-Mőller 2002

General Information No Project Tutorials in room 4220/4225 or wherever is suitable for you Entrance Cards (inpasseringskort) automatically activated for all of you that are course registered and have a CTH/GU-entrance card (inpasseringskort) Recommended to do the tutorials in groups (Labgrupper) of 2 and 2 Home Page

Studentrepresentanternas ansvar Informerar sig om sina kurskamraters synpunkter på kursen. Vidarebefordrar dessa samt deltar i övrigt i diskussionen vid mötena med egna synpunkter. Kan föreslå kursspecifika frågor i kursenkäten. Informerar sina kurskamrater om diskussioner och rekommendationer från mötena. Ersättning utgår i form av presentkort på 200 kr på Cremona. Kursutvärderingar vid Chalmers

Overview of the Pipeline and OpenGL

Department of Computer Engineering Ulf Assarsson

Department of Computer Engineering The screen consists of many pixels

Department of Computer Engineering 3D-Rendering Objects are often made of triangles x,y,z- coordinate for each vertex Y X Z

State-of-the-Art Real-Time Rendering 2001 Department of Computer Engineering

Y State-of-the-Art Department of Computer Engineering Real-Time Rendering X 2001 Z

Department of Computer Engineering Textures One application of texturing is to glue images onto geometrical object + =

Department of Computer Engineering Texturing: Glue images onto geometrical objects Purpose: more realism, and this is a cheap way to do it + =

Department of Computer Engineering Lighting computation per triangle vertex light blue Rasterizer Geometry red green

The Graphics Rendering Pipeline

You say that you render a 3D scene, but what is it? First, of all to take a picture, it takes a camera a virtual one. Decides what should end up in the final image A 3D scene is: Geometry (triangles, lines, points, and more) Light sources Material properties of geometry Textures (images to glue onto the geometry) A triangle consists of 3 vertices A vertex is 3D position, and may include normals and more.

Lecture 1: Real-time Rendering The Graphics Rendering Pipeline The pipeline is the engine that creates images from 3D scenes Three conceptual stages of the pipeline: Application (executed on the CPU) Geometry Rasterizer Application Geometry Rasterizer Image input 3D scene output

Application Geometry Rasterizer The APPLICATION stage Executed on the CPU Means that the programmer decides what happens here Examples: Collision detection Speed-up techniques Animation Most important task: send rendering primitives (e.g. triangles) to the graphics hardware

Application Geometry Rasterizer The GEOMETRY stage Task: geometrical operations on the input data (e.g. triangles) Allows: Move objects (matrix multiplication) Move the camera (matrix multiplication) Compute lighting at vertices of triangle Project onto screen (3D to 2D) Clipping (avoid triangles outside screen) Map to window

Application Geometry Rasterizer The RASTERIZER stage Main task: take output from GEOMETRY and turn into visible pixels on screen Also, add textures and various other per-pixel operations And visibility is resolved here: sorts the primitives in the z-direction

Application Geometry Rasterizer Rewind! Let s take a closer look The programmer sends down primtives to be rendered through the pipeline (using API calls) The geometry stage does per-vertex operations The rasterizer stage does per-pixel operations Next, scrutinize geometry and rasterizer

Application Geometry Rasterizer GEOMETRY - Summary model space world space world space camera space compute lighting projection image space clip map to screen

Virtual Camera Defined by position, direction vector, up vector, field of view, near and far plane. point fov (angle) dir near Create image of geometry inside gray region Used by OpenGL, DirectX, ray tracing, etc. far

Application Geometry Rasterizer GEOMETRY - The view transform You can move the camera in the same manner as objects But apply inverse transform to objects, so that camera looks down negative z-axis z x

Application Geometry Rasterizer GEOMETRY - Summary model space world space world space camera space compute lighting projection image space clip map to screen

GEOMETRY - Lighting Compute lighting at vertices Application Geometry Rasterizer light blue Rasterizer Geometry red green Try to mimic how light in nature behaves Hard so uses empirical models, hacks, and some real theory Much more about this in later lecture

Example

Application Geometry Rasterizer GEOMETRY - Summary model space world space world space camera space compute lighting projection image space clip map to screen

Application Geometry Rasterizer GEOMETRY - Projection Two major ways to do it Orthogonal (useful in few applications) Perspective (most often used) Mimics how humans perceive the world, i.e., objects apparent size decreases with distance

Application Geometry Rasterizer GEOMETRY - Projection Also done with a matrix multiplication! Pinhole camera (left), analog used in CG (right)

Application Geometry Rasterizer GEOMETRY - Summary model space world space world space camera space compute lighting projection image space clip map to screen

GEOMETRY Application Geometry Rasterizer Clipping and Screen Mapping Square (cube) after projection Clip primitives to square Screen mapping, scales and translates square so that it ends up in a rendering window These screen space coordinates together with Z (depth) are sent to the rasterizer stage

Application Geometry Rasterizer GEOMETRY - Summary model space world space world space camera space compute lighting projection image space clip map to screen

The RASTERIZER in more detail Scan-conversion Find out which pixels are inside the primitive Texturing Put images on triangles Interpolation over triangle Z-buffering Application Geometry Rasterizer + = Make sure that what is visible from the camera really is displayed Double buffering And more blue red green

The RASTERIZER Application Geometry Rasterizer Z-buffering The graphics hardware is pretty stupid It just draws triangles However, a triangle that is covered by a more closely located triangle should not be visible Assume two equally large tris at different depths incorrect correct Triangle 1 Triangle 2 Draw 1 then 2 Draw 2 then 1

The RASTERIZER Application Geometry Rasterizer Z-buffering Would be nice to avoid sorting The Z-buffer (aka depth buffer) solves this Idea: Store z (depth) at each pixel When rasterizing a triangle, compute z at each pixel on triangle Compare triangle s z to Z-buffer z-value If triangle s z is smaller, then replace Z-buffer and color buffer Else do nothing Can render in any order

The RASTERIZER Application Geometry Rasterizer double-buffering The monitor displays one image at a time Top of screen new image Bottom old image No control of split position And even worse, we often clear the screen before generating a new image A better solution is double buffering (Could instead keep track of rasterpos and vblank).

Application Geometry Rasterizer The RASTERIZER double-buffering Use two buffers: one front and one back The front buffer is displayed The back buffer is rendered to When new image has been created in back buffer, swap front and back

And, lately Programmable shading has become a hot topic Vertex shaders Pixel shaders Adds more control and much more possibilities for the programmer HARDWARE Application Geometry Rasterizer Vertex shader program Pixel shader program

The Pipeline and OpenGL

OpenGL function format function name dimensions glvertex3f(x,y,z) belongs to GL library x,y,z are floats glvertex3fv(p) p is a pointer to an array

Example type of object location of vertex glbegin(gl_polygon) glvertex3f(0.0, 0.0, 0.0); glvertex3f(0.0, 1.0, 0.0); glvertex3f(0.0, 0.0, 1.0); glend( ); end of object definition

A Simple Program Generate a triangle on a solid background

#ifdef WIN32 #include <windows.h> #endif Simple Application... #include <GL/glut.h> // This also includes gl.h static void drawscene(void) { glcolor3f(1,1,1); glbegin(gl_polygon); glvertex3f( 4.0, 0, 4.0); glvertex3f( 4.0, 0,-4.0); glvertex3f(-4.0, 0,-4.0); glend(); } Usually this and next 2 slides are put in the same file main.cpp

Simple Application void display(void) { glclearcolor(0.2, 0.2, 0.8, 1.0); // Set clear color glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); // Clears the color buffer and the z-buffer int w = glutget((glenum)glut_window_width); int h = glutget((glenum)glut_window_height); glviewport(0, 0, w, h); // Set viewport glmatrixmode(gl_projection); // Set projection matrix glloadidentity(); gluperspective(45.0,w/h, 0.2, 10000.0); // FOV, aspect ratio, near, far glmatrixmode(gl_modelview); // Set modelview matrix glloadidentity(); glulookat(10, 10, 10, // look from 0, 0, 0, // look at 0, 0, 1); // up vector } drawscene(); glutswapbuffers(); // swap front and back buffer. This frame will now been displayed.

int main(int argc, char *argv[]) { glutinit(&argc, argv); Simple Application... /* open window of size 512x512 with double buffering, RGB colors, and Z- buffering */ glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); glutinitwindowsize(512,512); glutcreatewindow("test App"); /* the display function is called once when the glumainloop is called, * but also each time the window has to be redrawn due to window * changes (overlap, resize, etc). */ glutdisplayfunc(display); // Set the main redraw function } glutmainloop(); /* start the program main loop */ return 0;

Changing Color per Vertex static void drawscene(void) { // glcolor3f(1,1,1); glbegin(gl_polygon); glcolor3f(1,0,0); glvertex3f( 4.0, 0, 4.0); glcolor3f(0,1,0); glvertex3f( 4.0, 0,-4.0); } glcolor3f(0,0,1); glvertex3f(-4.0, 0,-4.0); glend();

Starts looking good! Cooler application

Ulf Assarsson 2008

Ray Tracing and Geometric Optics One way to form an image is to follow rays of light from a point source finding which rays enter the lens of the camera. However, each ray of light may have multiple interactions with objects before being absorbed or going to infinity.

Physical Approaches Ray tracing: follow rays of light from center of projection until they either are absorbed by objects or go off to infinity Can handle global effects Multiple reflections Translucent objects Slow Must have whole data base available at all times Radiosity: Energy based approach Very slow