Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3

Slides:



Advertisements
Similar presentations
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Advertisements

Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
CSPC 352: Computer Graphics
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
Illumination and Shading
Computer Graphics - Class 10
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
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.
Computer Graphics (Fall 2005) COMS 4160, Lecture 16: Illumination and Shading 1
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.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
1 Lecture 10 Lighting in OpenGL. 2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Illumination and Shading
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
SET09115 Intro Graphics Programming
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 7: OpenGL Shading
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.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
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
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
CSE 381 – Advanced Game Programming GLSL Lighting.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
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.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
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.
Improving the appearance of 3D OpenGL scenes
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
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
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Computer Graphics (Fall 2006) COMS 4160, Lecture 16: Illumination and Shading 1
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
CSC Graphics Programming
CSE 167 [Win 17], Lecture 7: OpenGL Shading Ravi Ramamoorthi
Shading To determine the correct shades of color on the surface of graphical objects.
Illumination and Shading
Shading in OpenGL Ed Angel
Lighting Phong's Lighting Model normals
Lighting and Materials
Lighting – Light Sources
Lighting – Material Properties
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Material Colours and Lighting
Presentation transcript:

Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3

Methodology for Lecture  Lecture deals with lighting (teapot shaded as in HW1)  Some Nate Robbins tutor demos in lecture  Briefly explain OpenGL color, lighting, shading  Demo 4160-opengl\opengl3\opengl3-orig.exe4160-opengl\opengl3\opengl3-orig.exe  Lecture corresponds chapter 5 (and some of 4)  But of course, better off doing rather than reading

Importance of Lighting  Important to bring out 3D appearance (compare teapot now to in previous demo)  Important for correct shading under lights  The way shading is done also important glShadeModel(GL_FLAT)glShadeModel(GL_SMOOTH)

Outline  Basic ideas and preliminaries  Types of materials and shading  Ambient, Diffuse, Emissive, Specular  Source code  Moving light sources

Brief primer on Color  Red, Green, Blue primary colors  Can be thought of as vertices of a color cube  R+G = Yellow, B+G = Cyan, B+R = Magenta, R+G+B = White  Each color channel (R,G,B) treated separately  RGBA 32 bit mode (8 bits per channel) often used  A is for alpha for transparency if you need it  Colors normalized to 0 to 1 range in OpenGL  Often represented as 0 to 255 in terms of pixel intensities  Also, color index mode (not so important)

Shading Models  So far, lighting disabled: color explicit at each vertex  This lecture, enable lighting  Calculate color at each vertex (based on shading model, lights and material properties of objects)  Rasterize and interpolate vertex colors at pixels  Flat shading: single color per polygon (one vertex)  Smooth shading: interpolate colors at vertices  Wireframe: glPolygonMode (GL_FRONT, GL_LINE)  Also, polygon offsets to superimpose wireframe  Hidden line elimination? (polygons in black…)

Demo and Color Plates  See OpenGL color plates 1-8  Demo: 4160-opengl\opengl3\opengl3-orig.exe4160-opengl\opengl3\opengl3-orig.exe  Question: Why is blue highlight jerky even with smooth shading, while red highlight is smooth?

Lighting  Rest of this lecture considers lighting on vertices  In real world, complex lighting, materials interact  We study this more formally in next unit  OpenGL is a hack that efficiently captures some qualitative lighting effects. But not physical  Modern programmable shaders allow arbitrary lighting and shading models (not covered in class)

Types of Light Sources  Point  Position, Color [separate diffuse/specular]  Attenuation (quadratic model)  Directional (w=0, infinitely far away, no attenuation)  Spotlights  Spot exponent  Spot cutoff  All parameters: page 195 (should have already read HW1)

Material Properties  Need normals (to calculate how much diffuse, specular, find reflected direction and so on)  Four terms: Ambient, Diffuse, Specular, Emissive

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  Such as splines. GLUT does it automatically for teapot, cylinder,…

Outline  Basic ideas and preliminaries  Types of materials and shading  Ambient, Diffuse, Emissive, Specular  Source code  Moving light sources

LightMaterial Demo Demo

Emissive Term Only relevant for light sources when looking directly at them Gotcha: must create geometry to actually see light Emission does not in itself affect other lighting calculations

Ambient Term  Hack to simulate multiple bounces, scattering of light  Assume light equally from all directions

Ambient Term  Associated with each light and overall light  E.g. skylight, with light from everywhere Most effects per light involve linearly combining effects of light sources

Diffuse Term  Rough matte (technically Lambertian) surfaces  Light reflects equally in all directions N -L

Diffuse Term  Rough matte (technically Lambertian) surfaces  Light reflects equally in all directions  Why is diffuse of light diff from ambient, specular? N -L

Specular Term  Glossy objects, specular reflections  Light reflects close to mirror direction

Specular Term  Glossy objects, specular reflections  Light reflects close to mirror direction  Consider half-angle between light and viewer s N

Demo  What happens when we make surface less shiny?  What happens to jerkiness of highlights?

Outline  Basic ideas and preliminaries  Types of materials and shading  Ambient, Diffuse, Emissive, Specular  Source code  Moving light sources

Source Code (in display) /* New for Demo 3; add lighting effects */ /* See hw1 and the red book (chapter 5) for details */ { GLfloat one[] = {1, 1, 1, 1}; // GLfloat small[] = {0.2, 0.2, 0.2, 1}; GLfloat medium[] = {0.5, 0.5, 0.5, 1}; GLfloat small[] = {0.2, 0.2, 0.2, 1}; GLfloat high[] = {100}; GLfloat light_specular[] = {1, 0.5, 0, 1}; GLfloat light_specular1[] = {0, 0.5, 1, 1}; GLfloat light_position[] = {0.5, 0, 0, 1}; GLfloat light_position1[] = {0, -0.5, 0, 1}; /* Set Material properties for the teapot */ glMaterialfv(GL_FRONT, GL_AMBIENT, one); glMaterialfv(GL_FRONT, GL_SPECULAR, one); glMaterialfv(GL_FRONT, GL_DIFFUSE, medium); glMaterialfv(GL_FRONT, GL_SHININESS, high);

Source Code (contd) /* Set up point lights, Light 0 and Light 1 */ /* Note that the other parameters are default values */ glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_DIFFUSE, small); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular1); glLightfv(GL_LIGHT1, GL_DIFFUSE, medium); glLightfv(GL_LIGHT1, GL_POSITION, light_position1); /* Enable and Disable everything around the teapot */ /* Generally, we would also need to define normals etc. */ /* But glut already does this for us */ glEnable(GL_LIGHTING) ; glEnable(GL_LIGHT0) ; glEnable(GL_LIGHT1) ; if (smooth) glShadeModel(GL_SMOOTH) ; else glShadeModel(GL_FLAT) ; }

Outline  Basic ideas and preliminaries  Types of materials and shading  Ambient, Diffuse, Emissive, Specular  Source code  Moving light sources

Moving a Light Source  Lights transform like other geometry  Only modelview matrix (not projection). The only real application where the distinction is important  See types of light motion pages 202-  Stationary light: set the transforms to identity before specifying it  Moving light: Push Matrix, move light, Pop Matrix  Moving light source with viewpoint (attached to camera). Can simply set light to so origin wrt eye coords (make modelview matrix identity before doing this)

Lightposition demo Lightposition demo