Download An example of HDR from Valve Software`s Half

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CHAPTER 9
Lighting
© 2008 Cengage Learning EMEA
LEARNING 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
LIGHT 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 92(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.
LIGHT SOURCES
LIGHT SOURCES
Light can be emitted through either selfemission or reflection.
 Light sources are categorized by their light
emitting direction and the energy emitted
at each wavelength – determining the
color of the light.

LIGHT SOURCES
LIGHT 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.

LIGHT 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).
LIGHT SOURCES

The illumination function:
LIGHT 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
Point Lights
A point light emits light uniformly in 360
degrees.
 Point lights have fixed color and position
values and are omnidirectional in nature.

Spotlights
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.

Spotlights
Ambient 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.

Parallel 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.

Emissive 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.

REFLECTION 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
Ambient 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.

Specular 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.

Specular Reflection Model
Diffuse 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.

Diffuse Reflection Model
The 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.

The Phong Reflection Model
VECTORS
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.

VECTORS


Vector Length
Vector Addition
VECTORS

Scalar Multiplication
VECTORS



Cross Product
(Normal Vectors)
Unit Vectors
Direct3D Extension
Vector Functions
IMPLEMENTING LOCAL
ILLUMINATION

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
IMPLEMENTING LOCAL
ILLUMINATION
Our example implements local
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

IMPLEMENTING LOCAL
ILLUMINATION
[see the textbook and source code
“Lighting(prog9.1) (Direct3D)” and “Lighting
(OpenGL)” on the book’s website for detailed
examples].
REFLECTION AND REFRACTION

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.
Refraction

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.
Refraction

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.
Reflection and Refraction Extended
[see the textbook for a detailed example and
discussion].
HIGH DYNAMIC RANGE (HDR)
LIGHTING

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.
HIGH DYNAMIC RANGE (HDR)
LIGHTING
An example of HDR from Valve Software’s Half-Life 2: Lost Coast
technology showcase © Valve Corporation.
HIGH DYNAMIC RANGE (HDR)
LIGHTING

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.
HIGH DYNAMIC RANGE (HDR)
LIGHTING
[see the textbook for a detailed HDR example
and discussion].