Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.

Slides:



Advertisements
Similar presentations
15.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 15 – Visible Surfaces and Shadows.
Advertisements

©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods Jack van Wijk TU/e.
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
Computing & Information Sciences Kansas State University CG Basics 5 of 8: OpenGL Primer 2 CIS 636/736: (Introduction to) Computer Graphics CIS 636 Introduction.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
RealityEngine Graphics Kurt Akeley Silicon Graphics Computer Systems.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Status – Week 277 Victor Moya.
Computer Graphics (Fall 2003) COMS 4160, Lecture 6: OpenGL 2 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
SET09115 Intro Graphics Programming
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 7: OpenGL Shading
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Shading in OpenGL.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Computer Graphics I, Fall 2010 Shading in OpenGL.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
CG Summary: OpenGL Shading andTextures Angel, Chapters 5, 7; “Red Book” slides from AW, red book, etc. CSCI 6360/4360.
Review of OpenGL Basics
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Computer Graphics Bing-Yu Chen National Taiwan University.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
Visual Appearance Chapter 4 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Lecture 7 Midterm Review. OpenGL Libraries gl: Basic OpenGL library, e.g. primitives. glu: OpenGL Utility library, a set of functions to create texture.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
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.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
© University of Wisconsin, CS559 Spring 2004
Draw a Simple Object.
Programmable Pipelines
The Graphic PipeLine
Visual Appearance Chapter 4
School of Computer Science
Models and Architectures
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Frame Buffer Applications
Presentation transcript:

Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys

Texture Mapping Textures are images applied to objects Texture modifies the color assignment to a fragment –Texture color can modify the material color used in the shading model, or it can be a decal Use glTexCoord to assign a texture coordinate to a vertex

Texture Mapping Code glBegin( GL_QUADS ); glTexCoord2f( 0, 0 ); glVertex3f( a, b, c ); glTexCoord2f( 1, 0 ); glVertex3f( a, b, d ); glTexCoord2f( 1, 1 ); glVertex3f( a, e, d ); glTexCoord2f( 0, 1 ); glVertex3f( a, e, c ); glEnd();

Specifying the Texture Image glTexImage2D( target, level, components, width height, border, format, type, data ) target is GL_TEXTURE_2D level is (almost always) 0 components = 3 or 4 (RGB/RGBA) width/height MUST be a power of 2 border = 0 (usually) format = GL_RGB or GL_RGBA (usually) type = GL_UNSIGNED_BYTE, GL_FLOAT, etc…

More on Texture Optimizations for efficiency Mipmapping Filtering Texture Coordinate generation Texture Matrix Environment Mapping

Animation To generate a simple animation: –Encapsulate all drawing commands in a display function –Use an idle callback to change your objects or drawing parameters, and then force a redraw glutPostRedisplay will cause GLUT to call your display function as soon as it gets a chance You can use glutPostRedisplay in the display callback itself, but this gives up on rate control

Animation Example In main( ) glutIdleFunc( spin ); glutDisplayFunc( display ); In spin( ) ComputeNewAngle() glutPostRedisplay( ); In display( ) glClear( … ); glRotate( theta, … );

Double Buffering The time required to perform a redraw is not the same as the monitor’s refresh rate We might see part of an image if we’re not in sync The solution is to use two buffers: front and back –Front buffer is displayed –Back buffer is drawn into Switch between them with glutSwapBuffers() glutSwapBuffers() will switch the buffers exactly when the vertical retrace is completed Demo

Lighting (Chapter 5) Rendering Modes –Wireframe: glPolygonMode(GL_FRONT, GL_LINE) Can also use Polygon Offsets to superimpose wireframe Hidden line elimination? (polygons in black…) –Flat: glShadeModel(GL_FLAT) –Smooth (Goraud): glShadeModel(GL_SMOOTH) –Texture Mapped –Examples: color plates These specify how to interpolate vertex colors –How do we compute vertex colors? Lighting –glEnable(GL_LIGHT0) ; glEnable(GL_LIGHTING) ;

Specifying Normals Normals are specified through glNormal Normals are associated with vertices Specifying a normal sets the current normal –Remains unchanged until user alters it –Usual sequence: glNormal, glVertex, glNormal, glVertex, glNormal, glVertex… Usually, we want unit normals for shading –glEnable( GL_NORMALIZE ) –This is slow – either normalize them yourself or don’t use glScale Evaluators will generate normals for curved surfaces

Light Sources Point –Position, Color [separate diffuse/specular] –Attenuation Directional Spotlights –Spot exponent –Spot cutoff Emission, Ambient All parameters: pp 185 Transforms: Light is geometry (Modelview matrix) –Projection matrix doesn’t act. Eye coordinates important –3 types of light motions (pp )

Specifying a Light Source GLfloat light1_ambient[4] = {.1f,.1f,.1f,.0f}; glLightfv( GL_LIGHT0, GL_AMBIENT, light1_ambient ); Same for specular, diffuse, and position glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); Use glLightf for attenuation and spotlight properties Light positions are multiplied by the model view matrix

Specifying a Material Similar to setting the light source parameters: GLfloat mat_diffuse[4] = { 1.0f, 0.0f, 0.0f, 0.0f }; glMaterialfv( GL_FRONT, GL_DIFFUSE, mat_diffuse ) It is possible to have different material properties for the front and back of polygons See OpenGL book for a more detailed explanation of what you can do with a material

Lighting Equation Hack (common in computer graphics) Details and physical basis later Terms –Ambient –Diffuse –Specular –Emissive Materials, Light sources

Steps Simple example (pp 181) Normals for each vertex (glNormal) –Normalize (sparingly): glEnable(GL_NORMALIZE) –For each vertex, part of OpenGL state –Evaluators for curved surfaces (later) Lights –glLightModel, glLight, GL_LIGHT0…7 Materials –glMaterialfv

Materials, Lighting model Materials –Similar to light: glMaterialfv (diffuse, specular, Phong exponent). Front, back can be different Lighting model [pp 197] – Ambient intensity – Local/distant viewpoint –Lighting differently on front/back –Separate specular for texturing? Lighting equation, mathematics [pp214; ]

Putting it together 3D pipeline –Geometry –Transforms –Hidden Surface removal (z-buffering) Depth buffer: glEnable(GL_DEPTH_TEST) ; glDepthFunc(GL_LESS) ; –Lighting and shading 2D pipeline [pp 295] –glDrawPixels, glReadPixels, glCopyPixels, glBitmap –glRasterPos to control where pixels go –glPixelStore to control way in which images are stored Texture Mapping

Display Lists (Chapter 7) Immediate Mode –Primitives sent to display as soon as specified – no memory in graphics system Retained Mode –Primitives in display list –Can be stored on server, displayed in new state etc. Cached commands. Immutable, unreadable. –Performance gain Example –Display lists: pages 262, 263, Hierarchical 269, 270 Other optimizations: Vertex arrays, texture objects, cull,…

Other Topics Blending, Antialiasing, Fog, 2D (Chapters 6,8) Buffers (Chapter 10) –Fragment tests (scissor,alpha,stencil,depth,blending) –Color(front,back,left,right), Depth, Stencil –Accumulation Buffer Tessellators and Quadrics (Chapter 11) Evaluators and NURBS (Chapter 12) Selection and FeedBack (Chapter 13) More stuff (Chapter 14, appendices) Extensions:

Review Questions Consider a z-buffer with near plane 1, far plane infinity –Assuming 16 bits precision, what is resolution at 1? –At a distance 10? –At a distance 100? What is order in OpenGL of following ops? –Modelview transform to vertex geometry –Projection transform –Dehomogenization –Depth test –Clipping –Lighting –Transformation of normals (how?)