2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.

Slides:



Advertisements
Similar presentations
CHAPTER 5 3D Graphics Programming Color, Material, and Lighting Vivian by Richard S. Wright Jr.
Advertisements

OpenGL: Simple Use Open a window and attach OpenGL to it Set projection parameters (e.g., field of view) Setup lighting, if any Main rendering loop –Set.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
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.
3D Game Programming Geometric Transformations
Graphics Pipeline.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Computer Graphics - Class 10
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 16: Illumination Models Part 2 Emmanuel Agu.
Lighting and Shading Wen-Chieh (Steve) Lin
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
7M836 Animation & Rendering
Graphics Systems I-Chen Lin’s CG slides, Doug James’s CG slides Angel, Interactive Computer Graphics, Chap 1 Introduction to Graphics Pipeline.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
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.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
OpenGL - Lighting, Shading and Material Properties
Computer Graphics I, Fall 2010 Shading in OpenGL.
Lecture 9: Lighting and Shading 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
CS559: Computer Graphics Lecture 15: Hierarchical Modeling and Shading Li Zhang Spring 2008.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
CSE 381 – Advanced Game Programming GLSL Lighting.
Programming 3D Applications CE Displaying Computer Graphics Week 3 Lecture 5 Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
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.
Project 5 Lamp Shader Fri, Nov 7, 2003 Due Mon, Nov 17, 2003.
11/04/04© University of Wisconsin, CS559 Fall 2004 Last Time Visibility –Z-Buffer and transparency –A-buffer –Area subdivision –BSP Trees –Exact Cell-Portal.
Illumination and Shading
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
In the name of God Computer Graphics. Where We Stand So far we know how to: –Transform between spaces –Draw polygons Next –Deciding a pixel’s intensity.
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Computer Graphics (fall,2010) School of Computer Science University of Seoul Minho Kim.
CSC Graphics Programming
Rendering Pipeline Fall, 2015.
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
School of Computer Science
Shading in OpenGL Ed Angel
CSE 470 Introduction to Computer Graphics Arizona State University
Lighting and Materials
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

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 basic geometric rasterization and clipping algorithms

3 COEN Computer Graphics I Simulating Lighting In CGI n Lighting is a key component in computer graphics n Provides cues on: shape and smoothness of objects distance from lights to objects objects orientation in the scene n Most importantly, helps CG images look more realistic

4 COEN Computer Graphics I Lighting Models n Many different models exist for simulating lighting reflections we’ll be concentrating on the Phong lighting model n Most models break lighting into constituent parts ambient reflections diffuse reflections specular highlights

5 COEN Computer Graphics I Lighting Model Components n Material Properties used to describe an objects reflected colors n Surface Normals n Light Properties used to describe a lights color emissions n Light Model Properties “global” lighting parameters

6 COEN Computer Graphics I Physics of Reflections

7 COEN Computer Graphics I Ambient Reflections n Color of an object when not directly illuminated light source not determinable n Think about walking into a room with the curtains closed and lights off

8 COEN Computer Graphics I Diffuse Reflections n Color of an object when directly illuminated often referred to as base color

9 COEN Computer Graphics I Specular Reflections n Highlight color of an object n Shininess exponent used to shape highlight

10 COEN Computer Graphics I Phong Lighting Model n Using surface normal n OpenGL’s lighting model based on Phong’s

11 COEN Computer Graphics I OpenGL Material Properties n GL_AMBIENT n GL_DIFFUSE n GL_SPECULAR n GL_SHININESS n GL_EMISSION

12 COEN Computer Graphics I Setting Material Properties glMaterial[fd]v ( face, prop, params ); face represents which side of a polygon GL_FRONT GL_BACK GL_FRONT_AND_BACK polygon facedness controlled by glFrontFace()

13 COEN Computer Graphics I OpenGL Lights n OpenGL supports at least eight simultaneous lights GL_LIGHT0 - GL_LIGHT[n-1] n Inquire number of lights using glGetIntegerv( GL_MAX_LIGHTS, &n ); glLight[fd]v( light, property, params );

14 COEN Computer Graphics I OpenGL Light Color Properties n GL_AMBIENT n GL_DIFFUSE n GL_SPECULAR

15 COEN Computer Graphics I Types of Lights n Point ( also called Local ) n Directional ( also called Infinite ) n Light’s type determined by its w value w = 0 infinite light w = 1 local light

16 COEN Computer Graphics I Positioning Lights n Light’s positions are modified by ModelView matrix n Three variations fixed in space fixed in a scene total freedom

17 COEN Computer Graphics I Setting up a Fixed Light n Light positioned in eye coordinates identity matrix on ModelView stack n Special case - creating a headlamp imagine wearing a miner’s helmet with a light pass (0 0 0 w) for light’s position GLfloat pos[] = { 0.0, 0.0, 0.0, 1.0 }; glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glLightfv( GL_LIGHT0, GL_POSITION, pos );

18 COEN Computer Graphics I Positioning a Light in a Scene n Light positioned in world coordinates viewing transform only on ModelView stack GLfloat pos[] = { 1.0, 2.0, 3.0, 0.0 }; glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( ex, ey, ez, lx, ly, lz, ux, uy, uz ); glLightfv( GL_LIGHT0, GL_POSITION, pos );

19 COEN Computer Graphics I Arbitrary Light Positioning n Any modeling and viewing transforms on ModelView stack Transform light separately by isolating with glPushMatrix() and glPopMatrix() n Unique motion variable allows light to animate independently of other objects

20 COEN Computer Graphics I Arbitrary Light Positioning (cont. ) GLfloat pos[] = { 0.0, 0.0, 0.0, 1.0 }; glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt( ex, ey, ez, lx, ly, lz, ux, uy, uz ); glPushMatrix(); glRotatef( angle, axis.x, axis.y, axis.z ); glTranslatef( x, y, z ); glLightfv( GL_LIGHT0, GL_POSITION, pos ); glPopMatrix();

21 COEN Computer Graphics I Light Attenuation n Physical light’s brightness diminishes as the square of the distance n Simulate this in OpenGL GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION

22 COEN Computer Graphics I Everything Else … n “Global” lighting parameters are held in the light model glLightModel[fd]v( property, param ); GL_LIGHT_MODEL_AMBIENT GL_LIGHT_MODEL_TWO_SIDE GL_LIGHT_MODEL_LOCAL_VIEWER

23 COEN Computer Graphics I Turning on the Lights n To turn on lighting glEnable( GL_LIGHTING ); turns on the “power”, but not any lights n To turn on an individual light glEnable( GL_LIGHTn );

24 COEN Computer Graphics I OpenGL Lighting Model n At each vertex For each color component

25 COEN Computer Graphics I Computing Surface Normals n Lighting needs to know how to reflect light off the surface n Provide normals per face - flat shading vertex - Gouraud shading pixel - Phong shading –OpenGL does not support Phong natively

26 COEN Computer Graphics I Face Normals n Same normal for all vertices in a primitive results in flat shading for primitive glNormal3f( nx, ny, nz ); glBegin( GL_TRIANGLES ); glVertex3fv( v1 ); glVetrex3fv( v2 ); glVertex3fv( v3 ); glEnd();

27 COEN Computer Graphics I Computing Face Normals ( Polygons ) n We’re using only planar polygons n Can easily compute the normal to a plane use a cross product

28 COEN Computer Graphics I Computing Face Normals ( Algebraic ) n For algebraic surfaces, compute where

29 COEN Computer Graphics I Vertex Normals n Each vertex has its own normal primitive is Gouraud shaded based on computed colors glBegin( GL_TRIANGLES ); glNormal3fv( n1 ); glVertex3fv( v1 ); glNormal3fv( n2 ); glVetrex3fv( v2 ); glNormal3fv( n3 ); glVertex3fv( v3 ); glEnd();

30 COEN Computer Graphics I Computing Vertex Normals ( Algebraic ) n For algebraic surfaces, compute

31 COEN Computer Graphics I Computing Vertex Normals ( Polygons ) n Need two things face normals for all polygons know which polygons share a vertex

32 COEN Computer Graphics I Sending Normals to OpenGL glNormal3f( x, y, z ); Use between glBegin() / glEnd() Use similar to glColor*()

33 COEN Computer Graphics I Normals and Scale Transforms n Normals must be normalized non-unit length skews colors n Scales affect normal length rotates and translates do not glEnable( GL_NORMALIZE );

34 COEN Computer Graphics I Why? n Lighting computations are really done in eye coordinates this is why there are the projection and modelview matrix stacks n Lighting normals transformed by the inverse transpose of the ModelView matrix

35 COEN Computer Graphics I Rasterizing Points n Rendering a point should set one pixel n Which pixel should we set? n Use the following macro #define ROUND(x) ((int)(x + 0.5))

36 COEN Computer Graphics I Where should you draw n viewport is the part of the window where you can render n Need to clip objects to the viewport

37 COEN Computer Graphics I Clipping n Determination of visible primitives n Can clip to an arbitrary shape we’ll only clip to rectangles n Various clip boundaries window viewport scissor box

38 COEN Computer Graphics I Point Clipping n Simple point inside rectangle test xMin xMax yMin yMax (x, y)

39 COEN Computer Graphics I Mathematics of Lines n Point-Intercept form of a line x y b

40 COEN Computer Graphics I Digital Differential Analyzer ( DDA ) n Determine which pixels based on line’s equation slope determines which variable to iterate –for all of our examples, assume y = y1; for( x = x1; x <= x2; ++x ) { setPixel( x, ROUND(y) ); y += m; }

41 COEN Computer Graphics I Adding Color n Along with interpolating coordinates, we can interpolate colors.

42 COEN Computer Graphics I Digital Differential Analyzer ( cont. ) n Advantages simple to implement n Disadvantages requires floating point and type conversion –potentially slow if not in hardware –accumulation of round-off error

43 COEN Computer Graphics I Explicit Form of a Line x y C Another way of saying the same thing

44 COEN Computer Graphics I Why the Explicit Form is your Friend n Creates a Binary Space Partition tells which side of the line your on x y + -

45 COEN Computer Graphics I How does this help render lines? n We can use the explicit form to determine which pixel is closest to the line

46 COEN Computer Graphics I Midpoint Algorithm n Plot first point n Determine which side of the line the midpoint is on evaluate n Choose new pixel based on sign of result n Update

47 COEN Computer Graphics I We can do a little better n Keep a running sum of the error initialize n Choose next pixel based on sign of the error n Incrementally update error based on pixel choice

48 COEN Computer Graphics I Bresenham’s Algorithm dx = x2 - x1; dy = y2 - y1; x = ROUND(x1); y = ROUND(y1); d = 2*dy - dx; do { setPixel( x, y ); if ( d <= 0 ) // Choose d += 2*dy; else { // Choose y++; d += 2*(dy - dx); } } while( ++x < x2 );

49 COEN Computer Graphics I Cohen-Sutherland Line Clipping n Clip to rectangular region n Partition space into regions keep a bit-code to indicate which region a vertex is in

50 COEN Computer Graphics I Cohen-Sutherland Line Clipping (cont.) n Quickly determine if a line is outside the viewport if (mask v1 & mask v2 ) return False; // Don’t render n Or inside if (!(mask v1 | mask v2 )) return True; // render! No clipping needed

51 COEN Computer Graphics I n If quick tests fail … need to clip vertices n Render horizontal span between each edge’s pixel Cohen-Sutherland Line Clipping (cont.)