Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.

Similar presentations


Presentation on theme: "Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008."— Presentation transcript:

1 Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008

2 Lighting Principles  Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting settings  OpenGL uses an additive color model  Phong lighting computation at vertices

3 Lighting Principles  Light that is directly reflected off the surface creates a specular highlight  Light that is absorbed into the material before it is reflected creates the color we see. (Diffuse color)  Material's appearance is the result of a combination of several light and material properties

4 Lighting Principles  Lighting simulates how objects reflect light –Material composition of object –Light’s color and position –Global lighting parameters Ambient light Two sided lighting –Available in both color index and RGBA mode

5 How OpenGL Simulates Lights  Phong lighting model –Computed at vertices  Lighting contributors –Surface material properties –Light properties –Lighting model properties

6 Phong Reflection Model I = I a + I d + I s I = L a R a + L d R d + L s R s

7 Determining Vertex Color  Vertex color = The material emission at that vertex + The global ambient light scaled by the material's ambient property at that vertex + The ambient, diffuse, and specular contributions from all the light sources, properly attenuated

8 Surface Normals  Color determined by several factors –Surface normal and color –Light position –Eye position N

9 Surface Normals  Normals define how a surface reflects light Glnormal3f( x, y, z ) –Current normal is used to compute vertex’s color –Use unit normals for proper lighting

10 Light Sources  glLightfv( light, property, value ); –light specifies which light –multiple lights, starting with GL_LIGHT0  Infinite and local lights  Local lights can also be spot lights ( the local light will shine in a direction and its light will be limited to a cone centered around that direction vector. –GL_SPOT_DIRECTION defaults down -z –GL_SPOT_CUTOFF angle from center of light to edge of cone –GL_SPOT_EXPONENT concentration: 0 is uniform 128 is concentrated

11 Types of Lights  OpenGL supports two types of lights –Local (point) light sources –Infinite (directional) light sources  Type of light controlled by w coordinate

12 Turning on the Lights  Flip each light’s switch glEnable( GL_LIGHT n );  Turn on the power glEnable( GL_LIGHTING );

13 Light in OpenGL  Ambient light  Diffuse light  Specular light

14 Ambient Light  Uniform light level  Light has been scattered so much that you can't tell where it comes from  Appears to come from all directions  Constant throughout the scene  A kludge  Ambient light is scattered equally in all directions after hitting an object

15 Diffuse Light  Comes from one direction.  So it's brighter if it comes squarely down on a surface than if it barely glances off the surface.  After hitting a surface, it's scattered equally in all directions. –It appears equally bright, no matter where the eye is located.  Any light coming from a particular position or direction probably has a diffuse component.

16 Specular Light  Comes from a particular direction.  Bounces off the surface in a preferred direction.  A well-collimated laser beam bouncing off a high-quality mirror produces almost 100 percent specular reflection.  Specularity as shininess.

17 Specifying Light Sources in OpenGL  Light sources have a number of properties, such as color, position, and direction.  void glLight{if}[v](GLenum light, GLenum pname, TYPEparam);  Creates the light specified by light, which can be GL_LIGHT0, GL_LIGHT1,..., or GL_LIGHT7.  The characteristic of the light being set is defined by pname.

18 Position  Directional light source –Located infinitely far away from the scene –Rays of light can be considered parallel by the time they reach an object –Sun  Positional light source –Located near to the scene –The direction from which the light rays come –Desk lamp

19 Which Image Below Uses a Directional Light?

20 Attenuation  For real-world lights –The intensity of light decreases as distance from the light increases  OpenGL attenuates a light source by multiplying the contribution of that source by an attenuation factor:

21 Light Sources  Light color properties –GL_AMBIENT –GL_DIFFUSE –GL_SPECULAR  Light attenuation –GL_CONSTANT_ATTENUATION –GL_LINEAR_ATTENUATION –GL_QUADRATIC_ATTENUATION

22

23 Lighting Example GLfloat white[] = { 1, 1, 1, 0 }; GLfloat magenta[] = { 0.8, 0, 0.8, 0 }; GLfloat pos[] = { 2.5, 6, 3.5, 1.0 }; glLightfv( GL_LIGHT0, GL_AMBIENT_AND_DIFFUSE, magenta ); glLightfv( GL_LIGHT0,GL_SPECULAR,white); glLightfv( GL_LIGHT0, GL_POSITION, pos ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHTING );

24 Enabling Lighting  Turn on lighting calculations –glEnable( GL_LIGHTING );  Turn on each light –glEnable( GL_LIGHTn );

25 Spotlights  Lighting attributes GL_SPOT_DIRECTION GL_SPOT_CUTOFF GL_SPOT_EXPONENT

26 Lighting Features  Light attenuation –decrease light intensity with distance GL_CONSTANT_ATTENUATION GL_LINEAR_ATTENUATION GL_QUADRATIC_ATTENUATION

27 Material Specification in OpenGL  glMaterial assigns values to material parameters.  Front-facing, is used to shade points, lines, bitmaps, and front-facing polygons.  Back-facing, is used to shade back-facing polygons only when two-sided lighting is enabled.

28

29 Material Properties  Define the surface properties of a primitive glMaterialfv( face, property, value ); –Separate materials for front and back

30 Specifying Material Properties  glMaterialfv( face, property, value );  Material properties –GL_EMISSION –GL_AMBIENT –GL_DIFFUSE –GL_SPECULAR –GL_SHININESS  Polygons have material properties for front and back sides

31 Setting Material Properties GLfloat green[] = { 0.0, 1.0, 0.0, 0.5 }; GLfloat red[] = { 1.0, 0.0, 0.0, 0.75 }; GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green ); glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, red ); glMaterialfv( GL_FRONT, GL_SPECULAR, white ); glMaterialf( GL_FRONT_AND_BACK, GL_SHININESS, 100.0 );

32 Ambient Reflectance  Affects the overall color of the object.  Ambient reflectance is most noticeable where an object receives no direct illumination. –Diffuse reflectance is brightest where an object is directly illuminated.  Object’s total ambient reflectance is affected by the global ambient light and ambient light from individual light sources.  Ambient reflectance isn't affected by the position of the viewpoint.

33 Specular Reflectance  Specular reflection from an object produces highlights.  The amount of specular reflection seen by a viewer does depend on the location of the viewpoint. –It's brightest along the direct angle of reflection.

34 Specular Reflectance  Characteristics of specular highlight set with shininess exponent (0.0-128.0) –High value - concentrated specular reflection –Low value - larger less concentrated (more diffuse) specular reflection

35 Diffuse Reflectance  Plays the most important role in determining what you perceive the color of an object to be.  Affected by the color of the incident diffuse light and the angle of the incident light relative to the normal direction. –It's most intense where the incident light falls perpendicular to the surface.  Position of the viewpoint doesn't affect diffuse reflectance.

36 Emissive Reflectance  Make an object appear to be giving off light of that color.  Most real-world objects (except lights) don't emit light, you'll probably use this feature mostly to simulate lamps and other light sources in a scene.  Give appearance of slightly glowing. –They're not actually acting as light sources. –Create a light source and position it at the same location as the sphere to create that effect.

37  Different material properties that approximate real materials.  1st column has materials (from top to bottom) emerald, jade, obsidian, pearl, ruby, and turquoise.  2nd column resembles brass, bronze, chrome, copper, gold, and silver.  3rd column represents various colors of plastic: black, cyan, green, red, white, and yellow.  4 th column is drawn with similar colors of rubber.

38 Real-world and OpenGL Lighting  They are VERY different.  OpenGL lighting gives realistic results, while minimizing computation.

39 Tips for Better Lighting  Recall lighting computed only at vertices –Model tessellation heavily affects lighting results Better results but more geometry to process  Use a single infinite light for fastest lighting –Minimal computation per vertex

40 Light Position Tutorial

41 Twelve Spheres With Different Material Parameters. The row properties are as follows: row 1 - No ambient reflection row 2 - Grey ambient reflection row 3 - Blue ambient reflection. Column 1 - uses a blue diffuse material color with no specular properties Column 2 - The second column adds white specular reflection with a low shininess exponent Column 3 - The third column uses a high shininess exponent and thus has a more concentrated highlight. Column 4 - The fourth column uses the blue diffuse color and, instead of specular reflection, adds an emissive component.

42 Polygon Rendering  Shading calculations require a tremendous amount of processing  Based on polygon normals or vertex normals and pixel color

43 Local Illumination Algorithms  Wireframe  Faceted or flat shading  Gouraud shading  Phong shading

44 Wireframe  Shows underlying structure  No surfaces are visible  No shading necessary

45 Flat or Faceted  Polygon is shaded with a single color  If polygon normal points toward a light, the surface is illuminated

46 Interpolative Shading - OpenGL  For each polygon. –Calculate lighting at each vertex using the normal for the polygon. –Interpolate color between the vertices. –Interpolate color along the scan lines.

47 Gouraud Shading  May be done in hardware  Uses vertex normals  Interpolated vertex normals to calculate light at every pixel

48 Gouraud  Uses vertex normals  Colors are calculated for vertices  Colors are interpolated between the polygon edges  May be done in hardware

49 Gouraud  Uses vertex normals  Colors are calculated for vertices  Colors are interpolated between the polygon edges  May be done in hardware

50 Phong Shading  Calculates surface normals at vertices  Interpolates surface normals between vertices  Calculates color of surface

51 Phong Shading  Almost always done off line  Better quality than Gouraud  Increased rendering time

52 Phong Shading  Uses vertex normals  Interpolated vertex normals to calculate light at every pixel  Almost always done off line

53 Lighting Principles Review  Light that is directly reflected off the surface creates a specular highlight  Light that is absorbed into the material before it is reflected creates the color we see. (Diffuse color)  Material's appearance is the result of a combination of several light and material properties

54 Local Illumination  Local –Contribution from the light that goes directly from the light source and is reflected from the surface –Shading of any surface is independent from the shading of all other surfaces

55 Global Illumination  Contribution from the light that goes directly from the light source and is reflected from the surface  Contribution from the light that is reflected from other surfaces to the current surface

56 Photorealism Vs Lighting Visualization  Photorealism –Mimic reality but not physically real (ambient light) –Look real –Approximate interplay of lighting  Lighting visualization –Used when lighting must match real world –Calculates scene lighting from reality –Distinguishes between natural and electric lights

57 Homework!  Email me your source code for your completed project 3/21.  Be ready to demonstrate your project 1 in class 3/24.  For Thursday: review chapter 8  For Tuesday: read chapter 10


Download ppt "Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008."

Similar presentations


Ads by Google