Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.

Slides:



Advertisements
Similar presentations
2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods Jack van Wijk TU/e.
Advertisements

Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
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.
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.
IMGD 1001: Illumination by Mark Claypool
CS 4731: Computer Graphics Lecture 16: Illumination Models Part 2 Emmanuel Agu.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Now Playing: Multiply Jamie Lidell from Multiply Released June 13, 2005.
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
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.
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 6: Shading Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
Shading in OpenGL.
1 Chapter 6 Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
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
08 |Lighting and Shading Eriq Muhammad Adams J |
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
CG Summary: OpenGL Shading andTextures Angel, Chapters 5, 7; “Red Book” slides from AW, red book, etc. CSCI 6360/4360.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
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);
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Local Illumination and Shading
Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 Computer Graphics Three-Dimensional Graphics V.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
Shading To determine the correct shades of color on the surface of graphical objects.
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
CSC461: Lecture 23 Shading Computation
Shading in OpenGL Ed Angel
Lighting and Shading Lab 8:.
Lighting Phong's Lighting Model normals
Illumination and Shading
Lighting and Materials
CS5500 Computer Graphics April 10, 2006.
Lighting – Material Properties
Lighting and Shading Lab 8:.
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:

Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1

2 Constant (Flat) Shading (polygon based) The shade of a surface is the amount of ambient, diffuse and specular light reflected from the surface In constant shading, the reflection calculation only carried out once for a point on a polygon, e.g., the first vertex. The resulting shade is assigned to all pixels covered by the polygon. The surface normal is used in calculation The entire polygon has the same shade Efficient but often too coarse n

3  A Mach band is a stripe found along the edge of two polygons of different shades. Mach bands often occur in constant shading. Our eyes are particularly sensitive to the discrete change of shade

4 Gouraud shading (vertex based) Shading calculation is carried out for each vertex of a polygon. Each vertex is assigned a normal that may be the normal of the polygon, or the average of the normals of adjacent polygons. The shade of the pixel at a vertex is calculated using the normal assigned to the vertex n4n4 n3n3 n2n2 n1n1 n0n0 nbnb ncnc nana ndnd n

5 The shades of other pixel covered by the a polygon is obtained though interpolation Example: The color of an in-between point, C, is determined by ABC

6 Determine the colors of a pixel covered by a polygon More general, if a polygon has k vertices B A C F

7 Constant Shading Gouraud Shading

8

9 Phong Shading (pixel based)  Phong shading interpolates the normal across a polygon. Then use the normal of a pixel to calculate the shade of the pixel  Using Gouraud shading, we often need to cut a surface into very small pieces in order to obtain satisfactory result. Phong shading reduces the excessive cutting but requires more calculation.  It may produce quality pictures but much slower B A C F

10 2. Lighting in OpenGL Enable/Disable lighting glEnable( GL_LIGHTING ); glDisable( GL_LIGHTING ); Specify a shading model Either flat shading (Constant) or smooth (Gouraud) shading glShadeModel( GL_FLAT ); glShadeModel( GL_SMOOTH ); To specify a normal for each vertex. glNormal3f( x, y, z); glVertex3f( x, y, z);

11 A normal remains in effect until another normal is specified. //Draw a cylinder glBegin( GL_QUAD_STRIP); t = 0.; dt = (360. / nslice) * / 180.; for (j = 0; j <= nslice; ++j) { glNormal3f( cos( t), 0., sin( t)); glVertex3f( cos( t), 0., sin( t)); glVertex3f( cos( t), 2., sin( t)); t = t + dt; } glEnd(); z y x

12 To avoid the troublesome of providing unit vectors for normals, you may ask the system to normalize the vectors for you by adding the following in init() glEnable( GL_NORMALIZE); Specify the color components (r, g, b, a) of a light source GLfloat ambient0[] = { 0.1, 0.1, 0.1, 1.};//Grey GLfloat diffuse0[] = { 1., 1., 1., 1.}; //White GLfloat specular0[] = { 1., 1., 1., 1.};//White glLightfv( GL_LIGHT0, GL_AMBIENT, ambient0); glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightfv( GL_LIGHT0, GL_SPECULAR, specular0);

13 In real life, the diffuse and specular components of a light source are often similar. The ambient component depends on the environment. If the environment consists of many red objects, then the ambient component tends to be slightly red. GLfloat a[] = { 0.1, 0., 0., 1.};//Very pale red GLfloat d[] = { 1., 1., 0., 1.}; //Yellow GLfloat s[] = { 1., 1., 0., 1.};//Yellow glLightfv( GL_LIGHT0, GL_AMBIENT, a); glLightfv( GL_LIGHT0, GL_DIFFUSE, d); glLightfv( GL_LIGHT0, GL_SPECULAR, s);

14 Opengl has defined a dark grey (.2,.2,.2) global ambient source. To change these to (r, g, b), call float globalAmbient[] = { r, g, b, 1.}; glLightModelfv( GL_LIGHT_MODEL_AMBIENT, globalAmbient ); To specify the position of a point light source GLfloat light_position[] = { 2., 4., 6., 1.}; glLightfv( GL_LIGHT0, GL_POSITION, light_position); To specify the direction of a directional light source GLfloat light_position[] = { 1., 1., 1., 0.}; glLightfv( GL_LIGHT1, GL_POSITION, light_position);

15 There are up to 8 light sources GL_LIGHT0, GL_LIGHT1, …, GL_LIGHT7 To turn on/off a particular light source (right before/after the drawing) glEnable( GL_LIGHT0); glDisable( GL_LIGHT0); In the default mode, OpenGL assumes that the viewer is at infinite distance such that the viewing angle is a constant. This approximation may cause serious error when the viewer is actually close to an object. To ask OpenGL to use the true viewing angle in the calculation of specular reflection. glLightModeli( GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

16 The effect of mesh sizes (Important) In the following, a shinny white wall cutting into various sizes is rendered with a directional white light. GLfloat ambient0[] = { 0., 0., 0., 1.}; GLfloat diffuse0[] = {.7,.7,.7, 1.}; GLfloat specular0[] = { 1., 1., 1., 1.}; position[] = { 0., 0., 1., 0.}; //Light direction //Viewing position (0, 0, 8) 20 × × 104 × 42 × 21 × 1

17  A comparison of directional source and point source on shiny white objects. Viewing position is at (0, 0, 8) Point source at (0,0,8) Dir. source at (0,0,1)

18 For point light source, we may specify the constants in the formula of the attenuation factor glLightf( GL_LIGHT1, GL_CONSTANT_ATTENUATION,.0); glLightf( GL_LIGHT1, GL_LINEAR_ATTENUATION,.5); glLightf( GL_LIGHT1, GL_QUADRATIC_ATTENUATION, 0.); The default is a = 1, b = 0, c = 0 (no attenuation) For higher attenuation, set larger values for b and c, e.g., 1, 1.5, 2 or 3.

19 To define a spot light (a point source) The color components, position and attenuation constants are specified in the same way as an ordinary point source. In addition, we can specify the spot light direction and the cut-off angle

GLfloat light_direction[] = {0, 0, -1}; //From the light glLightfv( GL_LIGHT2, GL_SPOT_DIRECTION, light_direction); glLightf( GL_LIGHT2, GL_SPOT_CUTOFF, 20.);  The effects of cutoff angle on a white wall

21 e = 0e = 10 e = 100 You can also set the GL_SPOT_EXPONENT The default is 0 that implies uniform distribution of light intensity from the center to the rim A higher spot exponent results in a higher intensity around the center. glLightf( GL_LIGHT2, GL_SPOT_EXPONENT, 10.);

22 To specify the reflectances of a shiny red material GLfloat diffuse[] = {.41,.135,.067, 1.}; GLfloat specular[] = {1., 1., 1., 1.}; glMaterialfv( GL_FRONT, GL_AMBIENT, diffuse); glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse); glMaterialfv( GL_FRONT, GL_SPECULAR, specular); glMaterialf( GL_FRONT, GL_SHININESS, 125.); The direction of the white light source is (1,1,1)

23 Reflectance of a material The red, green and blue components of the specular reflectance are often the same so that the original color of a light source is reflected. (In the preceding picture of the teapot, the highlight is white, the same as the light source.) For highly shiny material, the specular reflectance is close to 1 and the shininess can be as high as 100 or more. The specular reflectance and shininess of a dull surface are close to 0. A material property, eg, reflectance, remains in effect until a new value is specified.

24 The color of a material mainly depends on the diffuse reflectance. The diffuse reflection alone provides most information about the curvature and the depth of an object The ambient reflectance of a material is often the same as the diffuse reflectance The highlights produced in specular reflections are the blurred images of the light sources.

Lecture light and shading II 25 Overall Pure DiffusePure Ambient Pure Specular

26 The pale yellowish pink material GLfloat ambient[] = {.6,.59,.42, 1.}; GLfloat diffuse[] = {.5,.5,.35, 1.}; GLfloat specular[] = {.1,.1,.07, 1.}; glMaterialfv( GL_FRONT, GL_AMBIENT, ambient); glMaterialfv( GL_FRONT, GL_DIFFUSE, diffuse); glMaterialfv( GL_FRONT, GL_SPECULAR, specular); glMaterialf( GL_FRONT, GL_SHININESS, 1.); The light source is a directional white light coming from (1, 1, 1)

27 Emission To make a material appear to be glowing, eg, the moon in the picture next page. GLfloat emission[] = { r, g, b, a}; glMaterialfv( GL_FRONT, GL_EMISSION, emission); Turn off the emission: assign 0 to the r-, g-, b-components. Note that an emission object is NOT a light source. Emission is just a property of material. GLfloat emission[] = { 1., 1.,.75, 1.}; glMaterialfv( GL_FRONT, GL_EMISSION, emission); draw_moon(); GLfloat no_em[] = { 0., 0., 0., 1.}; glMaterialfv( GL_FRONT, GL_EMISSION, no_em);

28 A pictures rendered with 5 kinds of material, two textures, 16 spot lights. The moon is an emission object.

29 Transparent Objects 1. Define the blending function and turn on blending glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable( GL_BLEND); 2. Define the material with the opacity less than Draw the background objects before drawing the transparent objects. Draw both front and back faces as filled polygons. void transMaterial1() { GLfloat a[] = {.7, 1.,.85,.3}; GLfloat s[] = { 1., 1., 1., 1.}; glMaterialfv( GL_FRONT, GL_AMBIENT, a); glMaterialfv( GL_FRONT, GL_DIFFUSE, a); glMaterialfv( GL_FRONT, GL_SPECULAR, s); glMaterialf( GL_FRONT, GL_SHININESS, 100.); }