Lighting

39
LIGHTING SET09115 Intro Graphics Programming

description

Lighting. SET09115 Intro Graphics Programming. Breakdown. Working with Colour Basics of Lighting Why Lighting? Ambient Light Surface Lighting Diffuse Light Specular Light Other Lighting Types. Recommended Reading. Real Time Rendering Chapter 5 – Visual Appearance Course Text - PowerPoint PPT Presentation

Transcript of Lighting

Page 1: Lighting

LIGHTINGSET09115 Intro Graphics Programming

Page 2: Lighting

Breakdown Working with Colour Basics of Lighting

Why Lighting? Ambient Light

Surface Lighting Diffuse Light Specular Light

Other Lighting Types

Page 3: Lighting

Recommended Reading Real Time Rendering

Chapter 5 – Visual Appearance Course Text

Chapter 6 – Lighting and Shading

Page 4: Lighting

Colours

Page 5: Lighting

Colour Representation Modern graphics work with 32 bit colour Typically 4 values of 8 bits used

Red, green, blue, alpha (transparency) Other formats exist

We could work with values 0..255 Better to work with floats 0.0f ..1.0f

0% to 100%

AlphaRed Green Blue

32 bits

8 bits

Page 6: Lighting

Working with Colour Treat colour as a value

you can work with Add colours together

Red + Green = Yellow (1.0, 0.0, 0.0) + (0.0,

1.0, 0.0) = (1.0, 1.0, 0.0) Multiply colours

together Magenta * Yellow = Red

(1.0, 0.0, 1.0) * (1.0, 1.0, 0.0) = (1.0, 0.0, 0.0)

Page 7: Lighting

Vertex Colours Attaching colours to vertices is what we have

been doing up until this point Blending occurs over surfaces between colour

points OpenGL follows the RGBA format

Image formats may not be in RGBA DirectX can support other formats

These colours can be used in lighting calculations Typically, we use textured objects to provide more

detail

Page 8: Lighting

Blending The ability to

blend colours in this way is useful Multi-texturing Terrain

We will revisit blending colours when working with textures and terrain

Page 9: Lighting

Working with colour

Questions?

Page 10: Lighting

Basics of Lighting

Page 11: Lighting

Why Lighting? Lighting adds

depth to a scene Unlit objects are

flat and lack detail

Lighting adds realism to objects Specular detail Light reflection

Page 12: Lighting

How Lighting Works Light works in

rays from a graphics point of view Light comes from

a source Light is reflected

off of objects Light eventually

makes it into the eye

Original light source

Light reflected from red box to

blue sphere

Light reflected from red box into

eye

Light reflected from blue sphere

into eye

Page 13: Lighting

Materials Light rays are just one part of the

equation Light itself can have a colour Objects also have a colour

The type of light they reflect into the eye rather than absorb

The light that an object reflects is commonly described in its material Material may have other properties

Page 14: Lighting

Main Lighting Types Generally, an object

has three lighting effects affecting it at any time Ambient Diffuse Specular

The colour of an object are these three lighting effects combined Plus any other effectx

Page 15: Lighting

What is Ambient Light? Ambient light is the light that affects

everything equally in a scene Has no direction Has no distance Doesn’t care about which part of the object

is being calculated Outside, daylight is an ambient light

effect

Page 16: Lighting

Ambient Light Equation Ambient light calculation is the simplest

The ambient light of a particular vertex is just the ambient material colour of the object multiplied by the ambient light colour of the scene

LightMaterialAmbient

Page 17: Lighting

Example

Page 18: Lighting

Why lighting?MaterialsAmbient light

Questions?

Page 19: Lighting

Lighting Surfaces

Page 20: Lighting

Lighting a Surface Ambient light is something affecting all

geometry equally Still gives a flat appearance to a scene Objects reflect light based on how their

surfaces are aligned with the light source Occluded objects / surfaces get no light Surfaces perpendicular to light source get

full light

Page 21: Lighting

Working with Normals We use surface

normals to determine how light should be reflected off a surface Andrew will go

into the mathematics of lighting next week

Normals are very important for lighting

Page 22: Lighting

What is Diffuse Light? Diffuse light is

concerned with directionality of the light Geometry facing a

light source is lit Geometry facing

away from the light source unlit

Think sunlight outside

Page 23: Lighting

How does Diffuse Light Work? Diffuse light is concerned with the light

direction against the surface normal of the piece of geometry in question If angle = 90 then full light If angle 0 to 90, or 90 to 180, then shaded If angle < 0 or > 180 then not lit

Think about how this would work if you shone a light on a table

Page 24: Lighting

Lambert’s Cosine Law A simple way to

calculate the diffuse light of an object is using Lambert’s Cosine Law Cos(0) = 0 Cos(90) = 1 Cos(180) = 0

The cosine graph shows how this works

Page 25: Lighting

Diffuse Light Algorithm Using Lambert’s Cosine Law, we can generate the

diffuse lighting algorithm

Remember, dot product of two vectors is equal to the cosine of the angle between them

We would normally have to transform the surface normal if the model is transformed

Diffuse alpha should always be 1. We will have to set this

)()0.0,max(

LightMaterialpowerDiffuseNormalLightVecpower

Page 26: Lighting

Example

Page 27: Lighting

What is Specular Light? Specular light refers

to the point on the object where the light strikes Specular reflection

This provides a shiny look to objects

Also indicates where the light is coming from

Page 28: Lighting

How does Specular Light Work?

Specular light requires three pieces of information Light direction Surface normal Eye position

Specular intensity is based on eye position

Page 29: Lighting

Specular Light Algorithm Specular light is the most complicated

algorithm

LightMaterialpowerSpecularwerspecularPotoEyereflectpowpower

NormalLightVecreflectreflectiontionvertexPosieyePosnormalizetoEye

)),0.0,(max(),()(

Page 30: Lighting

Example

Page 31: Lighting

Surface lightingDiffuse lightingSpecular lighting

Questions?

Page 32: Lighting

Other Lighting Types

Page 33: Lighting

Other Lighting Types Ambient, Diffuse, and Specular are

considered the main environmental lighting types Object materials usually deal with these

three types There are of course other lighting types

which affect a scene Dynamic lighting Point lights Spot lights

Page 34: Lighting

Point Lights A point light is a light

that emanates from a particular point in the scene

Use the same equations, but calculate light vector based on vertex position and light position

Distance to light affects the strength of the light

Page 35: Lighting

Spot Lights Spot lights also work

using light position and distance

The direction of the light is also important Objects behind the

spot light aren’t lit Light also has an

angle associated with it Beam width at

distance

Page 36: Lighting

Phong Shading Phong Shading is a popular per-pixel approach to

performing lighting calculations Normals are interpolated across the surface of a polygon Provides a smoother shading look

Vertex lighting as discussed in this lecture is sometimes referred to as Gourand shading

Page 37: Lighting

Point LightsSpot LightsPhong Shading

Questions?

Page 38: Lighting

To do this week… Investigate some of the different forms

of light that can affect a scene In particular, try and find their lighting

values Consider the type of lighting you may

want in your coursework OpenGL has light functionality built in

without the use of shaders Shaders provide more controllable lighting

Page 39: Lighting

Summary Lighting is an important concept to provide

depth and realism to your scene Lighting is about the colour of the light, and

how an object reflects this light Three main types of lighting

Ambient Diffuse Specular

You should make yourself familiar with how to work these out