Lighting – Light Sources

Slides:



Advertisements
Similar presentations
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Advertisements

1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
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.
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.
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.
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.
1 Lecture 9 Lighting Light Sources Reflectance Camera Models.
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);
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
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.
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Shading in OpenGL.
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
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,
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);
Project 5 Lamp Shader Fri, Nov 7, 2003 Due Mon, Nov 17, 2003.
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.
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.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Specular Reflection Lecture 27 Mon, Nov 10, 2003.
Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =
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.
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.
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
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.
Lecture 6 Lighting. Introduction What is light? How do we percept colors? Lights in OpenGL.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
Lecture 16: Shading and OpenGL Li Zhang Spring 2008
Illumination and Shading
Open GL: Colors and Lighting
Shading in OpenGL Ed Angel
Lighting.
Lighting Phong's Lighting Model normals
Illumination and Shading
Lighting and Materials
Lighting – Material Properties
Chapter IX Lighting.
Computer Graphics 4Practical Lesson
Computer Graphics 5Practical Lesson
ייצוג בעולם 3D ייצוג מצולעים (פוליגונים) צלע קודקוד צלעe0 : {v1,v2}
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Shading in OpenGL
Lighting Calculations
Presentation transcript:

Lighting – Light Sources Lecture 12 Wed, Sep 19, 2007

Lighting and Reflection The shade of a pixel is determined by two things: The light source(s). The material properties. The light sources determine the color and intensity of the light striking the surface. The material properties determine how that light is reflected.

Types of Light Source Ambient Point Source Directional Source Light source has no position in space. Point Source Light source is at a point in space. Light strikes different objects from different directions. Directional Source Light source is “at infinity.” Light strikes all objects from same direction.

Types of Light Source Emissive The object itself emits light. This is really a material property, not a light source. It does not illuminate other objects.

The Lighting Model To use lighting, the lighting model must be enabled: glEnable(GL_LIGHTING); When lighting is enabled, shading is determined by the lighting and material properties only; the glColor() function has no effect*. *Unless you enable GL_COLOR_MATERIAL.

General Ambient Light The only default lighting is the general ambient light, set to (0.2, 0.2, 0.2). This is independent of all regular light sources. The function glLightModel*() can be used to change the general ambient light. float model_ambient[] = {0.5, 0.5, 0.5, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);

Examples In the following examples, the material properties have been set to reflect all incident light.

Default Lighting Model Read Run

Light Source LIGHT0 OpenGL supports up to 8 separate light sources, each with its own characteristics. The are named LIGHT0, …, LIGHT7. The defaults for LIGHT0 are different from the defaults for LIGHT1 through LIGHT7. Otherwise, the 8 light sources are handled in the same way.

Defaults for Light Sources Ambient (0.0, 0.0, 0.0) Diffuse (1.0, 1.0, 1.0) Specular (1.0, 1.0, 1.0) Position (0.0, 0.0, 1.0) Defaults for LIGHT1 through LIGHT7 All types of light (0.0, 0.0, 0.0)

Enabling Lights Each light must be enabled. To enable LIGHT0, make the function call glEnable(GL_LIGHT0);

Default Settings for LIGHT0 Read Run

Point and Directional Sources At each point of a surface, the light has a direction. Point source – direction varies with position on surface. Directional source – direction does not vary with position on surface. Furthermore, with a point source, the intensity may vary with the distance from the source if we enable light attenuation.

Positioning the Lights Each light can be positioned at any point. OpenGL code to position LIGHT0: float light_position[] = {10.0, 10.0, 10.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Positioning Lights at Infinity A light source may be placed “at infinity” by setting the fourth coordinate to 0.0. float light_position[] = {1.0, 1.0, 1.0, 0.0}; The default type is directional. This example gives the light the direction vector (1, 1, 1), but no position in space. In other words, for objects in all locations, the light will shine from the direction (1, 1, 1).

LIGHT0 Positioned at (10, 10, 10) Read Run

Positioning the Light Sources The light sources may be set relative to the world coordinates (fixed) or relative to the camera (moveable). If they are relative to world coordinates, then the lighting remains the same when the camera is moved. If they are relative to the camera, then the lights move with the camera.

Positioning the Light Sources To make the light source fixed, the light’s position should be set after the camera is set. When the camera moves the scene, the lights move with the scene. To make the light source move with the camera, the light’s position should be set before the camera is set. The lights will not move with the scene.

Positioning the Light Sources We can make the lights fixed or moveable by swapping the order in which the functions setView() and setLights() are called. // Fixed lights setView(); setLights(); // Moveable lights setLights(); setView();

Positioning the Light Sources We can make the lights fixed or moveable by swapping the order in which the functions setView() and setLights() are called. // Fixed lights setView(); setLights(); Lights are transformed with the scene // Moveable lights setLights(); setView();

Positioning the Light Sources We can make the lights fixed or moveable by swapping the order in which the functions setView() and setLights() are called. // Fixed lights setView(); setLights(); // Moveable lights setLights(); setView(); Lights are not transformed with the scene

Fixed vs. Moveable Lights Read Run

Ambient Light Ambient light illuminates objects equally in all directions. In real life, ambient light is light that has been reflected off so many surfaces that it is impossible to identify the source.

Ambient Reflection The ambient reflection depends on The ambient light inherent in the scene. The ambient light given off by the light sources. The ambient property of the surface.

Setting the Light Properties The function glLight*() is used to set the various light properties, such as ambient light. It takes three parameters The light source. The light property. The value.

Setting the Ambient Light OpenGL code to set the ambient light for LIGHT0: float light_ambient[] = {0.3, 0.3, 0.3, 1.0}; glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);

LIGHT0 Ambient Light (0.3, 0.3, 0.3) Read Run

Diffuse Reflection Intensity of reflected diffuse light Depends on angle of incidence. Reflects equally in all directions, i.e., does not depend on the viewing angle. It can be computed more efficiently if the light is directional, since there is one less variable.

Setting the Diffuse Light OpenGL code to set the diffuse light for LIGHT0: float light_diffuse[] = {0.5, 0.5, 0.5, 1.0}; glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);

LIGHT0 Diffuse Light (0.5, 0.5, 0.5) Read Run

Specular Reflection Intensity of reflected specular light varies with viewing direction. Maximum intensity is in the direction pointing directly along the angle of reflection.

Specular Reflection Specular reflection creates the appearance of “shininess.” Surfaces with a high specular reflection appear very shiny. Surfaces with a low specular reflection appear matte.

Specular Reflection Computing specular reflection is less efficient than computing diffuse reflection, since it depends on the direction to the viewer as well as the position of the light source. The calculations can be speeded up if the viewer is placed “at infinity.”

Setting the Specular Light OpenGL code to set the specular light for LIGHT0: float light_specular[] = {1.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);