Lighting Jason Goffeney 452006 Lighting Lighting along with

  • Slides: 20
Download presentation
Lighting Jason Goffeney 4/5/2006

Lighting Jason Goffeney 4/5/2006

Lighting • Lighting along with perspective viewing adds to the illusion of viewing 3

Lighting • Lighting along with perspective viewing adds to the illusion of viewing 3 D on a 2 D screen

Lighting • There are really 2 parts to any lighting system: 1. How the

Lighting • There are really 2 parts to any lighting system: 1. How the lights are defined 1. How are the components of light set up? 2. How many lights? 3. Which type of lights? 2. How objects in the scene are defined 1. How are normals set up? 2. What are the material properties?

Lighting • By default with GL lighting turned off there is still white ambient

Lighting • By default with GL lighting turned off there is still white ambient light. But if GL lighting is enabled without a light set then there is no lighting at all.

Enabling Lighting • To enable the lighting system: gl. Enable(GL_LIGHTING); • To turn on

Enabling Lighting • To enable the lighting system: gl. Enable(GL_LIGHTING); • To turn on a single light: gl. Enable(GL_LIGHT 0);

Enabling Lighting • The first default light has the following properties: – It has

Enabling Lighting • The first default light has the following properties: – It has no ambient component – It has white diffuse and specular components – It is located at (0, 0, 1) on the coordinate system

Components of Light • Ambient light is considered sourceless and effects everything in the

Components of Light • Ambient light is considered sourceless and effects everything in the scene equally. • It does not add any depth to a scene.

Components of Light • Diffuse light emanates from a source and has a direction.

Components of Light • Diffuse light emanates from a source and has a direction. • The part of an object hit directly will be more brightly lit than parts where the light glances off.

Components of Light • Specular light is very directed light that reflects back to

Components of Light • Specular light is very directed light that reflects back to the viewer. • It results in the highlight seen on shiny objects like metal or plastics. • Specular light works with the material properties of an object. If the object is not shiny then specular does nothing.

Setting the Light Components • The basic function for setting lighting components is: gl.

Setting the Light Components • The basic function for setting lighting components is: gl. Lightfv(gl light, gl light property, values); GL_LIGHT 0 GL_LIGHT 1 … Such as, GL_POSITION GL_AMBIENT GL_DIFFUSE … light_position where light_position = {0. 0, -200. 0}

Setting the Light Components • Setting the position of the light. 1. Declare an

Setting the Light Components • Setting the position of the light. 1. Declare an array holding the x, y, z position of light GLfloat light_position[ ] = {0. 0, -200. 0}; 2. Set the gl. Light function. gl. Lightfv(GL_LIGHT 0, GL_POSITION, light_position);

Setting the Light Components • Setting the light color components. 1. Declare the arrays

Setting the Light Components • Setting the light color components. 1. Declare the arrays holding the r, g, b, w color components. GLfloat light_ambient[ ] = {0. 1, 1. 0}; GLfloat light_diffuse[ ] = {1. 0, 0. 0, 1. 0}; GLfloat light_specular[ ] = {1. 0, 1. 0}; 2. Set the gl. Light function. gl. Lightfv(GL_LIGHT 0, GL_AMBIENT, light_ambient); gl. Lightfv(GL_LIGHT 0, GL_DIFFUSE, light_diffuse); gl. Lightfv(GL_LIGHT 0, GL_SEPCULAR, light_specular);

Setting the Light Components • Be sure to enable the lights when you are

Setting the Light Components • Be sure to enable the lights when you are finished! • Other controllable properties – Light Attenuation – Spotlight Properties – Light Direction

Setting the Light Components • A light is basically another object in the scene

Setting the Light Components • A light is basically another object in the scene and can be affected by transformations. • To keep a light in one place, set its position in gl. Initialize and forget about it. • To move the light set its position after some transformation within gl. Paint.

Defining Materials • Material properties are the other half of the model. • The

Defining Materials • Material properties are the other half of the model. • The light components interact with the material properties for the final result. • Light and material colors combine • Material properties create dull or shiny objects

Defining Materials • Materials can be defined once during initialization to affect all scene

Defining Materials • Materials can be defined once during initialization to affect all scene objects or before an object is drawn to affect it and anything after it until another call is made.

Defining Materials • The function: gl. Materialfv( object face, material property, values); Which side

Defining Materials • The function: gl. Materialfv( object face, material property, values); Which side of the object faces should be included in the model calculations: GL_FRONT GL_BACK GL_FRONT_AND_BACK GL_AMBIENT GL_DIFFUSE GL_AMBIENT_AND_DIFFUSE GL_SPECULAR GL_SHININESS GL_EMISSION

Material Properties • Several of the properties complement their lighting counterparts. The others… –

Material Properties • Several of the properties complement their lighting counterparts. The others… – GL_SHININESS: A single float value used with the specular component to determine how tight the highlight it. The higher the value the smaller the spot. – GL_EMMISION: Allows the material to appear as if it is internally lit (kind of).

Setting Material Properties • Setting the values: GLfloat mat_specular[] = {1. 0, 1. 0};

Setting Material Properties • Setting the values: GLfloat mat_specular[] = {1. 0, 1. 0}; GLfloat mat_diffuse[] = {0. 0, 0. 3, 1. 0}; GLfloat mat_shininess[] = {10. 0}; GLfloat mat_emissive[] = {0. 5, 0. 0, 1. 0}; • Calling the functions: gl. Materialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); gl. Materialfv(GL_FRONT, GL_SPECULAR, mat_specular); gl. Materialfv(GL_FRONT, GL_EMISSION, mat_emissive); gl. Materialfv(GL_FRONT, GL_SHININESS, mat_shininess);

gl. Color. Material • Once you have set your materials you may wish to

gl. Color. Material • Once you have set your materials you may wish to change one for your objects using gl. Color. – Set the property to change for gl. Color. Material within your initialization gl. Color. Material(GL_FRONT, GL_DIFFUSE); gl. Enable(GL_COLOR_MATERIAL); – Now every call to gl. Color will change the Diffuse property of the material of the next object