Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Graphics Algorithms Ying Zhu Georgia State University

Similar presentations


Presentation on theme: "Advanced Graphics Algorithms Ying Zhu Georgia State University"— Presentation transcript:

1 Advanced Graphics Algorithms Ying Zhu Georgia State University
Lecture 03 The Graphics Rendering Pipeline

2 What is graphics rendering pipeline?
A process of generating a 2D image, given a virtual camera (eye), 3D objects, light sources, textures, etc. The 2D image is a frame of animation. A process for converting coordinates from its local 3D coordinate system to the final 2D window coordinate system. Both OpenGL and Direct3D implement part of the rendering pipeline.

3 Graphics Rendering Pipeline Stages
The rendering pipeline is normally divided into 3 conceptual stages Application Geometry Rasterizer The output of one stage is the input of next stage, thus the name “pipeline” Each stage also contains sub- stages Application Geometry Rasterizer

4 OpenGL pipeline (overview)

5 OpenGL pipeline (overview)
Application Rasterizer Geometry

6 OpenGL pipeline (detailed view)

7 Why use pipeline architecture?
It’s more efficient Think automobile assembly line Explore data parallelism Data parallelism vs. instruction parallelism The pipeline architecture is the fundamental architecture for both 3D graphics software and hardware Think GPU as an image assembly line

8 Application Stage Overview
3D objects are created using modeling tools 3D Studio Max, Maya, etc. 3D objects are positioned in 3D world and organized in a scene graph 3D objects can be moved by transformation Transformation are performed on vertices using different types of transformation matrices 3D transformations are specified in this stage but carried out in the Geometry stage

9 Application Stage Overview
Other tasks in the application stage: Handling user input level of details occlusion culling The result: the 3D geometry objects to be fed to the next stage Points, lines, polygons, etc. 3D geometry objects are eventually broken down to vertices, represented by (x, y, z) coordinates

10 Geometry Stage Overview
Responsible for the majority of per-polygon or per vertex operations Contains several sub-stages Model Transformation View Transformation (often combined with model transformation) Lighting Projection Clipping Screen Mapping

11 Coordinate Systems Multiple Cartesian coordinate systems are used at different stages of the pipeline 3D Model Coordinates (model space) Each model is in its own coordinate system with origin in some point on the model 3D World Coordinates (world space) Unified world coordinate system, with only one origin 3D Eye Coordinates (view space) Camera (eye) is the origin and look straight down Z-axis 2D Screen Coordinates (screen space) 3D coordinates are converted to 2D screen coordinates for display

12 3D Graphics Pipeline Data Flow
Objects in the 3D scene are sequentially transformed through different coordinate systems when proceeding the 3D pipeline.

13 Model Transform Transform the vertices and normals of 3D objects from model space to world space After the transform, all objects exit in the same coordinate system The camera (eye) has a location in world coordinate system and a direction

14 View Transform The camera and all the 3D objects are transformed with the view transform The purpose is to place the camera at the origin and make it look in the direction of Z-axis. Often combined with model transform – model-view transform

15 Projection Transform the view volume into a unit cube with its extreme points at (-1, -1, -1) and (1, 1, 1). The purpose is to simplify clipping. Two projection methods: Orthographic projection When realism is not a concern. Perspective projection When realism counts.

16 Lighting A lighting equation is used to calculate a color at each vertex of the 3D object that is to be affected by lighting. The lighting equations often have little to do with how lights behave in the real world. Per-vertex lighting vs. per-pixel lighting

17 Shading Each 3D object surface is divided into many triangles.
The colors at the vertices of a triangle are interpolated over the triangle. Three shading methods: Flat shading (operate per triangle) Gouraud Shading (operate per vertex) Phong Shading (operate per pixel) Programmable Shaders

18 Clipping Only the primitives wholly or partially inside the view volume need to be passed on to the rasterizer stage. Primitives (line or polygon) that are partially inside the view volume require clipping.

19 Screen Mapping Primitives that survive the clipping are passed on to screen mapping stage. X and Y coordinates of each primitive are transformed to screen coordinates. Z coordinates are not affected and are kept for depth buffer checking.

20 Rasterizer Stage Overview
In this stage, all primitives are converted into pixels in the window. The goal of this stage is to assign correct colors to the pixels. It contains one or all of the following sub-stages: Texture mapping Fog Translucency Test Depth buffering Antialiasing

21 Rasterization

22 Texturing Texture mapping means “attaching” an image onto a 3D object.
Textures are important to bringing realism to a 3D scene. Provide surface details Add scene depth Advance texture mapping Multi-texturing Bump mapping Environment mapping Pixel shader

23 Fog An optional stage but help set the mood
Also helps give a scene an addition sense of depth of field Added realism E.g. allow distant objects to gracefully "fade away" rather than just pop out of the scene

24 Translucency Tests Also called Alpha Test
Used to create effects such as glass, water, see-through views in CAD modeling, and translucent or transparent materials.

25 Depth Buffering Also called Z-buffer algorithm
Used for visibility check When multiple primitives are rendered to a certain pixel, the color of the pixel is the color of the primitive that is closest to the point of view of camera. The only exception is when primitives are transparent. This algorithm allows the primitives to be rendered in any order.

26 Anti-aliasing Alias effect: the jagged or stair-stepped look of diagonal or curved lines in computer graphics. Anti-aliasing algorithms sample, or examine and evaluate, the colors and shades of pixels adjoining curved or diagonal lines to present smoother looking line.

27 Display Finally, the final 2D image is generated and rendered to frame buffer and displayed on screen. Double-buffer technique may be used to reduce flashing Front buffer for display, back buffer for rendering next frame. A long trip down the graphics rendering pipeline If application runs at 60 frame/second, this whole process will repeat every 17 ms.

28 Summary The 3D graphics pipeline is the underlying tool for graphics rendering. Three major stages: Application Geometry Rasterizer

29 Readings “ExtremeTech 3D Pipeline Tutorial” at ,00.asp

30 Overview of OpenGL An open standard specification defining a cross platform API for writing 2D or 3D computer graphics applications Defines over 250 function calls Competes with Direct3D Managed by an industry consortium (Khronos Group)

31 Notable OpenGL games Doom 3 Half-Life Quake Call of Duty Second Life
Spore Unreal Tournament

32 Notable OpenGL applications
Blender Adobe Photoshop Adobe After Effects Adobe Premiere

33 OpenGL pipeline

34 Purposes of OpenGL Hide the complexities of interfacing with different 3D graphics hardware Hide the differing capabilities of hardware platforms, by requiring that all implementations support the full OpenGL feature set

35 OpenGL OpenGL's basic operation is to accept primitives such as points, lines and polygons, and convert them into pixels. OpenGL is a low-level, procedural API, requiring the programmer to dictate the exact steps required to render a scene. Requires programmers to have a good knowledge of the graphics pipeline,

36 OpenGL Books Red Book: OpenGL Programming Guide
Blue Book: OpenGl Reference Manual Orange Book: OpenGL Shading Language

37 OpenGL Files OpenGL files comes with MS Windows and/or Visual Studio installation Header files gl.h, glu.h Glut.h (needs to be downloaded) Static libraries Opengl32.lib, glu32.lib glut32.lib (needs to be downloaded) DLLs C:\windows\system32 Opengl32.dll, glu32.dll glut32.dll (needs to be downloaded)

38 How to compile OpenGL/GLUT programs?
ll04-22C151/howto/winGLUT.html ACTIVE_COMPUTER_GRAPHICS/FOURTH _EDITION/vc

39 Sample OpenGL programs
Examples from “OpenGL Programming Guide” edbook/ OpenGL code samples: Simple code samples: imple/

40 A Simple OpenGL Program (1)
#include <GL/glut.h> void display(void) { /* clear all pixels */ glClear (GL_COLOR_BUFFER_BIT); /* draw white polygon (rectangle) with corners at * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */ glColor3f (1.0, 1.0, 1.0); glBegin(GL_POLYGON); glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0); glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0); glEnd();

41 A Simple OpenGL Program (2)
/* start processing buffered OpenGL routines */ glFlush (); } void init (void) { /* select clearing color */ glClearColor (0.0, 0.0, 0.0, 0.0); /* initialize viewing values */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

42 A Simple OpenGL Program (3)
/* Declare initial window size, position, and display mode (single buffer and RGBA). Open window with "hello" in its title bar. Call initialization routines. Register callback function to display graphics. Enter main loop and process events. */ int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (250, 250); glutInitWindowPosition (100, 100); glutCreateWindow ("hello"); init (); glutDisplayFunc(display); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }

43 OpenGL Functions Overview (1)
Primitives: object creation glBegin(), glEnd(); A glBegin()-glEnd() pair encloses an object definition. OpenGL functions called between glBegin() and glEnd() define the object glVertex*(), glColor*(), glNormal*(), glMaterial*(), glCallList(), glCallLists(), glRect*(), gluSphere(), gluCylinder() Attributes glClearColor() and glClear() specify the color to be used when color buffers are cleared and to actually clear the buffer, respectively. Attributes (all are modal) control how primitives are displayed: glPolygonMode(), glPointSize(), glLineStipple(), glLineWidth()

44 Overview of OpenGL Functions (2)
Display lists glNewList(), glEndList(), glGenLists(), glListBase() Display lists are collections of graphics functions. You create them, name them, and "execute" them. You define objects in between glNewList() and glEndList(). Modeling transformations glScale*(), glTranslate*(), glRotate*() Before invoking any matrix manipulating function, you normally call glLoadIdentity(). Remember that glRotate() rotates about the origin so in order to rotate an object you usually must make sure that it is positioned at the origin.

45 OpenGL Functions Overview (3)
Viewing gluLookAt() The viewing transformation must precede modelling transformations in the code: you must first position the camera, then the objects. Projection gluOrtho2D(), glOrtho(), gluPerspective(), glViewport() Call glMatrixMode( GL_PROJECTION) before you change projection parameters with any of the three functions above, then call glMatrixMode( GL_MODELVIEW). When the projection has been applied (whether simple discarding of z or a perspective division) we obtain normalized device coordinates. Finally these are mapped to (a portion of) the screen window. This mapping is specified with

46 OpenGL Functions Overview (4)
States glEnable(), glDisable() Almost everyting in OpenGL is modal, i.e. settings remain in effect until changed (this is true, not only of state variables we set with glEnable(), but also of normals, material properties, and colours). Realism; light and shading glLight*(), glLightModel*(), glMaterial*(), glShadeModel() You must enable (with glEnable()) both lighting and the light sources you want to use.

47 OpenGL Functions Overview (5)
Hierarchical Models glPushAttrib(), glPopAttrib(), glPushMatrix(), glPopMatrix() In order to build hierarchical models we need ways of storing and restoring attributes and matrices. Display lists often start by pushing and ends by popping. 2D Texture & pixels glTexImage2D(), glBindTexture(), glTexCoord2*(), glRasterPos*(), glBitmap(), glDrawPixels() Texturing must be enabled explicitly.

48 GLUT Functions Overview (1)
Input and other callback functions OpenGL programs execute in event mode, i.e. loops forever while awaiting user input. We write callback functions to be invoked as a result of user interaction. GLUT automatically calls the functions if we have registered them. glutDisplayFunc(), glutMouseFunc(), glutMotionFunc(), glutReshapeFunc(), glutKeyboardFunc(), glutIdleFunc(), glutPostRedisplay()

49 GLUT Functions Overview (2)
Control Functions Control functions are functions that interface with the windowing system. You (usually) call them from your main() function. glutInit(), glutInitDisplayMode(), glutInitWindowSize(), glutCreateWindow(), glutMainLoop()

50 How to learn OpenGL? Read OpenGL Programming Guide
Read sample programs! There are tons of OpenGL programs online: Read tutorials Write programs

51 How to learn OpenGL? Bookmark the OpenGL manual pages
You need this more than anything else Bookmark the GLUT manual page ec3/spec3.html If you are really serious about learning OpenGL, read OpenGL specification

52 Other OpenGL Resources
OpenGL tutor Tutorial programs that demonstrate basic OpenGL functionality by allowing the user to modify the parameters of a function and see the effect on the scene OpenGL FAQ & Troubleshooting Guide A good OpenGL tutorial


Download ppt "Advanced Graphics Algorithms Ying Zhu Georgia State University"

Similar presentations


Ads by Google