Download presentation
Presentation is loading. Please wait.
Published byAbner Underwood Modified over 8 years ago
1
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul
2
Topics ● Hidden-surface removal & depth buffer ● OpenGL lighting model ● Material properties
3
A Hidden-Surface Removal Survival Kit
4
Hidden-Surface Removal ● A objects located far from the viewpoint should be obscured by the other object located nearer. ● Usually achieved using depth buffer. ● Depth test: For each fragment in the framebuffer, tests if the incoming fragment is closer to the view plane than the existing one.
5
Depth Buffer ● Keeps the nearest depth(distance) from the viewpoint. ● Without depth test, objects rendered early are obscured by those rendered later, regardless of their positions. ● Worst case: when two objects overlap.
6
Depth Buffer (cont'd) ● Needs to be created at the beginning by glutInitDisplayMode. ● Depth test needs to be enabled by glEnable. ● Needs to be initialized with the largest possible values. ● Needs to be cleared at each rendering frame by glClear.
7
Real-World and OpenGL Lighting
8
OpenGL Lighting Model ● Light broken into RGB components. ● Material characterized by the percentages of the incoming RGB components that are reflected in various directions. ● Approximate lighting equation. ● Lighting composed of four independent components: ambient, diffuse, specular, emissive.
9
Ambient Light ● Light scattered (a lot) by the environment, e.g., walls. ● No direction. (coming from all directions) ● When strikes a surface, scattered equally in all directions. ● Examples: backlighting in a room
10
Diffuse Light ● “Color of light” ● Comes from one direction. ● Changes brightness depending on the angle. ● When hits a surface, scattered equally in all directions. ● Doesn't depend on the viewpoint.
11
Specular Light ● Comes from one direction. ● Bounces off the surface in a preferred direction. ● “shininess” ● Color of “highlight” ● Should be set to the same value as the diffuse color for realistic effect.
12
Materials ● Ambient, diffuse, and specular each determine the ambient, diffuse, and specular reflectances of the material. ● Ambient and diffuse reflectances defined the color of the material and typically similar or identical. ● Specular color is usually white or gray.
13
RGB for Lights and Materials ● For lights ● Correspond to a percentage of full intensity. ● For materials ● Reflected proportion.
14
Emissive Color (Material Only) ● Specific to materials. ● Simulates lighting from an object itself. ● Adds intensity to the object. ● No affected by any light source. ● Doesn't introduce any additional light.
15
A Simple Example: Rendering a Lit Sphere
16
Normal Vectors ● In OpenGL, every lighting computation is per- vertex based. But we need a “surface” to compute the lighting. Therefore we assign normal vector to each vertex to tell the OpenGL engine its orientation (how the surface looks like near the vertex). ● Should be unit length, otherwise enable GL_RESCALE_NORMAL or GL_NORMALIZE. ● “normalization”
17
OpenGL Lighting ● Normal vectors need to be assigned to vertices. ● Besides lighting calculation ( GL_LIGHTING ), each light ( GL_LIGHT0 ~ GL_LIGHT n) needs to be turned on separately. ● Different materials can be assigned to front and back sides each.
18
Lighting Model 1.Global ambient light 2.Is the viewer infinitely far away? Or local? ● Affects the calculations for highlights. 3.One-sided or double-sided lighting? ● Normals reversed. 4.Specular lighting before or after texture mapping?”
19
Example: light.c ● Normal vectors for the vertices are set in glutSolidSphere function. ● Keeping aspect ratio of the scene regardless of the window size. (in reshape function)
20
Creating Light Sources
21
Light Source ● Several properties: color, position, direction, attenuation, cut-off angle, … ● Set by glLight*.
22
Types of Light ● Directional light ● Analogous to the sun ● Set by setting the w coordinate of position to 0. (vector) ● Simpler computation ● Positional light ● Analogous to a desk lamp ● Set by setting the w coordinate of position to nonzero. (point) ● Can define a spotlight.
23
Per-vertex Lighting ● Lighting computation is done only at the vertices! ● Problem with big polygon and narrow spotlight. ● cf) per-pixel lighting
24
Attenuation ● Disabled for directional lights. ● Emission and global ambient values aren't attenuated. ● Attenuation factor =
25
Spotlight ● A positional light with a cut-off angle in [0,90]. ● Also needs a direction. ● Spot exponent: “how concentrated the light it.”
26
Position & Direction of Lights ● Transformed by the current modelview matrix and stored in eye coordinates. ● Lighting computation is done in eye coordinates before projection. ● Example: movelight.c movelight.c
27
Selecting a Lighting Model
28
Lighting Model (reprised) 1.Global ambient light 2.Is the viewer infinitely far away? Or local? ● Affects the calculations for highlights. 3.One-sided or double-sided lighting? ● Normals reversed. 4.Specular lighting before or after texture mapping?”
29
Local/Infinite Viewpoint ● Affects the calculations for highlights.
30
Defining Material Properties
31
Diffuse Reflectance ● Diffuse and ambient reflectance can be set simultaneously. ● Only diffuse alpha is assigned to a vertex. ● Depends on the light position. ● Independent of viewpoint.
32
Ambient Reflectance ● Affects the overall color of an object. ● Noticeable where an object receives no direct illumination. ● Independent of both light position and viewpoint.
33
Specular Reflection ● Produces highlights. ● GL_SHININESS controls the size and brightness of the highlight. ● Depends on both light position and viewpoint.
34
Emission ● Doesn't introduce light sources!
35
Examples ● material.c material.c ● Nate Robin's tutorial
36
Color Material Mode ● Sets the material color by the current color. ● Depending on OpenGL implementation, performance improvement can be expected.
37
The Mathematics of Lighting (advanced)
38
Lighting Computation ● Computation is done on RGB separately. ● 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 ● No default shadow! ● Illuminated objects do not radiate!
39
Contributions from Light Sources ● contribution =attenuation factor*spotlight effect* (ambient term+diffuse term+specular term) ● attenuation factor = ● Spotlight effect = (max {v·d,0}) GL_SPOT_EXPONENT
40
Contributions from Light Sources (cont'd) ● ambient term = ambient light *ambient material ● diffuse term = (max{L·n,0}) *diffuse light *diffuse material ● Specular term = (max{s·n,0}) shininess *diffuse light *diffuse material
41
Lighting in Color-Index Mode
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.