Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.

Slides:



Advertisements
Similar presentations
OpenGL Course Notes Chapter 5: Lighting Jim Mims, Spring 2009.
Advertisements

Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Illumination Lighting and Shading CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford.
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
Computer Graphics - Class 10
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
IMGD 1001: Illumination by Mark Claypool
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.
7M836 Animation & Rendering
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.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Course Website: Computer Graphics 16: Illumination.
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
CS 445 / 645: Introductory Computer Graphics
Lecture 5: 3D Rendering Pipeline (II) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading in OpenGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
Computer Graphics I, Fall 2010 Shading in OpenGL.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE 381 – Advanced Game Programming GLSL Lighting.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
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.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Computer Graphics: Illumination
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Computer Graphics (fall,2010) School of Computer Science University of Seoul Minho Kim.
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
School of Computer Science
Shading in OpenGL Ed Angel
Lighting.
CSE 470 Introduction to Computer Graphics Arizona State University
Isaac Gang University of Mary Hardin-Baylor
Chapter IX Lighting.
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Frame Buffer Applications
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul

Topics ● Hidden-surface removal & depth buffer ● OpenGL lighting model ● Material properties

A Hidden-Surface Removal Survival Kit

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.

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.

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.

Real-World and OpenGL Lighting

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.

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

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.

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.

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.

RGB for Lights and Materials ● For lights ● Correspond to a percentage of full intensity. ● For materials ● Reflected proportion.

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.

A Simple Example: Rendering a Lit Sphere

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”

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.

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?”

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)

Creating Light Sources

Light Source ● Several properties: color, position, direction, attenuation, cut-off angle, … ● Set by glLight*.

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.

Per-vertex Lighting ● Lighting computation is done only at the vertices! ● Problem with big polygon and narrow spotlight. ● cf) per-pixel lighting

Attenuation ● Disabled for directional lights. ● Emission and global ambient values aren't attenuated. ● Attenuation factor =

Spotlight ● A positional light with a cut-off angle in [0,90]. ● Also needs a direction. ● Spot exponent: “how concentrated the light it.”

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

Selecting a Lighting Model

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?”

Local/Infinite Viewpoint ● Affects the calculations for highlights.

Defining Material Properties

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.

Ambient Reflectance ● Affects the overall color of an object. ● Noticeable where an object receives no direct illumination. ● Independent of both light position and viewpoint.

Specular Reflection ● Produces highlights. ● GL_SHININESS controls the size and brightness of the highlight. ● Depends on both light position and viewpoint.

Emission ● Doesn't introduce light sources!

Examples ● material.c material.c ● Nate Robin's tutorial

Color Material Mode ● Sets the material color by the current color. ● Depending on OpenGL implementation, performance improvement can be expected.

The Mathematics of Lighting (advanced)

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!

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

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

Lighting in Color-Index Mode