1 / 87

CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University

Lighting & Shading. CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University. Outline. Color Illumination models Global illumination model Local illumination model (our focus) Light sources Reflection model & material properties Polygonal shading. Coloring vertices.

dwaller
Download Presentation

CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lighting & Shading CSC4820/6820 Computer Graphics AlgorithmsYing ZhuGeorgia State University

  2. Outline • Color • Illumination models • Global illumination model • Local illumination model (our focus) • Light sources • Reflection model & material properties • Polygonal shading

  3. Coloring vertices • We have learned where to draw a vertex on the final 2D image • Now we discuss how to set the color for a vertex • Different ways to assign color to a vertex • Assign color to vertex directly • Let OpenGL calculate the vertex color based on its lighting model • Write a vertex shader to do lighting your way • Use OpenGL extension or pixel shader to do per-pixel lighting • Leave it entirely to texture mapping

  4. Color • When white light is incident on a surface some wavelengths are absorbed and others are reflected. • This gives us the perception of the color of the object. • When the human eye “sees” something, it is because the reflected light enters the eye and hits a light detector on the retina. • In computer graphics, we usually use three colors, called the primary colors, to produce a range of colors called the color gamut.

  5. RGB Color Model • In the RGB color model, we use red, green, and blue as the 3 primary colors. • There are no real three colors that can be combined to give all possible colors. • But a good choice of three colors provides a color gamut that covers most colors.

  6. Color Index • In color-index mode, a single number (called the color index) is stored for each pixel. • Each color index indicates an entry in a table that defines a particular set of R, G, and B values. • Such a table is called a color map. • Color map is usually controlled by window system, not by OpenGL.

  7. Color Mode in OpenGL • In OpenGL, you choose to use either RGB mode or color-index mode, but not both. • Most of the time we use RGB mode. • Color-index is useful in some cases: • Porting an application that already uses color-index mode. • Color map animation: if the contents of an entry in the color map change, then all pixels of that color index change their color.

  8. Color Mode in OpenGL • Specify display mode: • glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); or • glutInitDisplayMode(GLUT_INDEX|GLUT_DOUBLE); • Cannot be changed after initialization.

  9. Directly set color for vertices • Use the fragment shader out vec4 fragColor; void main() { fragColor = vec4(0.0, 0.0, 0.0, 1.0); }

  10. When to set vertex color directly? • When you know exactly what color to use for each vertex • When you don’t care about lighting and realism • When you don’t have enough information for lighting calculation • E.g. you don’t have the surface normals, etc. Without lighting With lighting

  11. Use OpenGL lighting model • Normally we use OpenGL lighting model to calculate color for each vertex • First, some background about illumination model

  12. Main ideas about light • Light is a set of little particles (photons) flying around • Each photon has a wavelength and an energy • When photons hit things they bounce, losing at least some of their energy. • When they lose most of the energy, they are “absorbed”. • How to model the way photons bounce? • The illumination model

  13. Illumination Models • Illumination: the transport of photons from light source via direct or indirect paths. • Illumination models: how light reflects from surfaces and produces what we perceive as color. • In general, light leaves some light source, e.g. a lamp or the sun, is reflected from many surfaces and then finally reflected to our eyes

  14. Illumination Models shadow multiple reflection translucent surface

  15. Illumination Models • Local illumination model: a surface point only receives light particles directly from the light source • Relatively simple and fast • The shading of any surface is independent from the shading of all other surfaces. • Not physically correct, but looks OK • OpenGL and Direct3D use only local illumination model.

  16. Illumination Models • Global illumination model: a surface point receives light after the light rays interact with other objects in the scene. • Consider light reflected by other surfaces • Physically correct, but very expensive • E.g. ray tracing, radiosity.

  17. Global Illumination Overview • There are several important effects that can not be simulated with a local illumination model: • Shadows • Refraction and transparency • Inter-object reflections • A better solution is global illumination. • More physically correct and produces more realistic images. • Also more computationally expensive than local illumination model.

  18. Global Illumination Overview • Main algorithms for global illumination • Multi-pass rendering • Radiosity (primarily for indoor scenes) • Ray tracing • This is a brief overview. Details about ray tracing and radiosity will be covered later

  19. Multi-pass Rendering • Render the same scene multiple times and combining the results. • A relatively “cheap” way to fake global illumination. • E.g. Quake III engine can do 10 passes on fast systems • This is the predominant approach for realistic imagery in real-time applications. • Many advanced rendering techniques fall into this category. • E.g. shadow, light map, etc.

  20. Radiosity • Simulate the energy transfer between surface patches at the physical level. • The basis of the radiosity rendering algorithm. • This is the most accurate method to simulate surface interactions such as between walls inside a building. • Very expensive (hours per frame)

  21. Ray Tracing • Ray tracing is currently the highest quality global illumination algorithm. • Many extensions include photon maps (for caustics), sky light, soft shadows, volumetric effects (fog, water) ,etc. • Can be very slow (minutes to hours per frame) • Real-time ray tracing may be on the way

  22. Global Illumination: state-of-the-art • Commercial packages use a combination of multi-pass rendering, radiosity, and ray tracing. • Lightwave, Mental Ray, Brazil r/s, etc.

  23. Components of Illumination Model • Light sources with following parameters • Color • Position and direction • Directional attenuation • Surface properties with following parameters • Color (Reflectance Spectrum) • Geometry (position, orientation, etc.) • Absorption

  24. Steps in OpenGL lighting • Now back to local illumination model • Steps in OpenGL lighting: • Specify light source parameters in the OpenGL program • Specify surface material parameters in the OpenGL program • Pass the light source and surface material parameters to GLSL shaders • Perform the lighting calculation in either the vertex shader or fragment shader

  25. Illumination Models • Illumination: the transport of photons from light source via direct or indirect paths. • Illumination models: how light reflects from surfaces and produces what we perceive as color. • In general, light leaves some light sources, e.g. a lamp or the sun, is reflected from many surfaces and then finally reflected to our eyes

  26. Light Sources • General light sources are difficult to work with because we must integrate light coming from all points on the source • OpenGL uses simple empirical models

  27. Typical OpenGL Light Sources • Ambient light source (e.g. reflected light) • Same amount of light everywhere in scene • No position, no direction, just a constant light value • Directional light (e.g. sun) • Has a direction but no specific location • Point light source (e.g. light bulb) • Has a location but light is emitted equally to all directions • Spotlight (e.g. headlight) • Has a position and light direction is restricted

  28. Ambient Light Source • Even though an object in a scene is not directly lit, it will still be visible. This is because light is reflected indirectly from nearby objects. • Ambient light source models this indirect illumination. • Ambient light has no spatial or directional characteristics. The amount of ambient light is a constant for all surfaces in the scene. • A very crude way of simulating indirect illumination.

  29. Point Light Source • The rays emitted from a point light equally to all directions. • This is an approximation to a light bulb with • Intensity ( ) • Position (P) • Factors (a, b, c) for light attenuation with distance (d) between P and surface vertex.

  30. Directional Light Sources • All of the light rays from a directional light source have a common direction, and no point of origin. • Models a point light source at infinity. • No attenuation with distance because distance is . • Commonly used to simulate sunlight.

  31. Spot Light Sources • Models point light source with direction: • Intensity ( ) • Position (P) • Direction (D) • Factors (a, b, c) for attenuation with distance (d). • For normalized vectors D and L, Dot Product

  32. Spot Light Sources • Spotlights are characterized by a narrow range of angles through which light is emitted • Consider spotlight as a light cone with apex at P, direction D, and width defined by an angle • Light distribution within the cone is defined by • Where approximates the light attenuation along the cone angle

  33. Other Light Sources • Area light sources • Light source occupies a 2D area (usually a polygon). • Extended light sources • Spherical light source • Elliptical light source • Cylindrical light source • Volumetric light source • With shaders, you can implement different kinds of light sources.

  34. Illumination Models • Illumination models: how light reflects from surfaces and produces what we perceive as color. • In general, light leaves some light source, e.g. a lamp or the sun, is reflected from many surfaces and then finally reflected to our eyes • We have discussed light sources. Now we discuss surface material properties

  35. Light-Material Interaction • Light-material interactions cause each point to have a different color or shade. • Light that strikes an object is partially absorbed and partially scattered (reflected) • The amount reflected determines the color and brightness of the object • A surface appears red under white light because the red component of the light is reflected and the rest is absorbed • The reflected light is scattered in a manner that depends on the smoothness and orientation of the surface

  36. Surface Types • The smoother a surface, the more reflected light is concentrated in the direction a perfect mirror would reflected the light • A very rough surface scatters light in all directions rough surface smooth surface

  37. Phong Reflectance Model • A simple reflectance model proposed by Bui-Thong Phong • Can be computed rapidly • Not physically correct, but the result looks right. • Adopted by OpenGL & Direct3D • Has four components • Diffuse reflection + Specular reflection + Ambient + Emission • Thus each light source (except for ambient light) has separate diffuse, specular, and ambient components

  38. Phong Reflectance Model • Defines four vectors • vertex to light source vector (light vector l) • Vertex to eye vector (view vector v) • Vertex normal (n) • Light reflection vector (r)

  39. OpenGL lighting equation • The final result I is a color component • This calculation is performed 3 times for R, G, B respectively Calculate for each light source separately and then add them up Diffuse component Ambient component Specular component Emission Distance Term for point/spotlight

  40. Diffuse Reflection • Assume surface reflects equally in all directions. • An ideal diffuse surface is a very rough surface: e.g. clay. • Ideal diffuse reflectors reflect light according to Lambert’s cosine law.

  41. Lambert’s Cosine Law • Lambert’s law determines how much of the incoming light energy is reflected. • Amount of light reflected is proportional to the vertical component of incoming light. • reflected light ~cos qi • cos qi = l · n if vectors normalized, where l is light vector, n is normal.

  42. Diffuse Component Vector dot product • : incoming light diffuse intensity (light intensity at the vertex) • : diffuse reflection coefficient. • n : vertex’s normal. • l : normalized vector from vertex to light source

  43. Specular Reflection • Most surfaces are neither ideal diffusers nor perfectly specular (ideal refectors). • Smooth surfaces show specular highlights due to incoming light being reflected in directions concentrated close to the direction of a perfect reflection. • E.g. mirrors, metals Specular Highlight

  44. Specular Component • Phong proposed using a term that dropped off as the angle between the viewer and the ideal reflection increased • V is vertex-to-eye vector, r is light reflection vector Incoming Light’s specular intensity Shininess Coefficient Specular Coefficient

  45. The Shininess Coefficient • Values of between 100 and 200 correspond to metals • Values between 5 and 10 give surface that look like plastic • The larger the value, the closer the eye vector has to be to the perfect reflection vector to see the specular highlight • This means highershininess -90 f 90

  46. Blinn & Torrance Variation • Uses the halfway vector h between l and v h Vertex normal

  47. Blinn & Torrance Variation • By using the halfway vector h, we do not need to compute the reflection vector r at very vertex. • Computing h is a lot cheaper.

  48. Distance Term • The light from a point source that reaches a surface is inversely proportional to the square of the distance between them • Phong model adds a factor of the form 1/(a + bd +cd2) to the diffuse and specular components. • The constant and linear terms soften the effect of the point source.

  49. Ambient Component • Ambient light is the result of multiple interactions between (large) light sources and the objects in the environment • Amount and color depend on both the color of the light(s) and the material properties of the object • A very crude approximation of global illumination. • May also define a global ambient light term Reflection Coefficient Intensity of Ambient light

  50. Putting it all together • The final result I is a color component • This calculation is performed 3 times for R, G, B respectively Calculate for each light source (except for ambinet) separately and then add them up Diffuse component Ambient component Specular component Distance Term for point/spot light

More Related