Rendering Geometric Primitives Reading: HB4, HB8-1 to HB8-6, HK9.7, 11

Slides:



Advertisements
Similar presentations
OpenGL Computer Graphics
Advertisements

Chapter 2: Graphics Programming
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Math Review Rendering.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
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.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
NoufNaief.net 1 TA: Nouf Al-Harbi.
UniS CS297 Graphics with Java and OpenGL Blending.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner OpenGL/GLUT Intro Week.
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Introduction to Graphics Programming. Graphics API.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
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.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
CSC Graphics Programming
- Introduction - Graphics Pipeline
Week 2 - Friday CS361.
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
CS451Real-time Rendering Pipeline
Understanding Theory and application of 3D
Programming with OpenGL Part 3: Three Dimensions
OpenGL API 2D Graphic Primitives
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Rendering Pipeline, OpenGL/GLUT
Programming with OpenGL Part 3: Three Dimensions
Introduction to OpenGL
Lecture 13 Clipping & Scan Conversion
Rendering Pipeline Week 2, Mon Jan 11
Models and Architectures
Models and Architectures
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Programming with OpenGL Part 3: Three Dimensions
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

Rendering Geometric Primitives Reading: HB4, HB8-1 to HB8-6, HK9.7, 11 Computer Graphics Last updated on 06-02-2012 Rendering Geometric Primitives Reading: HB4, HB8-1 to HB8-6, HK9.7, 11

Rendering Goal interactive rendering offline rendering transform computer models into images may or may not be photo-realistic interactive rendering fast, but limited quality roughly follows a fixed patterns of operations rendering pipeline offline rendering ray tracing global illumination

Rendering Tasks that need to be performed project all 3D geometry onto the image plane geometric transformations determine which primitives or parts of primitives are visible hidden surface removal determine which pixels a geometric primitive covers scan conversion compute the color of every visible surface point lighting, shading, texture mapping

Rendering Pipeline What is the pipeline? abstract model for sequence of operations to transform geometric model into digital image abstraction of the way graphics hardware works underlying model for application programming interfaces (APIs) that allow programming of graphics hardware OpenGL Direct 3D Actual implementation details of rendering pipeline will vary

Rendering Pipeline Geometry Database Model/View Perspective Lighting Transform. Lighting Perspective Clipping Scan Conversion Depth Test Texturing Blending Frame- Buffer

Geometry Database Geometry database Application-specific data structure for holding geometric information Depends on specific needs of application triangle, points, mesh with connectivity information, curved surface

Model/View Transformation Geometry Database Model/View Transform. Modeling Transformation Map all geometric objects from local coordinate system into world coordinates Viewing transformation Map all geometry from world coordinates into camera coordinates

Lighting Geometry Database Model/View Transform. Lighting Lighting Compute brightness based on property of material and light position(s) Computation is performed per-vertex

Perspective Transformation Geometry Database Model/View Transform. Lighting Perspective Transform. Perspective Transformation Projecting the geometry onto the image plane Projective transformations and model/view transformations can all be expressed with 4x4 matrix operations

Clipping Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Clipping Removal of parts of the geometry that fall outside the visible screen or window region May require re-tessellation of geometry

Scan Conversion Scan Conversion Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Scan Conversion Turn 2D drawing primitives (lines, polygons etc.) into individual pixels Interpolate color across primitive Generate discrete fragments

Texture Mapping Texture Mapping “Gluing images onto geometry” Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Texture Mapping “Gluing images onto geometry” Color of every fragment is altered by looking up a new color value from an image

Depth Test Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Depth Test Remove parts of geometry hidden behind other geometric objects Perform on every individual fragment

Blending Blending Final image: write fragments to pixels Geometry Database Model/View Transform. Lighting Perspective Transform. Clipping Scan Conversion Texturing Depth Test Blending Blending Final image: write fragments to pixels Draw from farthest to nearest No blending – replace previous color Blending: combine new & old values with arithmetic operations

Frame Buffer Frame Buffer Geometry Database Model/View Transform. Lighting Perspective Clipping Scan Conversion Depth Test Texturing Blending Frame- Buffer Frame Buffer Video memory on graphics board that holds image Double-buffering: two separate buffers Draw into one while displaying other, then swap to avoid flicker 255 255 255 0 255 255 0 255 255 0 255 255 255 155 0 155 255 155

Pipeline Advantages Only local knowledge of the scene is necessary Modularity: logical separation of different components 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

Pipeline 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 difficult

3D Scene Representation Scene is usually approximated by 3D primitives Point Line segment Polygon Polyhedron Cylinder Curved surface Solid object etc.

OpenGL Attributes of Graphics Primitives Color, antialiasing, … Point attributes, Line attributes, Curve attributes, Character attributes

OpenGL Attributes of Graphics Primitives Attributes are any parameters that affect the way graphic primitives are displayed. Basic attributes Color Size Style Fill patterns

OpenGL Attributes of Graphics Primitives Attribute parameter A parameter that affects the way a primitive is to be displayed, ex: color, size. State system / State machine A graphics system that maintains a list for the current values of attributes

OpenGL State Variables All OpenGL state parameters have default values. Set the state once, remains until overwritten Changing the attribute settings Only affects those primitives that are specified after the OpenGL state is changed Lines: blue or orange, dotted or dashed, and fat or thin. State parameters can have more than two states, e.g., colors, styles, etc.

OpenGL Color & Gray Scale Color is a common attribute for all primitives Color information can be stored in two ways 1. RGB color codes 2. Color table Stored Color Values in Frame Buffer 1 2 3 4 5 6 7 Black Blue Green Cyan Red Magenta Yellow White GREEN Displayed Color

OpenGL Color & Gray Scale Color is a common attribute for all primitives Color information can be stored in two ways 1. RGB color codes 2. Color table

OpenGL Color Functions Set color display mode 1. OpenGL RGB and RGBA mode 2. OpenGL Color-Index Mode glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB ) GLUT_RGBA GLUT_INDEX glColor* (colorComponents); // Select current color glIndexi(196); glutSetColor (index, red, green, blue); // Select current color // Specify color into a table

OpenGL Color Functions OpenGL color blending Combining the color of overlapping objects Blending an object with the background Color-blending function Destination object: Current object in the frame buffer Source object: Other object in the frame buffer glEnable(GL_BLEND); Source glDisable(GL_BLEND); Destination  Blending methods can be performed only in RGB or RGBA mode.

OpenGL Color Functions Blending Factors glColor4f(R, G, B, A), A is a blending factor Source color components are (Rs, Gs, Bs, As) Destination color components are (Rd, Gd, Bd, Ad) Source blending factors are (Sr, Sg, Sb, Sa) Destination blending factors are (Dr, Dg, Db, Da) The new blending color that is then loaded into the frame buffer is calculated as: (SrRs+DrRd, SrGs+DgGd, SbBs+DbBd, SaAs+DaAd) Source Destination

OpenGL Color Functions glBlendFunc (sFactor, dFactor); Default: GL_ONE GL_ZERO (1.0, 1.0, 1.0, 1.0) (0.0, 0.0, 0.0, 0.0) Ex. glBlendFunc(GL_SRC_ALPHA,GL_ONE); Ex: implement it by using glColor4f (0.8, 0.2, 0.2, 0.4); Source Destination

OpenGL Example: Blending 1/3 #include <GL/glut.h> void init (void) { glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // (sFactor, dFactor) glClearColor (1.0, 1.0, 1.0, 0.0); //(red, green, blue, alpha) }

OpenGL Example: Blending 2/3 void display(void) { glClear (GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); // Draw triangle glColor4f(1.0, 0.0, 0.0, 0.75); glVertex3f(0, -0.5, 0.0); glVertex3f(0.5, -0.5, 0.0); glVertex3f(0, 1, 0.0); glEnd(); glBegin(GL_POLYGON); // Draw rectangle glColor4f(0.0, 0.0, 1.0, 0.75); glVertex3f (-0.6, -0.6, 0); glVertex3f (0.6, -0.6, 0); glVertex3f (0.6, 0.6, 0); glVertex3f (-0.6, 0.6, 0); glFlush (); }

OpenGL Example: Blending 3/3 int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (600, 400); glutInitWindowPosition (200, 100); glutCreateWindow ("Hello Students"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }

OpenGL Home Work Plot red, green & blue circles overlapping as shown in figure. Reading: HB4, RB

OpenGL Point Attributes & Functions Basic attributes Color Size A multiple of the pixel size (a square) glPointSize (size); // size is the number of pixels

OpenGL Line Attributes & Functions Basic attributes Color Width glLineWidth(width); Style glEnable(GL_LINE_STIPPLE); glLineStippel(repeatFactor, pattern); Other attributes Shade glShadeModel(GL_SMOOTH); How many times each bit is to be repeat 16-bit integer Default: 0xFFFF  Solid line Lower-order bits are applied first

OpenGL Line Attributes & Functions Pixel mask A pattern of binary digits For example, 11111000 dashed line Inter-dash spacing

OpenGL Fill-Area Attribute Functions OpenGL fill-area routines for convex polygons only. Four steps: Define a fill pattern Invoke the polygon-fill routine Activate the polygon-fill feature Describe the polygons to be filled.

OpenGL Example void init(void) { glClearColor (0.0, 0.0, 0.0, 0.0); glShadeModel (GL_SMOOTH)} void triangle(void) glBegin (GL_TRIANGLES); glColor3f (1.0, 0.0, 0.0); glVertex2f (5.0, 5.0); glColor3f (0.0, 1.0, 0.0); glVertex2f (25.0, 5.0); glColor3f (0.0, 0.0, 1.0); glVertex2f (5.0, 25.0); glEnd(); } http://www.opengl.org/resources/code/samples/redbook/smooth.c

OpenGL Polygon Stippling

OpenGL Polygon Stippling byte fly[] = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x80, (byte) 0x01, (byte) 0xC0, (byte) 0x06, (byte) 0xC0, (byte) 0x03, (byte) 0x60, (byte) 0x04, (byte) 0x60, (byte) 0x06, (byte) 0x20, (byte) 0x04, (byte) 0x30, (byte) 0x0C, (byte) 0x20, (byte) 0x04, (byte) 0x18, (byte) 0x18, (byte) 0x20, (byte) 0x04, (byte) 0x0C, (byte) 0x30, (byte) 0x20, (byte) 0x04, (byte) 0x06, (byte) 0x60, (byte) 0x20, (byte) 0x44, (byte) 0x03, (byte) 0xC0, (byte) 0x22, (byte) 0x44, (byte) 0x01, (byte) 0x80, (byte) 0x22, (byte) 0x44, (byte) 0x01, (byte) 0x80, (byte) 0x22, (byte) 0x66, (byte) 0x01, (byte) 0x80, (byte) 0x66, (byte) 0x33, (byte) 0x01, (byte) 0x80, (byte) 0xCC, (byte) 0x19, (byte) 0x81, (byte) 0x81, (byte) 0x98, (byte) 0x0C, (byte) 0xC1, (byte) 0x83, (byte) 0x30, (byte) 0x07, (byte) 0xe1, (byte) 0x87, (byte) 0xe0, (byte) 0x03, (byte) 0x3f, (byte) 0xfc, (byte) 0xc0, (byte) 0x03, (byte) 0x31, (byte) 0x8c, (byte) 0xc0, (byte) 0x03, (byte) 0x33, (byte) 0xcc, (byte) 0xc0, (byte) 0x06, (byte) 0x64, (byte) 0x26, (byte) 0x60, (byte) 0x0c, (byte) 0xcc, (byte) 0x33, (byte) 0x30, (byte) 0x18, (byte) 0xcc, (byte) 0x33, (byte) 0x18, (byte) 0x10, (byte) 0xc4, (byte) 0x23, (byte) 0x08, (byte) 0x10, (byte) 0x63, (byte) 0xC6, (byte) 0x08, (byte) 0x10, (byte) 0x30, (byte) 0x0c, (byte) 0x08, (byte) 0x10, (byte) 0x18, (byte) 0x18, (byte) 0x08, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x08 };

3D Geometric Primitives http://mrl.snu.ac.kr/courses/CourseGraphics/ObjectRepresentation.ppt

Rendering Generate an image from geometric primitives Rendering Raster Image

What issues must be addressed by a 3D rendering system? 3D Rendering Example What issues must be addressed by a 3D rendering system?

3D Object Representation Polyhedra

OpenGL 3D Primitives (GLUT Support)

Cube Sphere glutWireCube(GLdouble size) size = length of a side OpenGL 3D Primitives Cube glutWireCube(GLdouble size) size = length of a side Sphere glutWireSphere(GLdouble radius, GLint nSlices, GLint nStacks) Approximated by polygonal faces nSlices = # of polygons around z-axis nStacks = # of bands along z-axis There are solid counterparts of the wire objects

Regular Polyhedron Tetrahedron (4 sided) Hexahedron (6 sided) OpenGL 3D Primitives Regular Polyhedron Tetrahedron (4 sided) glutWireTetrahedron() Hexahedron (6 sided) glutWireHexahedron() Octahedron (8 sided) glutWireOctahedron() Dodecahedron (12 sided) glutWireDodecahedron() Icosahedron (20 sided) glutWireIcosahedron() Display with center at the origin and with radius (distance from the center of polyhedron to any vertex) equal to Sqrt(3)

Cone OpenGL 3D Primitives Axis coincides with the z-axis glutWireCone(GLdouble baseRad, GLdouble height, GLint nSlices, GLint nStacks) Axis coincides with the z-axis Base rests on xy-plane and extends to +ve z = height baseRad: radius at z = 0 nSlices: The number of subdivisions around the z axis. nStacks: The number of subdivisions along the z axis.

Approximated by polygonal faces Teapots glutWireTeapot(GLdouble size) OpenGL 3D Primitives Torus glutWireTorus(GLdouble inRad, GLdouble outRad, GLint nSlices, GLint nStacks) Approximated by polygonal faces Teapots glutWireTeapot(GLdouble size)

Things to do OpenGL practice: HB 2.9

References http://www.ugrad.cs.ubc.ca/~cs314/ http://faculty.cs.tamu.edu/schaefer/teaching/441_Spring2012/index.html http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007/