chapter 9 lighting © 2008 cengage learning emea. learning objectives in this chapter you will learn...

39
CHAPTER 9 CHAPTER 9 Lighting Lighting © 2008 Cengage Learning EM

Upload: virginia-armstrong

Post on 22-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

CHAPTER 9CHAPTER 9

LightingLighting

© 2008 Cengage Learning EMEA

Page 2: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LEARNING OBJECTIVESLEARNING OBJECTIVES In this chapter you will learn about:

– Light sources– Point lights– Spotlights– Ambient lights– Parallel lights– Emissive light– Reflection models– The ambient reflection model– The specular reflection model– The diffuse reflection model– The Phong reflection model– Vectors– Vector length– Vector addition (head-to-tail rule)– Scalar multiplication– Calculating a cross product (normal vectors)– Unit vectors– Direct3D extension vector functions– Implementing local illumination– Reflection and refraction– High Dynamic Range (HDR) lighting

Page 3: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES Texture mapping helped to enhance the overall

appearance of an object but failed to convey any real sense of depth.

For example, when looking at the two flat objects in Figure 9-1(a), it is clear that the three-dimensional nature of the scene, a wall positioned perpendicular on a floor, is not being conveyed properly. Figure 9-1(b) shows this same scene illuminated by a properly defined light source.

This lack of depth is the result of uniform lighting, i.e. the equal illumination of all surfaces.

Figure 9-2(a) shows a uniform lit sphere and Figure 9-2(b) the same sphere with basic lighting enabled.

The shaded sphere is the result of graduations in the sphere’s color based on the color of the light source. – In this case the color grey is incrementally decreased from

dark grey to white.

Page 4: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES

Page 5: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES

Light can be emitted through either self-emission or reflection.

Light sources are categorized by their light emitting direction and the energy emitted at each wavelength – determining the color of the light.

Page 6: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES

Page 7: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES

Objects can absorb or reflect light emitted from a light source depending on the reflecting object’s material properties.

Light will thus only be ‘visible’ when illuminated surfaces have the ability to reflect or absorb the said light.

Material properties are user-defined parameters built around rules determining the amount of scattering or reflection of incident light.

Page 8: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES

The type of light source also plays an important role in addition to the object’s material properties.

A light type property specifies the type of light to place in a scene. – This property simply denotes a light

source as a point light, spotlight, or directional light (also called a parallel light).

Page 9: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES

The illumination function:

Page 10: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

LIGHT SOURCESLIGHT SOURCES

A lighting model defines light-object interactions based on the type of light source and the material properties of the object.

The basic graphics pipeline is constrained to the use of just one lighting model, the fixed function lighting model. – This lighting model is basically an extended

version of the Phong lighting model

Page 11: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Point LightsPoint Lights

A point light emits light uniformly in 360 degrees.

Point lights have fixed color and position values and are omnidirectional in nature.

Page 12: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

SpotlightsSpotlights

Spotlights are specified by a color, spatial position and some specific direction and range in which light is emitted.

A spotlight is basically a point light with its emitting light constrained within an angle range.

Page 13: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

SpotlightsSpotlights

Page 14: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Ambient LightsAmbient Lights

Ambient lighting provides a uniform level of illumination throughout a scene.

Numerous large light sources are generally positioned in such a way as to scatter emitted light in all directions, thus making it impossible to determine the original position of the light source.

Page 15: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Parallel LightsParallel Lights

A parallel or directional light illuminates objects through a series of parallel light rays.

These light sources can be considered as point lights located a significant distance from the surface of an object.

Page 16: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Emissive LightEmissive Light

Emissive light is radiated (can be considered self-reflecting) light originating from an object’s surface.

This type of light blends with our other light types, resulting in a surface smoothly colored through the combination of all global light color components.

Page 17: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

REFLECTION MODELSREFLECTION MODELS

A surface is only visible when it has the ability to reflect or absorb light. – This ability is the result of the surface’s

material properties, i.e. rules determining the amount of scattering and/or reflection of incident light.

We can specify:– material properties for any surface, the most

common types being the Phong reflection model, ambient reflection, diffuse reflection, specular reflection, and transparency.

– our own per-vertex or per-pixel reflection models via either Cg or HLSL shaders

Page 18: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Ambient Reflection ModelAmbient Reflection Model

Ambient reflection, also called continuous reflection, occurs whenever light emitted from a source is reflected so much that its origin is impossible to determine.

Ambient light is omnidirectional in nature.

Page 19: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Specular Reflection ModelSpecular Reflection Model

Specular reflection occurs whenever light, from a single incoming direction, is reflected at a single outgoing direction.

Specular reflection is characterized by bright highlights on the surface of an object reflected in the direction of the view vector.

Page 20: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Specular Reflection ModelSpecular Reflection Model

Page 21: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Diffuse Reflection ModelDiffuse Reflection Model Diffuse reflections occur when incoming light

is reflected in arbitrary directions. The main contributing factor to this form of

reflection is an uneven or rough surface. A diffuse surface appears identical to all

viewers, regardless of their respective point of view.

This type of reflection is common for matte or uneven surfaces (such as carpets or brushed metal) and is used for shading surfaces in such a way as to convey a sense of depth.

Page 22: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Diffuse Reflection ModelDiffuse Reflection Model

Page 23: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

The Phong Reflection ModelThe Phong Reflection Model

The Phong model is an illumination model that controls the shading of individual pixels; it is computationally efficient and leads to realistic looking reflections.

Phong’s goal was to create realistic looking objects in as close to real time as possible.

The Phong reflection model basically combines ambient, specular and diffuse lighting components to closely approximate real world reflections.

Page 24: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

The Phong Reflection ModelThe Phong Reflection Model

Page 25: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

VECTORSVECTORS

Determining the lighting of a scene entails the calculation of vectors, dot products, and cross products.

A vector can be represented as a line/entity with both a magnitude and direction.

A line/entity lacking direction but with a magnitude is known as a scalar.

Page 26: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

VECTORSVECTORS

Vector Length Vector

Addition

Page 27: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

VECTORSVECTORS

Scalar Multiplication

Page 28: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

VECTORSVECTORS

Cross Product (Normal Vectors)

Unit Vectors

Direct3D Extension Vector Functions

Page 29: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

IMPLEMENTING LOCAL IMPLEMENTING LOCAL ILLUMINATIONILLUMINATION

Local illumination, unlike global illumination, only considers the interaction between a light source and object. – For example, when lighting a series of cubes,

each cube is lit independently from the others.– Thus, even though one cube might be blocking

light from another, it is never considered by the local illumination model

Page 30: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

IMPLEMENTING LOCAL IMPLEMENTING LOCAL ILLUMINATIONILLUMINATION

Our example implements local Our example implements local illuminations illuminations using the diffuse reflection model, resulting in a uniformly lit scene.

The amount of reflection is calculated using Lambert’s law – hence by considering the cosine of the angle between the vector directed at the light source and the surface normal

Page 31: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

IMPLEMENTING LOCAL IMPLEMENTING LOCAL ILLUMINATIONILLUMINATION

[see the textbook and source code “Lighting(prog9.1) (Direct3D)” and “Lighting (OpenGL)” on the book’s website for detailed examples].

Page 32: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

REFLECTION AND REFLECTION AND REFRACTIONREFRACTION

The basic reflective environmental mapping presented in Chapter 8 didn’t factor in the phenomenon known as the Fresnel effect nor the chromatic dispersion effect. – The Fresnel effect combines reflection and

refraction; i.e. it allows us to simulate the accurate reflection off and refraction through a surface using a number of Fresnel equations.

Chromatic dispersion extends the basic refraction model to consider the wavelength of the incoming light, that is, to recognise that certain light colors are refracted more than others. – Specifically, the higher the wavelength of the

color, the more it is refracted.

Page 33: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

RefractionRefraction

Refraction is the change in direction of a light ray due to a variance in material density (for example, a light wave travelling from air into water).

- This directional change is the result of a light ray’s speed. For example, light travels faster in air than in

water – hence, light travels more slowly in denser materials causing a change in direction where the light enters this material.

Page 34: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

RefractionRefraction Snell’s Law, also known as Descartes’ law, is used

to calculate the degree of refraction at the boundary of a lower- and higher density material. – This law describes the correlation between the incoming

light direction and the amount of refraction based on the index of refraction for each material.

The index of refraction is simply a measure based on the manner in which the material affects the speed of light – the higher the index of refraction, the slower the speed

of light.

Page 35: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

Reflection and Refraction Reflection and Refraction ExtendedExtended

[see the textbook for a detailed example and discussion].

Page 36: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

HIGH DYNAMIC RANGE (HDR) HIGH DYNAMIC RANGE (HDR) LIGHTINGLIGHTING

High Dynamic Range (HDR) lighting, also known as High Dynamic Range Rendering (HDRR), is the rendering of lighting using more than 256 color shades for each of the primary colors, namely, the red, green, and blue components. – Thus, we can now use 16 to 32-bit colors per RGB

channel as opposed to the normal 8 – eliminating luminance and pixel intensity being clamped to a [0, 1] range.

This allows for the display of light sources over 100 000 times brighter than normally possible.

Page 37: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

HIGH DYNAMIC RANGE (HDR) HIGH DYNAMIC RANGE (HDR) LIGHTINGLIGHTING

An example of HDR from Valve Software’s Half-Life 2: Lost Coasttechnology showcase © Valve Corporation.

Page 38: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

HIGH DYNAMIC RANGE (HDR) HIGH DYNAMIC RANGE (HDR) LIGHTINGLIGHTING

The following steps outline the process of rendering a scene using HDR lighting:1 Load the HDR floating-point values into a buffer (a

floating-point render target).2 Apply the bloom effect.

a Down-sample the buffer to 1/4 its original size. This is required so that the bloom effect is only ranged from edge pixels to neighbouring ones.

b Blur the image both vertically and horizontally (thus averaging the pixels and consequently creating the bloom effect by bleeding color from edge to neighboring pixels).

3 Combine the blurred and original texture.4 Tone map the composed texture.

Page 39: CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights

HIGH DYNAMIC RANGE (HDR) HIGH DYNAMIC RANGE (HDR) LIGHTINGLIGHTING

[see the textbook for a detailed HDR example and discussion].